...

View Full Version : help with php preview and submit form



topislogo
03-24-2009, 11:48 AM
Hello everyone! This is regarding HTML forms, PHP .

My Question:

How do you create an html formor php form that goes to a preview screen and then allows the user to move back to the form if they made any errors and corrections are needed or click the send button to submit the form. The form's contents are to be send to an email address

Fumigator
03-24-2009, 05:10 PM
The easiest way is to use a session to save the form data so it is available to both the review page and the form page.

Mouseman
03-24-2009, 06:46 PM
I'm looking to do a similar thing but I'm not convinced PHP is the way forward, either that or I've not grasped the sessions principle well enough:

I want the user to enter their personal details, name email address etc THEN they need to fill out instruments that they play, this could be one or could be five instruments. Rather than having an enormous HTML form that in the majority of cases wouldn't be used, I thought it would be neat to have a smaller form asking for the personal details, then a button that would disappear the form they've just filled out and another one asking for instrument details. Another button on that form to fill out their next instrument or submit details to the (SQL) database.

My n00bness will show with the following thinking:

One method, have them fill out name etc, click "next" which increments a variable. Start the script with an if($_POST){} statement which if true displays a new form for instrument input, if false defaults to the personal details form. If this makes sense so far, does it make sense to have the instrument variables get incremented by the POST varibale (that's incremented on POST)?

So page loads, if($_POST)==FALSE, so display personal details. Our post_increment = 0.

They enter details, so if($_POST)==TRUE, so display instrument details. post_increment now = 1. Make instrument_name variable = instrument_name[post_increment] ?? That way, when they submit again for a new instrument, the second instrument details are stored in instrument_name[2] ??

That keeps things tidy in one script, rather than passing things back and forth to maybe five pages? All variables held in the usual $_POST global array, instruments numbered according to the post_variable identfier?


Or do I have the wrong end of the stick? ;)

rafiki
03-24-2009, 07:52 PM
Mouseman I think you have the wrong end of the stick but to comply with rules please start your own thread, thanks.
Rafiki.

Mouseman
03-24-2009, 11:56 PM
Apologies, I deliberately posted in this thread as it's pretty much the same as what I'm doing right now. I'm just thinking of other ways of doing it. (In other forums I frequent the regulars get very upset and newbies creating threads willy nilly when there's plenty available on the front page to contribute to/discuss in ;))

I appreciate it's not identical but using sessions would be one way of accomplishing my goal but I feel messy? Anyways, I'll save that for another place. :) OP - sessions is the right move for one form to be checked and changed if needed.

Fumigator
03-25-2009, 12:25 AM
I may as well continue the hijack :p

Mouseman if you are amenable to using Javascript/jQuery, you can take advantage of the jQuery UI and use the accordion or the tab widgets which will make it really simple to display one section of the form at a time. One submit will then validate the form on every tab at once. This is the direction I'd look in if I were creating a multi-part form right now.

http://jqueryui.com/demos/accordion/

Then again, I just discovered jQuery so my excitement about its power and abilities may be influencing my answers. ;)

(The OP could also use this technique, actually)

Mouseman
03-25-2009, 12:33 AM
Looks neat, cheers. Might as well throw this into the mix; currently touched upon the obvious in this project: HTML, SQL, PHP, Javascript, CSS. Exciting stuff to try to cram in quickly! :eek:

Lots more reading needed, as ever!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum