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
?>
- Name * <?php if (isset($err_myname)) { echo $err_myname; } ?> <?php if (isset($err_patternmatch)) { echo $err_patternmatch; } ?>
- Password <?php if (isset($err_passlength)) { echo $err_passlength; } ?>
- Password (confirm) <?php if (isset($err_mypassconf)) { echo $err_mypassconf; } ?>
-
Favorite Music
- Rock
- Classical
- Reggaeton
- How did you hear about us? Choose... A friend Facebook Twitter
-
Request Type
- Question
- Comment
- Suggestion
- Comment