By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,746 Members | 1,865 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,746 IT Pros & Developers. It's quick & easy.

simple form validation

tolkienarda
100+
P: 316
hi all

I need to make sure someone entered some data into a form i am not concerned on this particular site about hacks or malatious injection so i just need to make sure the person entered somthing into each field. i currently send the results of my form to a remote php page. here are the names of the form fields and the basic form check as far as i have gotten. my question is if blank inputs are sent as null vlaues or if they have some random vlaue.

[HTML]
<form target="mailer.php" action="post">
<input type="text" name="email">
<input type="text" name="first_name">
<input type="text" name="last_name">
<input type="text" name="address">
<input type="text" name="city">
<input type="text" name="state">
<input type="text" name="zip_code">
</form>
[/HTML]

[PHP]
if ($_POST[email] = WHAT GOES HERE || $_POST[first_name] || $_POST[last_name] || $_POST[address] || $_POST[city] || $_POST[state] || $_POST[zip_code])
{
$url= "failed.htm";
}

[/PHP]

thanks for any and all help
Jan 31 '07 #1
Share this Question
Share on Google+
6 Replies


Motoma
Expert 2.5K+
P: 3,235
hi all

I need to make sure someone entered some data into a form i am not concerned on this particular site about hacks or malatious injection so i just need to make sure the person entered somthing into each field. i currently send the results of my form to a remote php page. here are the names of the form fields and the basic form check as far as i have gotten. my question is if blank inputs are sent as null vlaues or if they have some random vlaue.

[HTML]
<form target="mailer.php" action="post">
<input type="text" name="email">
<input type="text" name="first_name">
<input type="text" name="last_name">
<input type="text" name="address">
<input type="text" name="city">
<input type="text" name="state">
<input type="text" name="zip_code">
</form>
[/HTML]

[PHP]
if ($_POST[email] = WHAT GOES HERE || $_POST[first_name] || $_POST[last_name] || $_POST[address] || $_POST[city] || $_POST[state] || $_POST[zip_code])
{
$url= "failed.htm";
}

[/PHP]

thanks for any and all help

I am not quite sure what your question is. Please elaborate.
Jan 31 '07 #2

tolkienarda
100+
P: 316
I am not quite sure what your question is. Please elaborate.
ok so basicaly I need to see rather the post values i am reciving from the forms is vlaid. i dont realy care about injection or special chars or any kind of security checking i just want to know if some kind of data was entered into of each of the input boxes. if they were i want it to set $url to equal to failed.htm so i can tell the users that they need to complete the form. so the section in my code that says WHAT GOES HERE i need to know what would be sent if the input boxes were left blank

thanks
eric
Jan 31 '07 #3

Motoma
Expert 2.5K+
P: 3,235
To check if the user entered data for all fields, you would do something like this:
Expand|Select|Wrap|Line Numbers
  1. if(!isset($_POST['email']) || !isset($_POST['fullname']))
  2. {
  3.     $url = "failure.html";
  4. }
  5.  
Jan 31 '07 #4

tolkienarda
100+
P: 316
ah
i always wondered what that little thing ment. well now i know

thanks
eirc
Jan 31 '07 #5

ronverdonk
Expert 2.5K+
P: 4,258
I am sorry to spoil the party, but when the user did not enter any data, but left it blank, the isset() function will return true.

Just checking if a value (no blank) has been entered:[php]if ( strlen(trim($_POST['email'])) < 1
OR strlen(trim($_POST['first_name'])) < 1
OR strlen(trim($_POST['last_name'])) < 1
OR strlen(trim($_POST['address'])) < 1
OR strlen(trim($_POST['city'])) < 1
OR strlen(trim($_POST['state'])) < 1
OR strlen(trim($_POST['zip_code'])) < 1 )
{
$url= "failed.htm";
} [/php]Ronald :cool:
Jan 31 '07 #6

tolkienarda
100+
P: 316
Thank ya ron

this little script isn't done so i will be posting next time i get stuck (soon)

thanks again
eirc
Jan 31 '07 #7

Post your reply

Sign in to post your reply or Sign up for a free account.