Do you guys noticed that in shoppingcart.aspx user can submit order without filling shipping address form. Though in the code proper validation is used. Just have a look at these images....Firstone is that where we need to fill shipping add....
The validation would not take place until the very end, when the form is submitted. That's how validation works.
The way the ShoppingCart is set up, only authenticated (logged-in) users can get to the shipping address step. If they leave the shipping fields blank, the fields are automatically filled in from their profile data.
If they leave the fields blank AND they have no data in their profile, and then try to submit the order, you should see the validation kick in at that point.
Yes you are right. Actually proper validation is used as shown in the following code, but still user is able to move ahead without providing shipping address. Why???[:^)]
--------------------------
<asp:WizardStep runat="server" Title="Shipping Address">
<div class="sectiontitle">Shipping Address</div>
<p></p>
<asp:MultiView ID="mvwShipping" runat="server">
<asp:View ID="vwLoginRequired" runat="server">
An account is required to proceed with the order submission. If you already have an account
please login now, otherwise <a href="Register.aspx">create a new account</a> for free.
<br /><br /><br /><br /><br /><br />
</asp:View>
<asp:View ID="vwShipping" runat="server">
Fill the form below with the shipping address for your order. All information is required, except for phone and fax numbers.
<p></p>
<table cellpadding="2" width="410">
<tr>
<td width="110" class="fieldname"><asp:Label runat="server" ID="lblFirstName" AssociatedControlID="txtFirstName" Text="First name:" /></td>
<td width="300">
<asp:TextBox ID="txtFirstName" runat="server" Width="100%" />
<asp:RequiredFieldValidator ID="valRequireFirstName" runat="server" ControlToValidate="txtFirstName" SetFocusOnError="true" ValidationGroup="ShippingAddress"
Text="The First Name field is required." ToolTip="The First Name field is required." Display="Dynamic"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td class="fieldname"><asp:Label runat="server" ID="lblLastName" AssociatedControlID="txtLastName" Text="Last name:" /></td>
<td>
<asp:TextBox ID="txtLastName" runat="server" Width="100%" />
<asp:RequiredFieldValidator ID="valRequireLastName" runat="server" ControlToValidate="txtLastName" SetFocusOnError="true" ValidationGroup="ShippingAddress"
Text="The Last Name field is required." ToolTip="The Last Name field is required." Display="Dynamic"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td class="fieldname"><asp:Label runat="server" ID="lblEmail" AssociatedControlID="txtEmail" Text="E-mail:" /></td>
<td>
<asp:TextBox runat="server" ID="txtEmail" Width="100%" />
<asp:RequiredFieldValidator ID="valRequireEmail" runat="server" ControlToValidate="txtEmail" SetFocusOnError="true" ValidationGroup="ShippingAddress"
Text="The E-mail field is required." ToolTip="The E-mail field is required." Display="Dynamic"></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator runat="server" ID="valEmailPattern" Display="Dynamic" SetFocusOnError="true" ValidationGroup="ShippingAddress"
ControlToValidate="txtEmail" ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"
Text="The E-mail address you specified is not well-formed." ToolTip="The E-mail address you specified is not well-formed."></asp:RegularExpressionValidator>
</td>
</tr>
<tr>
<td class="fieldname"><asp:Label runat="server" ID="lblStreet" AssociatedControlID="txtStreet" Text="Street:" /></td>
<td>
<asp:TextBox runat="server" ID="txtStreet" Width="100%" />
<asp:RequiredFieldValidator ID="valRequireStreet" runat="server" ControlToValidate="txtStreet" SetFocusOnError="true" ValidationGroup="ShippingAddress"
Text="The Street field is required." ToolTip="The Street field is required." Display="Dynamic"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td class="fieldname"><asp:Label runat="server" ID="lblPostalCode" AssociatedControlID="txtPostalCode" Text="Zip / Postal code:" /></td>
<td>
<asp:TextBox runat="server" ID="txtPostalCode" Width="100%" />
<asp:RequiredFieldValidator ID="valRequirePostalCode" runat="server" ControlToValidate="txtPostalCode" SetFocusOnError="true" ValidationGroup="ShippingAddress"
Text="The Postal Code field is required." ToolTip="The Postal Code field is required." Display="Dynamic"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td class="fieldname"><asp:Label runat="server" ID="lblCity" AssociatedControlID="txtCity" Text="City:" /></td>
<td>
<asp:TextBox runat="server" ID="txtCity" Width="100%" />
<asp:RequiredFieldValidator ID="valRequireCity" runat="server" ControlToValidate="txtCity" SetFocusOnError="true" ValidationGroup="ShippingAddress"
Text="The City field is required." ToolTip="The City field is required." Display="Dynamic"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td class="fieldname"><asp:Label runat="server" ID="lblState" AssociatedControlID="txtState" Text="State / Region:" /></td>
<td>
<asp:TextBox runat="server" ID="txtState" Width="100%" />
<asp:RequiredFieldValidator ID="valRequireState" runat="server" ControlToValidate="txtState" SetFocusOnError="true" ValidationGroup="ShippingAddress"
Text="The State field is required." ToolTip="The State field is required." Display="Dynamic"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td class="fieldname"><asp:Label runat="server" ID="lblCountry" AssociatedControlID="ddlCountries" Text="Country:" /></td>
<td>
<asp:DropDownList ID="ddlCountries" runat="server" AppendDataBoundItems="True" Width="100%">
<asp:ListItem Text="Please select one..." Value="" Selected="True" />
</asp:DropDownList>
</td>
</tr>
<tr>
<td class="fieldname"><asp:Label runat="server" ID="lblPhone" AssociatedControlID="txtPhone" Text="Phone:" /></td>
<td><asp:TextBox runat="server" ID="txtPhone" Width="100%" /></td>
</tr>
<tr>
<td class="fieldname"><asp:Label runat="server" ID="lblFax" AssociatedControlID="txtFax" Text="Fax:" /></td>
<td><asp:TextBox runat="server" ID="txtFax" Width="100%" /></td>
</tr>
</table>
<br /><br />
</asp:View>
</asp:MultiView>
</asp:WizardStep>
-------------------------------
“Do not go where the path may lead, go instead where there is no path and leave a trail.”- Waldo Emerson
This works for any wizard. Basically, just capture the event that fires when the user clicks the button to go forward. Then test for validity, and if necessary cancel the click using the WizardNavigationEventArgs object.
The call to Page.IsValid lets you test for validity at any point in the process, instead of waiting until form submission at the end.
Not what I was thinking. I was thinking about extending it to actually validating against a zip code database. At least taking it to that extreme. My issue right now is I have a zip code database that would not fall under a license I could distribute with
the book. I think I may have a way to do something like I want.
I realize that would not work for outside the US, but the infrastructure would be doable, etc. I guess when I see validate something like that I am thinking more about is this a viable address, not just are the fields filled in.
Okay, I see. I assume if you're going beyond Required and/or Regex validation, you'd be using a web service for this (i.e., USPS CASS/MASS system) as zip codes change rather frequently.
call me a brit, but i can't see a lot of value in merely validating arbitary coloquial code (the us zip codes) based on a specific delta (that's not to say that i don't appreciate that validation by example per se is invalid). by virtue that the creative
commons lic may be an problem here, demonstrates the 'internationalisation' issue totally. 'we' should be looking at solutions that are as applicable in kentucky as they are in kabul. to this end please by all means explore this facet [and even include it
as a 'business logic' option] but be aware that presenting such a 'solution' may alienate a vast section of potential [other world] readers (even tho' in fairness, you acknowledge this parochial fact).
i'm not saying DON'T use what is easily to hand as an example, just that a generic way may give you more mileage/respect [or is that kilometereage] than one that exposes any paticular bias.
mind you, we brits were among the worst in the last but one century for our 'world' view [:)] - think more, code less...i do honestly 'feel' for you on this (thorny localisation) issue!
hopefully, coming across as considered, rather than brittle!!
Exactly what I was thinking, the problem is I do not know of a web service to hit to validate against other countries right now. I am thinking of a few things for the US and one might do Canada and maybe the UK. But I have an articeture idea that might work
to exapnd it out.
WebEye
Member
26 Points
27 Posts
Why Shipping address is not validated?
Sep 18, 2008 02:46 AM|LINK
Hi,
Do you guys noticed that in shoppingcart.aspx user can submit order without filling shipping address form. Though in the code proper validation is used. Just have a look at these images....Firstone is that where we need to fill shipping add....
[URL=http://img228.imageshack.us/my.php?image=shoppingcartonelm2.png][IMG]http://img228.imageshack.us/img228/6648/shoppingcartonelm2.th.png[/IMG][/URL]
Second one is the final step.We can move to final step without filling shipping add...
[URL=http://img228.imageshack.us/my.php?image=shoppingcarttwowq8.png][IMG]http://img228.imageshack.us/img228/907/shoppingcarttwowq8.th.png[/IMG][/URL]
Lee Dumond
Contributor
6404 Points
1173 Posts
Re: Why Shipping address is not validated?
Sep 18, 2008 03:29 PM|LINK
The validation would not take place until the very end, when the form is submitted. That's how validation works.
The way the ShoppingCart is set up, only authenticated (logged-in) users can get to the shipping address step. If they leave the shipping fields blank, the fields are automatically filled in from their profile data.
If they leave the fields blank AND they have no data in their profile, and then try to submit the order, you should see the validation kick in at that point.
Follow Me on Twitter
WebEye
Member
26 Points
27 Posts
Re: Why Shipping address is not validated?
Sep 18, 2008 04:47 PM|LINK
Yes you are right. Actually proper validation is used as shown in the following code, but still user is able to move ahead without providing shipping address. Why???[:^)]
--------------------------
<asp:WizardStep runat="server" Title="Shipping Address"> <div class="sectiontitle">Shipping Address</div> <p></p> <asp:MultiView ID="mvwShipping" runat="server"> <asp:View ID="vwLoginRequired" runat="server"> An account is required to proceed with the order submission. If you already have an account please login now, otherwise <a href="Register.aspx">create a new account</a> for free. <br /><br /><br /><br /><br /><br /> </asp:View> <asp:View ID="vwShipping" runat="server"> Fill the form below with the shipping address for your order. All information is required, except for phone and fax numbers. <p></p> <table cellpadding="2" width="410"> <tr> <td width="110" class="fieldname"><asp:Label runat="server" ID="lblFirstName" AssociatedControlID="txtFirstName" Text="First name:" /></td> <td width="300"> <asp:TextBox ID="txtFirstName" runat="server" Width="100%" /> <asp:RequiredFieldValidator ID="valRequireFirstName" runat="server" ControlToValidate="txtFirstName" SetFocusOnError="true" ValidationGroup="ShippingAddress" Text="The First Name field is required." ToolTip="The First Name field is required." Display="Dynamic"></asp:RequiredFieldValidator> </td> </tr> <tr> <td class="fieldname"><asp:Label runat="server" ID="lblLastName" AssociatedControlID="txtLastName" Text="Last name:" /></td> <td> <asp:TextBox ID="txtLastName" runat="server" Width="100%" /> <asp:RequiredFieldValidator ID="valRequireLastName" runat="server" ControlToValidate="txtLastName" SetFocusOnError="true" ValidationGroup="ShippingAddress" Text="The Last Name field is required." ToolTip="The Last Name field is required." Display="Dynamic"></asp:RequiredFieldValidator> </td> </tr> <tr> <td class="fieldname"><asp:Label runat="server" ID="lblEmail" AssociatedControlID="txtEmail" Text="E-mail:" /></td> <td> <asp:TextBox runat="server" ID="txtEmail" Width="100%" /> <asp:RequiredFieldValidator ID="valRequireEmail" runat="server" ControlToValidate="txtEmail" SetFocusOnError="true" ValidationGroup="ShippingAddress" Text="The E-mail field is required." ToolTip="The E-mail field is required." Display="Dynamic"></asp:RequiredFieldValidator> <asp:RegularExpressionValidator runat="server" ID="valEmailPattern" Display="Dynamic" SetFocusOnError="true" ValidationGroup="ShippingAddress" ControlToValidate="txtEmail" ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*" Text="The E-mail address you specified is not well-formed." ToolTip="The E-mail address you specified is not well-formed."></asp:RegularExpressionValidator> </td> </tr> <tr> <td class="fieldname"><asp:Label runat="server" ID="lblStreet" AssociatedControlID="txtStreet" Text="Street:" /></td> <td> <asp:TextBox runat="server" ID="txtStreet" Width="100%" /> <asp:RequiredFieldValidator ID="valRequireStreet" runat="server" ControlToValidate="txtStreet" SetFocusOnError="true" ValidationGroup="ShippingAddress" Text="The Street field is required." ToolTip="The Street field is required." Display="Dynamic"></asp:RequiredFieldValidator> </td> </tr> <tr> <td class="fieldname"><asp:Label runat="server" ID="lblPostalCode" AssociatedControlID="txtPostalCode" Text="Zip / Postal code:" /></td> <td> <asp:TextBox runat="server" ID="txtPostalCode" Width="100%" /> <asp:RequiredFieldValidator ID="valRequirePostalCode" runat="server" ControlToValidate="txtPostalCode" SetFocusOnError="true" ValidationGroup="ShippingAddress" Text="The Postal Code field is required." ToolTip="The Postal Code field is required." Display="Dynamic"></asp:RequiredFieldValidator> </td> </tr> <tr> <td class="fieldname"><asp:Label runat="server" ID="lblCity" AssociatedControlID="txtCity" Text="City:" /></td> <td> <asp:TextBox runat="server" ID="txtCity" Width="100%" /> <asp:RequiredFieldValidator ID="valRequireCity" runat="server" ControlToValidate="txtCity" SetFocusOnError="true" ValidationGroup="ShippingAddress" Text="The City field is required." ToolTip="The City field is required." Display="Dynamic"></asp:RequiredFieldValidator> </td> </tr> <tr> <td class="fieldname"><asp:Label runat="server" ID="lblState" AssociatedControlID="txtState" Text="State / Region:" /></td> <td> <asp:TextBox runat="server" ID="txtState" Width="100%" /> <asp:RequiredFieldValidator ID="valRequireState" runat="server" ControlToValidate="txtState" SetFocusOnError="true" ValidationGroup="ShippingAddress" Text="The State field is required." ToolTip="The State field is required." Display="Dynamic"></asp:RequiredFieldValidator> </td> </tr> <tr> <td class="fieldname"><asp:Label runat="server" ID="lblCountry" AssociatedControlID="ddlCountries" Text="Country:" /></td> <td> <asp:DropDownList ID="ddlCountries" runat="server" AppendDataBoundItems="True" Width="100%"> <asp:ListItem Text="Please select one..." Value="" Selected="True" /> </asp:DropDownList> </td> </tr> <tr> <td class="fieldname"><asp:Label runat="server" ID="lblPhone" AssociatedControlID="txtPhone" Text="Phone:" /></td> <td><asp:TextBox runat="server" ID="txtPhone" Width="100%" /></td> </tr> <tr> <td class="fieldname"><asp:Label runat="server" ID="lblFax" AssociatedControlID="txtFax" Text="Fax:" /></td> <td><asp:TextBox runat="server" ID="txtFax" Width="100%" /></td> </tr> </table> <br /><br /> </asp:View> </asp:MultiView> </asp:WizardStep>-------------------------------Lee Dumond
Contributor
6404 Points
1173 Posts
Re: Why Shipping address is not validated?
Sep 18, 2008 05:17 PM|LINK
Why? Because validation doesn't take place until you try to submit the form. Merely "moving ahead" in the form is not the same as submitting it.
If you want the validation to fire when the user moves ahead, before the form is submitted, you have to do that in the code behind.
Follow Me on Twitter
docluv
Star
12685 Points
2005 Posts
ASPInsiders
MVP
Re: Why Shipping address is not validated?
Oct 03, 2008 05:36 PM|LINK
I am on your side, I will see about making that happen. You gave me an idea too, I will have to see if I can implement it under creative commons. :)
Lee Dumond
Contributor
6404 Points
1173 Posts
Re: Why Shipping address is not validated?
Oct 03, 2008 06:23 PM|LINK
This is already implementable in the framework as it stands.
Just set up validation as normal. Then, you would do something like this (this example is for a CreateUserWizard form):
This works for any wizard. Basically, just capture the event that fires when the user clicks the button to go forward. Then test for validity, and if necessary cancel the click using the WizardNavigationEventArgs object.
The call to Page.IsValid lets you test for validity at any point in the process, instead of waiting until form submission at the end.
Follow Me on Twitter
docluv
Star
12685 Points
2005 Posts
ASPInsiders
MVP
Re: Why Shipping address is not validated?
Oct 03, 2008 08:14 PM|LINK
Not what I was thinking. I was thinking about extending it to actually validating against a zip code database. At least taking it to that extreme. My issue right now is I have a zip code database that would not fall under a license I could distribute with the book. I think I may have a way to do something like I want.
I realize that would not work for outside the US, but the infrastructure would be doable, etc. I guess when I see validate something like that I am thinking more about is this a viable address, not just are the fields filled in.
Lee Dumond
Contributor
6404 Points
1173 Posts
Re: Why Shipping address is not validated?
Oct 03, 2008 08:41 PM|LINK
Okay, I see. I assume if you're going beyond Required and/or Regex validation, you'd be using a web service for this (i.e., USPS CASS/MASS system) as zip codes change rather frequently.
Follow Me on Twitter
jimibt
Member
724 Points
185 Posts
Re: Why Shipping address is not validated?
Oct 04, 2008 08:49 PM|LINK
call me a brit, but i can't see a lot of value in merely validating arbitary coloquial code (the us zip codes) based on a specific delta (that's not to say that i don't appreciate that validation by example per se is invalid). by virtue that the creative commons lic may be an problem here, demonstrates the 'internationalisation' issue totally. 'we' should be looking at solutions that are as applicable in kentucky as they are in kabul. to this end please by all means explore this facet [and even include it as a 'business logic' option] but be aware that presenting such a 'solution' may alienate a vast section of potential [other world] readers (even tho' in fairness, you acknowledge this parochial fact).
i'm not saying DON'T use what is easily to hand as an example, just that a generic way may give you more mileage/respect [or is that kilometereage] than one that exposes any paticular bias.
mind you, we brits were among the worst in the last but one century for our 'world' view [:)] - think more, code less...i do honestly 'feel' for you on this (thorny localisation) issue!
hopefully, coming across as considered, rather than brittle!!
jimi
docluv
Star
12685 Points
2005 Posts
ASPInsiders
MVP
Re: Why Shipping address is not validated?
Oct 05, 2008 12:29 AM|LINK
Jim,
Exactly what I was thinking, the problem is I do not know of a web service to hit to validate against other countries right now. I am thinking of a few things for the US and one might do Canada and maybe the UK. But I have an articeture idea that might work to exapnd it out.
Chris