PHP form

Posted on 2007-07-29
Last Modified: 2007-07-30
My client wants a Samples Request form that when an item is selected it will be added to a list. It would be sort of like a shopping cart but nothing is actually purchased so a shopping cart would be overkill. They just want whatever sample items are selected on the form to appear on a page and then when submitted that info is passed on to my client so they can ship the sample(s) to their prospective customer.

I have used FormMail PHP and am thinking that PHP could handle this type of scenario but have no idea how implement it. Where I'm lost is how to show the selected items before processing the form.
Question by:fred_belanger
    LVL 17

    Accepted Solution

    There are a couple of ways to show the selected items before processng the form.

    1) on the form's "action" page, don't send the e-mail directly, only show the forms fields from the form ( ie. echo all the $_POST vars) , then, create a new form on that page that has all the $_POST vars in hidden form fields with a new form action, thus, this form will only have a "submit" button visible to the user, but contain all the information submitted in the original form as hidden fields. ON the subsequent action page, you can use the $_POST vards from this second form to contruct your mail and actually mail it.

    2) On submit of you original form, you can write the form fields to a db. Then, on the action page, you can simply echo the $_POST vars and then have a button/link to a new page that reads the data from the db and compose an e-mail .

    3) You can do everything on the same page by submitting the form back to itself. Then you just add some "markers" to the "action" link depending on which step in the process you are. In your code, you check for theis $_GET variable that you can append to the action link and only show/execute the relevant forms/code
    LVL 1

    Assisted Solution

    The best way is to put the items in a Session:
    1. Use a normal form to enter the request (preferrably using a method="post" in your form)
    2. Pick up the data and put it in a session (eg array_push($_SESSION['samples'],$_POST['item']). This way everything is saved in an array and you can add as many items as you want
    (3. If needed, display everything so the client can see what samples he requested)
    4. Send everything (with a simple for/foreach-loop that puts everything in a mail)

    Author Comment

    Thanks both of you for your suggestions. I definitely have enough info now to start digging in and figuring things out.  

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Join & Write a Comment

    Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit ( and similar technologies have enjoyed wide adoption, making it possib…
    Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
    Learn the basics of lists in Python. Lists, as their name suggests, are a means for ordering and storing values. : Lists are declared using brackets; for example: t = [1, 2, 3]: Lists may contain a mix of data types; for example: t = ['string', 1, T…
    Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

    754 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now