Jump to content

good practice with multiple forms on a page


1internet

Recommended Posts

So if I have multiple forms performing different functions on the same page, is it best to put all the php code at the top of the page before I declare the doctype? Oppossed to the php code above each form?

 

Is this considered best practice? Is this also what prevents the header already assigned errors that need to be corrected with the ob_start, etc functions?

Well, I'll be quite fair, if you're going to be submitting multiple forms or just 1 form, you're best running the processing code in a separate file "process.php" or similar.

 

The reason I say this, is because if you use the same page as the recipient, its very hard for you to avoid accidental form resubmission (hitting the refresh button)

 

You could also use the same page as the processing page (If you absolutely MUST) aslong as you redirect the user to a "confirmation" page, and get them away from that page AFAP (sounds dirty huh!)

 

But to answer your question, yes -- running your form processing code before ANY character data (even spaces and new lines) will avoid the "headers already sent" error, but if you echo, print, etc, information to the browser before you call header() you will receive that error anyway.

 

- Russell

Yes, but the only reason people will use the same page to process form data is if they're trying to use the form data collected in targeting erroneous fields. (For example: Long Profile Detail Pages -- which should use AJAX of some sort to be quite fair)

 

While that is a decent approach, for that application, in almost every other application its best to process on separate pages, atleast in my professional experience.

 

- Russell

I currently dont use a redirect for the errors, if there are no errors it redirects to another page, but if there errors it will remain on the same page from the form action="", with the $errors loaded in the array and displayed to the user.

Is this approach acceptable?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.