close ad
WARNING: Do Not Install the DREAMWEAVER CC 2017 Update »
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

Required Fields if Checkbox Selected

Thread began 7/01/2013 5:10 pm by Daryl | Last modified 7/15/2013 5:27 pm by Jason Byrnes | 911 views | 23 replies |

DarylBeta Tester

Required Fields if Checkbox Selected

Is there a way that I can make a text field or text fields required if a particular checkbox from a group of checkboxes is selected?

Sign in to reply to this post

Jason ByrnesWebAssist

Takes a little hand coding but conditional validation can be done, see the following post by Ray for details:
showpost.php?p=3355&postcount=4

Sign in to reply to this post

DarylBeta Tester

Hi Jason

That mostly makes sense to me, however I am using a radio button group and I would like the validation to work if a specific radio button is checked.

The way Form Builder has made the group means that all of them have the same name but a different id.

Sign in to reply to this post

Jason ByrnesWebAssist

ok, using rays example of the phone number field

  <?php echo((isset($_POST['phoneNumber'])?$_POST['phoneNumber']:"")); ?>

Now update it to use:
<?php echo((isset($_POST['callMe'])?$_POST['phoneNumber']:"(222) 222-2222")); ?>  



you could update that to compare the call me field to a specific value:
<?php echo(((isset($_POST['callMe']) && $_POST['callMe'] = "yes")?$_POST['phoneNumber']:"(222) 222-2222")); ?>

Sign in to reply to this post

DarylBeta Tester

I have tried replicating the code that you have suggested based on the code generated by Form Builder.

I have ended up with

php:
<?php echo((isset($_GET["EmploymentStatus"]) && $_GET['EmploymentStatus'] = "Employed")?ValidatedField("ApplicationForm","EmployersName"):"")); ?>



However this produces a Syntax error in dreamweaver.

I wasnt sure what I would use for the validation part, you used a telephone number example, as this is just a required field

Code for the Radio Button

php:
<input type="radio" name="EmploymentStatus" id="EmploymentStatus__1" value="Employed" class="formRadioField_Standard" <?php if (!(strcmp((isset($_GET["invalid"])?ValidatedField("ApplicationForm","EmploymentStatus"):""),"Employed"))) {echo "checked=\"checked\"";} ?> tabindex="19">



Code for the Form Field that only requires validation if the above button is checked

php:
<input id="EmployersName" name="EmployersName" type="text" value="<?php echo((isset($_GET["invalid"])?ValidatedField("ApplicationForm","EmployersName"):"")); ?>" class="formTextfield_Large" tabindex="24" onBlur="hideServerError('EmployersName_ServerError');">



Also I am unsure as to why everything is $_GET when the form was created as $_POST and also submits using $_POST

Sign in to reply to this post

Jason ByrnesWebAssist

I dont believe you aere editing the correct code.

it looks like you editing the value of the form element and not the server validations

send a copy of the page with out the change, and i can tell you what code needs to be edited.

Sign in to reply to this post

DarylBeta Tester

I have attached the page as requested.

I also get a Syntax error for one of the Spry Validations but have found that if I manually change the code as the names dont match then it is ok. I am unsure why this is happening as this is generated code.

Thank you Jason!

Attached Files
ApplicationForm.zip
Sign in to reply to this post

Jason ByrnesWebAssist

ok, so the required validation for the employers name is at line 22:

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

to make that required only if the Employment status is set to employed, change that to:
$WAFV_Errors .= WAValidateRQ(((isset($_POST["EmploymentStatus"]) && $_POST["EmploymentStatus"] == "Employed")?$_POST["EmployersName"]:"") . "NA",true,12);

as for the spry validation, which one is giving the syntax error?

one issue i see in your form is that you have some form element names that are not valid.

for exaample the declaration select lists use numbers and the underscore character as the first character in the name. When naming form elements, you should follow these rules:

1) only use letters and numbers, the only exception is the underscore.
2) The first character of a form element name must be a letter.


NOTE: You will need to delete the following line for spry validation, spry does not support conditional validation:
var EmployersName_Spry = new Spry.Widget.ValidationTextField("EmployersName_Spry", "none",{validateOn:["blur"]});

Sign in to reply to this post

DarylBeta Tester

Thank you for the comment about the numbering issue. It was just because it was question 1, question 2 etc.

I have change this and it has sorted the Syntax error that was occuring

Sign in to reply to this post

Jason ByrnesWebAssist

Yeah, spaces cant be used in form element names either, instead of "question 1" for the name, you should use "question_1" or "question1"

Sign in to reply to this post
loading

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