I'm using the Nice & Simple Contact form and it works perfectly but I need some help with something else.
How do I make an entry field required to be filled out before submission? You know, where the user gets an error message saying, "Please fill out your name & email."
The PHP is exactly what Chris gave us other than edits to the To and From emails. If anyone could help, I'd greatly appreciate it!! I'm only familiar with editing PHP and not creating it.
if (reason != \"\") { //alert(\"Some fields need correction:\n\n\n\" + reason); return false; }
//alert(\"All fields are filled correctly\"); return true; } function validateEmpty(fld) { var error = \"\";
if (fld.value.length == 0) { fld.style.background = '#f1f453'; error = \"The required message field has not been filled in.\n\n\n\" } else { fld.style.background = 'White'; } return error; } function validateName(fld) { var error = \"\"; var illegalChars = /\W\ /; // allow letters, numbers, and underscores
if (fld.value == \"\") { fld.style.background = '#f1f453'; error = \"Please enter your full name.\n\n\"; } else if (fld.value.length < 3) { fld.style.background = '#f1f453'; error = \"Your name should be in full and over 5 characters in length.\n\n\"; } else if (illegalChars.test(fld.value)) { fld.style.background = '#f1f453'; error = \"The name contains illegal characters.\n\n\"; } else { fld.style.background = 'White'; } return error; }
function trim(s) { return s.replace(/^\s+|\s+$/, ''); } function validateEmail(fld) { var error=\"\"; var tfld = trim(fld.value); // value of field with whitespace trimmed off var emailFilter = /^[^@]+@[^@.]+\.[^@]*\w\w$/ ; var illegalChars= /[\(\)\<\>\,\;\:\\\\"\[\]]/ ;
if (fld.value == \"\") { fld.style.background = '#f1f453'; error = \"Please enter a valid email address.\n\n\"; } else if (!emailFilter.test(tfld)) { //test email for illegal characters fld.style.background = '#f1f453'; error = \"Please enter a valid email address.\n\n\"; } else if (fld.value.match(illegalChars)) { fld.style.background = '#f1f453'; error = \"The email address contains illegal characters.\n\n\"; } else { fld.style.background = 'White'; } return error; } function validatePhone(fld) { var error = \"\"; var stripped = fld.value.replace(/[\(\)\.\-\ ]/g, '');
if (fld.value == \"\") { error = \"Please enter your phone number including area code and omit spaces.\n\n\"; fld.style.background = '#f1f453'; } else if (isNaN(parseInt(stripped))) { error = \"The phone number contains illegal characters.\n\n\"; fld.style.background = '#f1f453'; } else if (!(stripped.length == 11)) { error = \"Make sure you included an area code and omit spaces. \nThe phone number should be 11 numbers in length.\n\n\"; fld.style.background = '#f1f453'; } else { fld.style.background = 'White'; } return error; } function validateCaptchaHTML(fld) { var error = \"\"; var stripped = fld.value.replace(/[\(\)\.\-\ ]/g, '');
if (fld.value == \"\") { error = \"Please enter the result of the sum.\n\n\"; fld.style.background = '#f1f453'; } else if (isNaN(parseInt(stripped))) { error = \"The number is wrong.\n\n\"; fld.style.background = '#f1f453'; } else if (!(stripped.length == 2)) { error = \"The number is wrong.\n\n\"; fld.style.background = '#f1f453'; } else { fld.style.background = 'White'; } return error; } //End Hide Script--> </script>
How do I make an entry field required to be filled out before submission? You know, where the user gets an error message saying, "Please fill out your name & email."
The PHP is exactly what Chris gave us other than edits to the To and From emails. If anyone could help, I'd greatly appreciate it!! I'm only familiar with editing PHP and not creating it.
if($requiredfield) {
//it is true - form submitted
} else {
//it is false form re-displayed with a message at the top like \"fill it in properly\" :)
}
If you know PHP a little, that will make sense, if not then you might need to give us some code lol
Well, I guess I don't know as much as I thought I did because I'm a little confused.
Here's my PHP
And here is the form in my HTML
if you would like to see this let me know:
some prefer some other ways to do it, I did not want anything intrusive for the person filling in the form......
ok this is the javascript in the head tag:
here is my form:
now it will work as is, but your form may not look like this, however you can change it, it is quite easy to understand.....