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

Checkout Page Form Field Validation

Thread began 12/10/2009 6:34 pm by Kevin373660 | Last modified 12/16/2009 8:43 pm by Eric Mittman | 14092 views | 7 replies |

Kevin373660

Checkout Page Form Field Validation

Using eCart 4.5.2 and the Validation Tool Kit 2.3.5 I would like to set up validation for the fields in the checkout.php form that contains both the users Billing and Shipping information. I have done this before for single forms however I am not sure how to approach this if:

1. The user may select the option “Same as billing address” which allows the shipping fields to be automatically populated.

2. If an order does not require Shipping information, as in the case of items that do not need to be shipped (ex. digital downloads).

I have set up a session variable that will tell if the order needs shipping services. Currently, only a message pops up to say that this information is not required. I would prefer to hide that part of the form if not required. I believe that it is called a show/hide region server behaviour but I have never had success trying to create on my own.

From what I have read I belive that I need to split the form in two and use the same name for both? What is the best approach to show/hide the shipping part and apply validation to both sections billing and shipping?

Sign in to reply to this post

Eric Mittman

If you are using the value of a session variable to determine if shipping is needed or not then you can do this server side with an if statement and your session variable like this:

php:
if($_SESSION['your shippable session var'] != 1){


// the shipping portion of the form goes here

}



With this in place you can do this all with server validations. On the confirm page that this is posting to you will want to ensure that you have the validations for the various fields. You can add a similar if statement around the specific validations for the shipping fields. This way if shipping info is not required the form will not request it and the validations will not run against those elements.

If you omit the shipping values then you may want to use this same logic for the display on the confirm and checkout success pages.

Sign in to reply to this post

Kevin373660

Hi Eric, the Billing & Shipping show/hide works well. I have most of the validation part completed for the checkout.php page. As attached. But I need a little bit more help.

I ran into a problem retaining the variable input bindings on the checkout when the validation returns from the confirm back to the checkout page, if there are errors. I bound the form values to the fields on the checkout page. The values pass the validtion code on the confirm page but are lost when page is redirected back. What is the trick to retain them? Please and thanks.

Sign in to reply to this post

Eric Mittman

One way that you could do this would be to move your set session value server behaviors on your confirm page to be above the validation code. You may need to add a few in also in case there are values you are currently not setting in session variables.

If the values from the form are set in session variables before they are validated you can just set the value of the fields on your checkout page to be these session variables. That way if these variables are set they will be the default values on the checkout page.

Sign in to reply to this post

Kevin373660

Setting the session for each form input on the confirm.php page and binding these to the form fields on the checkout page works great! Except for the dynamic menu/list for the State and Country selections.

Tip for others in forum: When Binding a menu/list to a session value use the Design view, place curser on the leftside of the form field and use the Tab key to select the form box. Then select the appropriate binding element from Application-Bindings and click on the Insert button at the bottom of the Bindings window. The session value will instert a "title=" echo <session>"" entry into the form code.

If returned back to the confirm page, when a State is selceted the validation error message hides and when you hover over the field the value displays. The session is set to hold the "value" not the label (ex. label=New York, value=NY). The value is required next to process the courier and payment functions. So in a sense the valiation is working correctly. However, the user sees a blank label with the state name in the from field. I think that I ran into this before and look at my other code but in that case I was using both server and client validation. What can I do so that the customer does not need reselect?


***********************************
<tr>
<th><label for="state_province" >State</label></th>
<td><select name="state_province" id="state_province" style="width:200px;" tabindex="7" title="<?php echo $_SESSION['eCartCheckoutForm_state_province']; ?>">
<option value="<?php echo $_SESSION['eCartCheckoutForm_state_province']; ?>" <?php
if (ValidatedField('checkout','checkout')) {
if ((strpos((",".ValidatedField("checkout","checkout").","), "," . "7" . ",") !== false || "7" == "")) {
if (!(false)) {
?>
class="fail"
<?php //WAFV_Conditional checkout.php checkout(7:)
}
}
}?>></option>
<?php
do {
?>
<option value="<?php echo $row_BillState['state_Abrv']?>"><?php echo $row_BillState['statePrintable']?></option>
<?php
} while ($row_BillState = mysql_fetch_assoc($BillState));
$rows = mysql_num_rows($BillState);
if($rows > 0) {
mysql_data_seek($BillState, 0);
$row_BillState = mysql_fetch_assoc($BillState);
}
?>
</select></td>
<td class="CkOutValidationErrors"><?php
if (ValidatedField('checkout','checkout')) {
if ((strpos((",".ValidatedField("checkout","checkout").","), "," . "7" . ",") !== false || "7" == "")) {
if (!(false)) {
?>
* Please select state.
<?php //WAFV_Conditional checkout.php checkout(7:)
}
}
}?></td>
</tr>

Sign in to reply to this post

Eric Mittman

I think the suggestions that you read were for getting a dynamic value into the select list, that is not what you should be trying to do here. Instead you should just be setting the selected value based on your session variable. To do this you would select the list in design view and in the property inspector click on the dynamic button. In this interface use the lightning bolt icon next to the 'Select value equal to' field to select your session variable that holds this value. I'm including a screen shot of what this dynamic interface looks like for a select list for your reference.

Sign in to reply to this post

Kevin373660

I got the billing and shipping country to retain the session values. But... State billing and shipping fields initally display the line of the state recordset (no sort) which has the value="" label=United States as its first record entry in db. It just looks confussing for the customer if you know what I mean State: [Uniited States]. In the states table have used a country heading with no value for various countries.

Through DW Dynamic List/Menu similar to your screen shot I had a blank Static option for value & label and I tried as per attached to enter the lable=Select State, neither seem work.

When you click on the dropdown list, the value "Select State" is visable above the label "United States" it just wants to pick the first table value first.

Any ideas of what I may have done wrong?

Sign in to reply to this post

Eric Mittman

I having difficulty creating an example like the problem you are experiencing so it is difficult for me to determine what may be going wrong. Looking at the select list dynamic properties it seems to be set correctly. Is it possible for you to post back with your states table so that I can test this out further using your info?

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