close ad
Help us test the new Databridge BETA with MySQLi support
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

require a field based on different field selection

Thread began 12/28/2012 7:10 pm by bryan107833 | Last modified 4/18/2013 12:14 pm by bryan107833 | 1204 views | 9 replies |

bryan107833

require a field based on different field selection

I am attempting to figure out how to require a field based on the selection of a different dropdown list with server validation. Can someone help with this? Thank you.

I need to charge different tax based on different county within a state. I have created a county dropdown list that will only appear if specific state is selected but I want to obviously require the selection of the county only if specific state is selected.

Is there a better way to charge different tax based on state and county? My client ships products from a couple of states. Some have different tax based on county some do not. I believe I have the easiest solution if I can just add this one more piece.

Sign in to reply to this post

Jason ByrnesWebAssist

here is a thread that talks about doing conditional validation:
showpost.php?p=3355&postcount=4

the example given is for a phone number field, but the same idea can be used for a State / County field ax well.

Sign in to reply to this post

bryan107833

Thank you, that was helpful but I am still a little short. (Part of my problem is also that the page I need to update was created with your previous validation toolkit which works very differently and is no longer avail through Dreamweaver now that I have updated to the newer Super Suite. - thus I it would appear that I need to delete all of the old validation on the checkout page and start fresh with your newer system.)

Two additional questions:
I see how this code will require validation if another field has a value, but I need it to validate only if that field has a specific value. i.e. shipping_state = NY. How would I amend this code for this.

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

Also, is there a reason in this example you sent that you filled in the phone number (222)222-2222 and did not just leave it blank as ""?

All the above will be necessary for the future but in regard the site that I am currently working can you show me how to edit the code below so that it could be added to validate the county field based on the shipping_state_province value being NY? It appears that I may need it to validate (require the county field) for both NY and PA so if you could also show me the adapted code if I need both NY & PA that would be great. (This would be much quicker / easier in this case then transferring to the newer Webasssist system.)

WAValidateRQ(document.forms[2].shipping_state_province,'- Please select Shipping State / Province',document.forms[2].shipping_state_province,0,true,'select');

Thank you.

Sign in to reply to this post

Jason ByrnesWebAssist

to validate a specific value, you would amend the code to this:

php:
<?php echo(((isset($_POST['callMe']) && $_POST['callMe'] == "NY")?$_POST['phoneNumber']:"(222) 222-2222")); ?>




in this example, it is using phone number validation, so a valid phone number needs to be passed as the conditional validation. If it where using Required validation, than a string would need to be used.

the code you provided is for client side validation. we dont use client side validation in the current version of super suite since it is easily disabled by disabling javascript in the browser, you should use server side validation instead.

Sign in to reply to this post

bryan107833

Ok, I understand that I should update the page with the server validation but I am still a little bit confused. I have examined a confirm page that I just created (different site) that is using the server validation and I not finding code like what you have mentioned above. The new code that I believe you are referencing looks like -

$WAFV_Errors .= WAValidateAN(((isset($_POST["shipping_state_province"]))?$_POST["shipping_state_province"]:"") . "",true,true,true,true,"",true,19);

would I amend this to:

$WAFV_Errors .= WAValidateAN(((isset($_POST["shipping_state_province"]) && $_POST["shipping_state_province"] == "NY")?$_POST["county"]:"") . "",true,true,true,true,"",true,19);

I see in your example the field callMe he ' around it instead of ". Will either work based on this updated code?

Would this be the correct code if I want it to validate on either NY or PA?

$WAFV_Errors .= WAValidateAN(((isset($_POST["shipping_state_province"]) && $_POST["shipping_state_province"] == "NY") || $_POST["shipping_state_province"] == "PA")?$_POST["county"]:"") . "",true,true,true,true,"",true,19);

Thank you again.

Sign in to reply to this post

Jason ByrnesWebAssist

do not edit the code directly, you should be editing the Server Validation server behavior rather than editing the page in code view.

Sign in to reply to this post

bryan107833

Ok...but I still need to hand write the code with the server behavior. This being the case would this be the correct code?

<?php echo((isset($_POST["shipping_state_province"]) && $_POST["shipping_state_province"] == "NY")?$_POST["county"]:"") ?>

If yes, and I wanted to validate on NY or PA would this be correct?

<?php echo((isset($_POST["shipping_state_province"]) && $_POST["shipping_state_province"] == "NY") || $_POST["shipping_state_province"] == "PA")?$_POST["county"]:"") ?>

Thank you.

Sign in to reply to this post

Jason ByrnesWebAssist

the correct code to validate the county if state province is NY would be:

php:
<?php echo(((isset($_POST['shipping_state_province']) && $_POST['shipping_state_province'] == "NY")?$_POST['county']:"NA")); ?>



the correct code for NY OR PA would be:

php:
<?php echo(((isset($_POST['shipping_state_province']) && ($_POST['shipping_state_province'] == "NY" || $_POST['shipping_state_province'] == "PA"))?$_POST['county']:"NA")); ?>
Sign in to reply to this post

bryan107833

It just came to me what was going on.... I had not placed the county field into the hidden elements on the confirm page form so when the customer was hitting submit and it was processing again to the confirm page but this time the county variable was not being sent again to the page.

Sign in to reply to this post

Jason ByrnesWebAssist

on the confirm page, add the following hidden elements at line 1568:

php:
<input type="hidden" name="ship_county_ny" id="shipping_country" value="<?php echo ((isset($_SESSION["eCartCheckoutForm_ship_county_ny"]))?$_SESSION["eCartCheckoutForm_ship_county_ny"]:""?>" />

<input type="hidden" name="ship_county_pa" id="shipping_country" value="<?php echo ((isset($_SESSION["eCartCheckoutForm_ ship_county_pa"]))?$_SESSION["eCartCheckoutForm_ ship_county_pa"]:""?>" />
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...