I've set-up a form that uses js validation and sends email with php. In the form fields I have initial values specified such as Name, email, etc. The problem is you can just click the send button and the initial values meet the validation requirements so the email is sent.
Can the initial filed values be made to NOT validate using js or php?
Thanks for the info! I was hoping to avoid adding js to these pages. It seem like overkill.
Could there be a php solution or a way to set the validation to include a requirement that input must contain certain characters or a certain number of characters to validate? (ie. email must contain "@" or phone must contain only numbers)
The I think the there is only a HTML5 maxlength attribute, but again if you use it in the php validation you can check against the strlen.
Here is a snippet of the email validation with comments for you:
//Check the form fields if(empty($email)){ $errors['email'] = '<span class="error">Enter your email</span>'; } else{
// First, we check that there's one @ symbol, // and that the lengths are right. if (!ereg("^[^@]{1,64}@[^@]{1,255}$", $email)) { // Email invalid because wrong number of characters // in one section or wrong number of @ symbols. $errors['email'] = '<span class="error">Invalid email</span>'; }
// Split it into sections to make life easier $email_array = explode("@", $email); $local_array = explode(".", $email_array[0]); for ($i = 0; $i < sizeof($local_array); $i++) {
Can the initial filed values be made to NOT validate using js or php?
See html form code:
See PHP (very messy):
Thank you,
CM
P.S.
Wasn't sure what category to put this question in.
Could there be a php solution or a way to set the validation to include a requirement that input must contain certain characters or a certain number of characters to validate? (ie. email must contain "@" or phone must contain only numbers)
CM
http://css-tricks.com/forums/discussion/14225/jquery-placeholder-in-ie-passing-validation...#Item_4
You can also see the php validation I put together for the email input here:
http://css-tricks.com/forums/discussion/14161/php-form-validation-example.-secure-or-not-secures#Item_5
As far as only numbers, you can search is_numeric on php.net and that should help out.
http://www.php.net/manual/en/function.is-numeric.php
or for how many characters you want look up strlen (string length).
Thank you,
This is great!
Here is a snippet of the email validation with comments for you: