close ad
 
Important WebAssist Announcement
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

Checkbox Validation using Spry in ContactForm Solution Pack

Thread begun 3/30/2010 11:05 pm by Groshko | Last modified 4/01/2010 8:20 am by neilo | 3940 views | 4 replies |

Groshko

Checkbox Validation using Spry in ContactForm Solution Pack

Hi there,

I have one check box on a form that needs to be ticked before the submission is made.
I have looked at the Spry for the checkbox and have selected it as a required field.
However if I don't tick this box the form is still processed.

I must be missing something right in front of me. I am assuming that i can achieve this with just Spry, like all the other fields in the form.


This is my checkbox...

<span id="sprycheckbox1">
<input name="Terms" type="checkbox" id="Terms" value="1">
<span class="checkboxRequiredMsg">Please make a selection.</span></span></span>


And this is my spry code at the bottom of the form

var sprycheckbox1 = new Spry.Widget.ValidationCheckbox("sprycheckbox1", {validateOn:["blur", "change"]});


Any advice would be appreciated.

Sign in to reply to this post

Jason ByrnesWebAssist

A spry check box does not offer a required attribute to make it required when the form submits.


Instead, you should use sever validation on the checkbox to make it required.


In the server behaviors list, double click the server validation server behavior.

Select the Required / Not Blank from the validation type, then click the lightning bolt next to server variable and select the terms checkbox from the form collection.

Click the plus button to add this validation to the list.

Sign in to reply to this post

neilo

Hiya Jason,

Are you saying that the spry checkbox validation doesn't work alongside server-side validation, or that it just isn't an effective/reliable way of validating it? (Or that it just doesn't work?)

Sign in to reply to this post

Jason ByrnesWebAssist

Spry validation is always less effective and reliable than server validation since it relies on java script which can be turned off in the clients browser.

spry Can work alongside server validations.

In my experience server side validation is less temperamental than spry or other javascript based validations.

For example, the reason spry is not working in the OP's form, is the empty onsubmit attribute in the form tag:
<form action="" method="post" name="emailContact" id="emailContact" onsubmit="">

This is causing the spry validation to fail on the checkbox when the form submits. Remove the empty onsubmit attribute in the form tag:
<form action="" method="post" name="emailContact" id="emailContact">

and spry validation will function.

Sign in to reply to this post

neilo

Cheers Jason, thanks for all the info (At some point you may need to start billing me for it all).

I was looking into the onsubmit part of the form tag (I had some vague memory of s script I picked up somewhere, having forgotten about Spry altogether) and eventually

found it - also containing javascript - but that script worked by disabling the submit button until the 'I accept the terms and conditions' checkbox had been ticked.

I thought it might help Groshko a bit, but suppose that's probably only effective in conjunction with serverside validation too. I attach the instructions anyway.

---------------------------------------------------------------------------------------

Hiya Groshko,

I may be wrong, but I believe that having a few of the server error elements with the same name (nameServerError) might cause you problems with the serverside

validations and the error messages on the page . I believe that each $WAFV_Errors (as listed in the block of WA Server Validations near the beginning of your page)

should refer to a uniquely named server error elements. (I think the 'nameServerError' originally just applied to the 'Name' field).

So for instance, in line 15 in the contact_php file:

$WAFV_Errors .= WAValidateRQ(((isset($_POST["Address"]))?$_POST["Address"]:"") . "",true,2);


refers to an input 2, which is the Address input field so perhaps in that block you could change the references to 'nameServerArea' to 'AddressServerError', i.e:

<span id="sprytextarea1">
<textarea name="Address" class="inputText" id="Address" onblur="if (document.getElementById('AddressServerError'))

document.getElementById('AddressServerError').style.display='none'" ><?php echo(ValidatedField("contact","Address")) ?

></textarea>
<span class="textareaRequiredMsg">A value is required.</span></span>
<?php
if (ValidatedField("contact","contact")) {
if ((strpos((",".ValidatedField("contact","contact").","), "," . "3" . ",") !== false || "3" == "")) {
if (!(false)) {
?>
<span id="AddressServerError" class="textfieldServerError">Please enter your address here.<br />
</span>
<?php //WAFV_Conditional contact.php contact(2:)
}
}
}?>


---------------------------------------------------------------------------------------

Attachment is the bit of 'diable button' code from Dynamic Drive.

Sign in to reply to this post

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...