php validation

hello trying to validate my fields so if a name is typed into name field then

a password incorrectly typed into password field the form remebers what has been typed in name field

[php]<?php
ini_set(‘error_reporting’, E_ALL);
ini_set(‘display_errors’, ‘1’);

if (($_SERVER[‘REQUEST_METHOD’] == ‘POST’) && (!empty($_POST[‘action’]))):

if (isset($_POST['myname'])) { $myname = $_POST['myname']; }
if (isset($_POST['mypassword'])) { $mypassword = $_POST['mypassword']; }
if (isset($_POST['mypasswordconf'])) { $mypasswordconf = $_POST['mypasswordconf']; }
if (isset($_POST['mycomments'])) { $mycomments = $_POST['mycomments']; }
if (isset($_POST['reference'])) { $reference = $_POST['reference']; }
if (isset($_POST['favoritemusic'])) { $favoritemusic = $_POST['favoritemusic']; }
if (isset($_POST['requesttype'])) { $requesttype = $_POST['requesttype']; }



if ($myname === '') :
	$err_myname = '<div class="error">Sorry, your name is a required field</div>';
endif; // input field empty

if (strlen($mypassword) <= 6):
	$err_passlength = '<div class="error">Sorry, the password must be at least six characters</div>';
endif; //password not long enough


if ($mypassword !== $mypasswordconf) :
	$err_mypassconf = '<div class="error">Sorry, passwords must match</div>';
endif; //passwords don't match


if ( !(preg_match('/[A-Za-z]+, [A-Za-z]+/', $myname)) ) :
	$err_patternmatch = '<div class="error">Sorry, the name must be in the format: Last, First</div>';
endif; // pattern doesn't match

endif; //form submitted
?>

Form Sample
  1. Name * <?php if (isset($err_myname)) { echo $err_myname; } ?> <?php if (isset($err_patternmatch)) { echo $err_patternmatch; } ?>
  2. Password <?php if (isset($err_passlength)) { echo $err_passlength; } ?>
  3. Password (confirm) <?php if (isset($err_mypassconf)) { echo $err_mypassconf; } ?>
  4. Favorite Music
    1. Rock
    2. Classical
    3. Reggaeton
  5. How did you hear about us? Choose... A friend Facebook Twitter
  6. Request Type
    1. Question
    2. Comment
    3. Suggestion
  7. Comment
send [/php]

Are you still having issues with this? It looks pretty straight forward. I don’t see anything wrong at first glance, if you’re still having trouble I’ll test it out tomorrow.

Sponsor our Newsletter | Privacy Policy | Terms of Service