Hello,
I am trying to set up a PHP form validation with a form which includes fields that have pre-defined values. However, I want to return an error message if the form visitors does not input a field value other than the one that has be pre-defined.
To better explain my situation, I have a form field as follows:
<input name="Name" class="input" value="Your name:" type="text" onblur="if(this.value=='') {this.value='Your name:';}" onfocus="if(this.value=='Your name:') {this.value='';}">
The field name=Name above has a pre-defined value of "Your name:", which I use to describe to the user what I want them to fill out (pretty elemental), as oppose to include the explanation text out side the input field. But I want such field to be required to submit the form. Hence, I need a PHP case in which it says, in layman's terms, "if the value of the field X is equal to a pre-defined value, then echo an error message."
In short, I need something like a "required" case, but instead of an empty field, the field must NOT be equal to its original value:
case "same_as_original":
if (!isset($fields[$field_name]) || $fields[$field_name] == "PRE-DEFINED VALUE")
$errors[] = $error_message;
break;
The error messages have been defined elsewhere on a validation.php file.
I realize the easy path would be to leave the field blank and place the explanation text outside the input field, but that would be too easy, right? 😃
Can anyone help me here or is this way outside the scope of this forum?
Thanks in advance for your help.