Welcome to WebmasterWorld Guest from 18.204.48.199

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Form validation, is it possible to post vars without form?

     
8:15 am on Nov 23, 2005 (gmt 0)

Junior Member

10+ Year Member

joined:Oct 11, 2005
posts:174
votes: 0


Hi,

I have many forms on my site and so far just check to see if my vars have a value and if not just show a messages saying please fill out such and such a field.

What i want to do is, check that each form field has a value and for the ones that dont, send the appropriate error message or number to another script that displays the error messages. This way I have one error page used to display various errors from all forms of my site. So i need a way to send the error messages to the error page. Like an array then i can just iterate the error array to display each message.

Why the extra page? Cause i'm using a template that wont be easy to put directly into form processing scripts. It could be done but i would prefer a cleaner method.

Sorry if that was confusing

Thanks for any help

8:51 am on Nov 23, 2005 (gmt 0)

Senior Member

WebmasterWorld Senior Member dreamcatcher is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Mar 30, 2003
posts:3719
votes: 0


Hi one_mind,

If you want to send data to another page, then you`ll probably need to pass it in a query string.

So, try something like this. Its not the best way I don`t suppose, but should work. Note that in using the header function this processing MUST go at the top of your script.


error = array();

if ($name="")
{
$error[] = 'name=1';
}
if ($email=="")
{
$error[] = 'email=1';
}
if ($comments=="")
{
$error[] = 'comments=1';
}

and so on..

Then create the error string if any errors are present:

if ($error)
{
//Build query string

$for($i=0; $i<count($error); $i++)
{
if ($i)
{
$error_string .= '&' . $error[$i];
}
else
{
$error_string = $error[$i];
}
}

header("Location: error.php?$error_string");
}
else
{
header("Location: thanks.php");
}

On your error.php page, display messages based on the query string.

if (isset($_GET['name']))
{
echo 'Please enter your name';
}

etc etc

Hope that helps.

dc

9:30 am on Nov 24, 2005 (gmt 0)

Junior Member

10+ Year Member

joined:Oct 11, 2005
posts:174
votes: 0


Thanks dreamcatcher,

That works great.

Cheers :)

3:00 pm on Nov 24, 2005 (gmt 0)

Senior Member

WebmasterWorld Senior Member dreamcatcher is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Mar 30, 2003
posts:3719
votes: 0


You`re welcome. :)
5:55 pm on Nov 24, 2005 (gmt 0)

Full Member

10+ Year Member

joined:Mar 27, 2004
posts:276
votes: 0


Wow dreamcatcher another great tip. I will trying on my contact form. I have one question though. If I have a filed on two forms and not on the other two can i still use this on all for forms with the error.php listing all errors and the pages olny grabbing the error needed for that form. Hope this is understandable
Pat
6:11 pm on Nov 24, 2005 (gmt 0)

Senior Member

WebmasterWorld Senior Member dreamcatcher is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Mar 30, 2003
posts:3719
votes: 0


Pat,

Not really sure I`m understanding you. The above example is just for redirecting to a seperate page. Its much easier to have all the info for the form on one page, but then its all down to personal preference.

dc

2:12 am on Nov 25, 2005 (gmt 0)

Junior Member

10+ Year Member

joined:Oct 11, 2005
posts:174
votes: 0


Hi Kysmiley,

I am using error.php for over 20 forms of my site. What i do is just make my querie string like so:

header("Location: ../error.php?form=1&$error_string");

So for my login page has form=1 then my contact page has form=2 ect then i just switch($form) on the error page with each case being the proper error display code.