# php form validation.. 

**URL:** <https://www.phphelp.com/t/php-form-validation/20475>\
**Category:** Code Snippets\
**Created:** [June 15, 2013, 2:07am UTC](https://www.phphelp.com/t/php-form-validation/20475 "2013-06-15T02:07:29Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![webdevdea](https://www.phphelp.com/user_avatar/www.phphelp.com/webdevdea/32/914_2.png) [@webdevdea](https://www.phphelp.com/u/webdevdea)\
**Post date:** [June 15, 2013, 2:07am UTC](https://www.phphelp.com/t/php-form-validation/20475/1 "2013-06-15T02:07:29Z")

</div>

I am trying to create a form that lets the user know if they didnt enter information when they hit the submit button.

[code]

Assignment2
# What's your name?

### Writing a form for user input
 Please type your first name:   
 Please type your last name:   
 Please type your city:   
 Please type your State:   
 Please type your Zipcode:   
 [/code] [php] Assignment2
### Personal Information
\<?php $chkErrors = FALSE; if (isset($\_POST['fName'])){ echo " please hit the back arrow and enter your name "; $chkErrors= TRUE; } if (isset($\_POST['lName'])){ echo " please hit the back arrow and enter your Last Name "; $chkErrors = TRUE; } if (isset($\_POST['city'])){ echo " please hit the back arrow and enter your city"; $chkErrors = TRUE; } if (isset($\_POST['state'])){ echo " please hit the back arrow and enter your state"; $chkErrors= TRUE; } if (isset($\_POST['zipCode'])){ echo " please hit the back arrow and enter your zipcode "; $chkErrors= TRUE; } $fName = filter\_input(INPUT\_POST, "fName"); $lName = filter\_input(INPUT\_POST, "lName"); $city = filter\_input(INPUT\_POST, "city"); $state = filter\_input(INPUT\_POST, "state"); $zipCode = filter\_input(INPUT\_POST, "zipCode"); if($chkErrors == FALSE) { echo \<\<\<HERE
### Hi there, $fName $lName, so you live in $city, in the great state of $state. I hear the climate around $zipCode is great this time of year. $fName, I hear that $state has alot to offer as far as recreation goes. I hope that you have a great summer in $city.
HERE; } ?\> [/php]

---

<div class="post-metadata">

**Author:** ![MrMaverick](https://www.phphelp.com/user_avatar/www.phphelp.com/mrmaverick/32/270_2.png) [@MrMaverick](https://www.phphelp.com/u/MrMaverick)\
**Post date:** [June 19, 2013, 3:24pm UTC](https://www.phphelp.com/t/php-form-validation/20475/2 "2013-06-19T15:24:18Z")

</div>

You should add an exclamation point before the isset function like so:

From:  
[php]  
// Where you are testing for if the array element fName is set  
if (isset($\_POST[‘fName’])){  
echo " please hit the back arrow and enter your name ";  
$chkErrors= TRUE;  
}  
[/php]

To:  
[php]  
// Testing if the array element fName is NOT set  
if (!isset($\_POST[‘fName’])){  
echo " please hit the back arrow and enter your name ";  
$chkErrors= TRUE;  
}  
[/php]

If any fields from the form are blank, they will remain blank when they enter the $\_POST array and therefore will be essentially uninitialized (not set). So you want to test if these are not set.
