Forum Moderators: coopster

Message Too Old, No Replies

looping through a form & check the results

         

fintan

12:38 pm on Jan 5, 2005 (gmt 0)

10+ Year Member



What would be the best way to loop through a form and check the fields. I have three forms p1 goes to p2 and p2 goes to p3 then it's submited after it's all been checked. Would it be best to have php do all the writing of the forms or just leave them in html. The forms contain text boxes, dropdowns, textareas and radio button's. I need to be able to redirect to the submited form if anything wasn't filled out and say highlight them in red. I'd perfer to do it in one function that could be included in the pages if that's posible. Thanks in advance

fintan.

jamie

1:55 pm on Jan 5, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



fintan,

i would put it all in one php script and always have the form action as $_SERVER['PHP_SELF'] - so it is always calling the same script.

then for each page, pass a hidden variable to the script so that i knows which bit of the form to display.

regarding error handling, you'd need a way of knowing which form field was in each page (probably easiest with an array of fields used for each page). that way, when an error was generated, you'd know which page/section to display

you might also look at hot scripts or similar, there are loads of ready-made form scripts which can tackle this sort of thing

good luck

fintan

2:31 pm on Jan 5, 2005 (gmt 0)

10+ Year Member



Thanks jamie for the reply. Would it not be a bit messy doing the 3 forms in 1. I'd like to have the form's on seperate pages but say have a include checking the forms. The $_SERVER['PHP_SELF'] would be handy if I just had one page I guess. I'll have a look at hot scripts. I'd prefer to come up with something myself instead of using someone's elses scripts. Thanks

jamie

7:56 pm on Jan 5, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



hi fintan,

unless the design was different for each page, you could simply post the data to yourself each time and remain on the same page. i prefer having less clutter in my doc_root, so when i can combine pages i do. by splitting it up it means 3 separate html pages to edit.

fintan

11:28 am on Jan 6, 2005 (gmt 0)

10+ Year Member



I have the 3 pages done already though. If your posting the 3 forms to the same page wouldn't get a bit messy code wise