close ad
Install the LAtest Updates to Work with CC 2017 and CC 2018
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

Storing error messages in the form fields

Thread began 3/24/2010 11:53 am by gwh362692 | Last modified 3/31/2010 7:33 pm by gwh362692 | 1363 views | 10 replies

gwh362692

Originally Said By: Dani Chankhour
  In regard to your second question, you probably could do it as you said. But Another way you can do it is in javascript. So on the submit event of of the form, create a function that checks if the value is First Name then return false, otherwise return true.  



Sorry to come back to this issue but I'm still having trouble solving it. Just to recap, 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>



Since I'm only using server side validation for the fields and the errors are output to spans, I didn't want to go the javascript way as you suggested. To do it the php way, I'm guessing I would have to alter the ValidatedField() function so that it returns false on blank or "First name", or "Last 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.

<?php 
if (!session_id()) {
session_start();
}
function ValidatedField($page,$field) {
$theFields= "";
$retVal = "";
if (isset($_SESSION["WAVT_".$page."_Errors"])) {
$theFields = "&".$_SESSION["WAVT_".$page."_Errors"];
}
if (strpos($theFields,"&WAVT_".$field."=") !== false) {
$retVal = substr($theFields,strpos($theFields,"&WAVT_".$field."=")+strlen("&WAVT_".$field."="));
}
if (strpos($retVal,"&WAVT_") !== false) {
$retVal = substr($retVal,0,strpos($retVal,"&WAVT_"));
}
if ($retVal == "" && $page == $field) {
$retVal = ValidatedField($page,$field."_Errors");
}
return $retVal;
}

?>



As I'm not really sure how the above function works, can I get some help in revising it if this is the way to solve this? I understand though if this is beyond the scope of help in these forums.

Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

Build websites from already-built web applications

These out-of-the-box solutions provide you proven, tested applications that can be up and running now.  Build a store, a gallery, or a web-based email solution.

Want your website pre-built and hosted?

Close Windowclose

Rate your experience or provide feedback on this page

Account or customer service questions?
Please user our contact form.

Need technical support?
Please visit support to ask a question

Content

rating

Layout

rating

Ease of use

rating

security code refresh image

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.

Close Windowclose

We were unable to retrieve the attached file

Close Windowclose

Attach and remove files

add attachmentAdd attachment
Close Windowclose

Enter the URL you would like to link to in your post

Close Windowclose

This is how you use right click RTF editing

Enable right click RTF editing option allows you to add html markup into your tutorial such as images, bulleted lists, files and more...

-- click to close --

Uploading file...