Hey
I have a couple of small problems with my script for a simple html contact form that has validation on send and also echo’s the value in a particular field if it has already been posted.
My HTML form is as below:
<form id="contact" method="post" action="result.php">
<input id="firstname" class="box" name="firstname" type="text"/><br />
<textarea id="message" class="commentbox" name="message" rows="4" cols="22"></textarea><br />
<input id="send" name="send" class="submitbutton" type="submit" value="Send"></input>
</form>
Now the problems:
I validate each field on submit to test if it is valid. All is fine expect in my ‘message’ textarea field i need to allow the user to press ENTER or RETURN. So far i have Upper/Lowercase Numbers, Letters, ?,!, full stop and a comma allowed, how can i add enter into the current validation?:
function validateMessage($message){
if(strlen($message) < 1)
return false;
if(ereg('[^A-Za-z0-9,?!. ]+', $message))
return false;
else
return true;
}
On my ‘result’ page if an error from validation comes up i display the form again but i echo the posted values into each field so the user doesn’t have to ren-enter the whole form again. All is fine on the standard input fields but i cannot get the ‘message’ text area field to echo back its posted value.
My code currently is:
<form id="contact" method="post" action="result.php">
<input id="firstname" class="box" name="firstname" type="text"
<?PHP
if ( isset($_POST['send']) && (!validateFirstName($_POST['firstname']))){
echo('value="Please Enter a Valid First Name"');
}
else if ($_POST['firstname']) {
echo('value="'.$_POST['firstname'].'"');
}
?>
/><br />
<textarea id="message" class="commentbox" name="message" rows="4" cols="22"
<?PHP
if ( isset($_POST['send']) && (!validateMessage($_POST['message']))) {
echo('Please Enter Your Enquiry');
}
else if ($_POST['message']) {
echo(''.$_POST['message'].'');
}
?></textarea><br />
<input id="send" name="send" class="submitbutton" type="submit" value="Send"></input>
Can anyone help with these problems? I am sure it will be something quite quick and simple but just cannot figure it out so far…
Many Thanks
Jon