homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

php form with validation
php form with validation

 6:23 pm on Mar 28, 2008 (gmt 0)

Hi All:

I have a form that submits to a php script to process the output but am having difficulty with the validation piece.

The form works fine, submits to my processing page that stores the form field values in variables and then submits an email. I am stuck with how to check for any empty field values (going through them all first) and then redirect back to the original form, repopulating the form with the values that were entererd and indicating to the user (message) the fields that were not filled out.

I know I can use session variables to store the form data but my mind keeps spinning in circles (like my code these days) on how to let the script know to go back and forth.

Any help would be greatly appreciated.




 6:49 pm on Mar 28, 2008 (gmt 0)

What code are you using for validation ?


 6:54 pm on Mar 28, 2008 (gmt 0)

You could use javascript

if(empty($_POST['field1'])) {
echo '<script language="Javascript">
alert ("Error! Missing Value for field1.")
} else {
$field1 = mysql_real_escape_string($_POST['field1']);


 7:15 pm on Mar 28, 2008 (gmt 0)

Thanks for the replies. I was hoping to use php and check for a field value:

-- If a value, store in a session variable for re-use (to repopulate the field if directed back to the form because of an empty value somewhere else) or
-- If no value, set a message value for that field and store it in a session variable to be passed back to the form for displaying to the user.

Ideally I would like to "test" all field values and generate variables for all fields before going back to tell the user, or in the case of success just executeg my script after the validation.

I can use javascript, but my process form is already in php so figured I could keep it together.

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved