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?

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.