close ad
 
Important WebAssist Announcement
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

Validating form fields if a particular value in a radio button is selected

Thread began 6/21/2011 3:07 am by lightwalkercreations361768 | Last modified 7/05/2011 7:56 am by Jason Byrnes | 2588 views | 5 replies |

lightwalkercreations361768Beta Tester

Validating form fields if a particular value in a radio button is selected

Dear WebAssist,

Is there a way to be able to validate certain form fields only if a particular radio button is selected. For instance if I have a radio button that has option 1 and option 2. If option 1 is selected then Form Toolkit will validate textbox 1, but if the radio button option 2 is selected then validation toolkit will validate textbox 2 but not textbox 1 etc.

Would this be possible? and what would be the best way to do it?

Many thanks as always for your help

Sign in to reply to this post

Jason ByrnesWebAssist

it takes a little bit of hand coding to accomplish this, but it can be done using server side validation.

Use the required / not blank / selection made validation type.

for the sever variable, click the lightning bolt and select the radio group, this will add code similar to:

php:
<?php echo((isset($_POST["RadioGroup"]))?$_POST["RadioGroup"]:""?>



edit that to:

php:
<?php echo((isset($_POST["RadioGroup"]) && $_POST["RadioGroup"] == "1")?$_POST["textfield"]:"ok"?>




this tells it to check if Radio group has a value of 1. Id so, it passes the value of textfield for validation, if not it passes the value "ok" for validation which will pass.

add a second required validation, this time use the server variable:

php:
<?php echo((isset($_POST["RadioGroup"]) && $_POST["RadioGroup"] == "2")?$_POST["textfield2"]:"ok"?>



this checks the radio group for the value 2, if so, it validates the textfield2 form element

Sign in to reply to this post

lightwalkercreations361768Beta Tester

Dear Jason,

Thank you that make's perfect sense. Thank you for being so clear. I will give it a go. Many thanks as always for your support.

Sign in to reply to this post

Jason ByrnesWebAssist

you're welcome

Sign in to reply to this post

lightwalkercreations361768Beta Tester

Dear Jason,

Thank you for your help. I tried following you example but I am getting a syntax error and I am afraid I do not know enough to fix it or know what might be happening. Could you take a look at where I have gone wrong. I have included the php file.

Many thanks as always

Attached Files
form_test.php.zip
Sign in to reply to this post

Jason ByrnesWebAssist

what is the error?

I need the exact error, including the line number to know where to look and what to look for.

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