View Full Version : Forms

12-24-2007, 10:13 PM
Hey, i have multiple forms on each page (most pages) of a cms, yet when i click on a submit button for one, the other one submits blank data.
i don't want my visitors to keep seeing errors about having a blank message if they're using the shoutbox for example.

I've tried giving the forms different names, this still doesn't fix the problem.
Any Advice?

12-24-2007, 10:18 PM
Use a different method for each form, eg for one method="submit.php?type=1" and then in submit check only if the type is in the URL

12-24-2007, 10:22 PM
wtf, thats a dumb way, all my forms are submitted via POST (more secure) and each form is on a different script.
but i include them so hence one page, lots of forms. and i'm not using GET Url's

12-24-2007, 10:24 PM
I meant action in my last post instead of method.

Alternatively you could use a hidden input field with the type instead of using GET

12-24-2007, 10:25 PM
but still thats scruffy.. i want it to be smart and neat.

12-24-2007, 10:26 PM
POST being a more secure method may be a slight stretch of the imagination but i'll go with it.

It is possible to set the method as post but then set the action to include the get variable
i.e. <form action="page.php?go=1" method="post">
then you still access your form data using post but check if go=1 to execute the relavent actions.
For your multiple forms your could either set different variables i.e. go=1, back=1 or you could have one variable with different values i.e. go=1, go=2

This is the most common way of doing this.

12-24-2007, 10:29 PM
thanks mike, but i don't want to use a get action as it looks scruffy as hell. any other ideas?

12-24-2007, 10:32 PM
Well i don't agree with your reasoning but next method:

Just make sure all your form fields have different names then for your processing enter the block with the usual if(isset$_POST['xyz'])){
then inside that just check what fields are set.
i.e. 2 forms, one with username and password, one with name and date.
if username and password are set
execute this
elseif name and date are set
execute this

12-24-2007, 10:33 PM
lolz, don't worry i got another idea.