Welcome to WebmasterWorld Guest from

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

php form with validation

php form with validation



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

5+ Year Member

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)

5+ Year Member

What code are you using for validation ?


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

10+ Year Member

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)

5+ Year Member

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.


Featured Threads

Hot Threads This Week

Hot Threads This Month