PHP form

Posted on 2007-07-29
Medium Priority
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

psimation earned 1000 total points
ID: 19588902
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

Assisted Solution

Lambrassie earned 1000 total points
ID: 19590677
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

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

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
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…
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
Suggested Courses
Course of the Month17 days, 12 hours left to enroll

829 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