Hi everyone,
The following code has a javascript onblur event in the input fields so that if someone clicks out of the field without typing something in it, the original label, eg. 'First name' is reinserted into the field. The field is also being validated by some php code, however the onblur event creates a problem because the form still submits even if a name isn't typed into the field. It's assuming that 'First name' or 'Last name' are entries and therefore isn't validating it correctly.
<div>
<label for="firstname">First Name:</label>
<input id="firstname" name="firstname" type="text" value="First name" onfocus="if (this.value == 'First name') this.value=''" onblur="if (this.value == '') this.value='First name'" />
<?php
if (ValidatedField('index_965','index_965')) {
if ((strpos((",".ValidatedField("index_965","index_965").","), "," . "1" . ",") !== false || "1" == "")) {
if (!(false)) {
?>
<span style="color: red"> First name is required </span>
<?php
}
}
}?>
</div>
<div>
<label for="lastname">Last Name:</label>
<input id="lastname" name="lastname" type="text" value="Last name" onfocus="if (this.value == 'Last name') this.value=''" onblur="if (this.value == '') this.value='Last name'" /> </div>
<?php
if (ValidatedField('index_965','index_965')) {
if ((strpos((",".ValidatedField("index_965","index_965").","), "," . "2" . ",") !== false || "2" == "")) {
if (!(false)) {
?>
<span style="color: red"> Last name is required </span>
<?php
}
}
}?>
<div>
I'm guess it would have to check if the contents of the first field was 'First name' and if yes then validation would fail and so the span with the error text "First name is required" would show, then the same with the second field.
Any assistance with this, much appreciated.