Developer forum

Forum » Development » Cart step 4: server side validation for checkbox General Conditions

Cart step 4: server side validation for checkbox General Conditions


Reply

We’re using DW version 19.0.0.4.
 

In the cart step 4 we have a checkbox you’ve to check to agree with the General Conditions.
 

We have client side javascript validation for this (just like in the bikez demo), but also want server side validation.
 

We’ve made a notification for Dynamicweb.Notifications.eCommerce.Order.Steps.Confimed.
That requests the posted value of the checkbox by using HttpContext.Current.Request.Form. If it’s not checked we throw an exception.
This works fine if we don’t use a paymentprovider.


But if we use a payment provider, the user is redirected from step 4 to the paymentprovider, and then redirected to step 5: the agreedWithCondition checkbox value isn’t posted, so you get an exception.
That’s logical, but not the wanted behavior. ;)


How can we implement server side validation for a checkbox General Conditions in step 4?
 


Replies

 
Reply

Hi Marcel,

Last year we implemented the Validation Groups feature in the Configurations menu to accomodate the need for server side validation in eCommerce since other approaches, as you describe youself, are likely to fail due to behavior of the check-out process.

To implement this you would need to make an order field from Settings -> Order fields and then create a validation group that performs validation on this field and the others you want to validate server side. Finally you need to apply this validation group to the paragraph settings of your cart and you should expect to do some minor modifications to your template to have custom fields and validation messages included.

This article explains in detail how to implement validation: http://engage.dynamicweb-cms.com/Order-step-validation-184.aspx

 
Reply

Thanks for your reply Lars.
 

We already have server side validation for the Customer data (step 2).
We didn't know that this validation is also possible for step 3 and 4. Nice :)


What we've just done:
1. Created a new custom order field 'AcceptGeneralConditions' of type checkbox.
2. Created a new validationGroup 'AcceptGeneralConditions' where we set the custom order field 'AcceptGeneralConditions' required.
3. In the AcceptCart.html template we've added loops for the ValidationErrors.
4. In the cart module settings we've added the validationGroup 'AcceptGeneralConditions'.


However, when we try to order something, we can't get further than step 2, but we don't get any error message.
When we remove the validationgroup 'AcceptGeneralConditions' it works fine.

 
Reply
We still haven't got server side validation in step 4, because we had to disable it.

Because if we enable server side validation for the checkbox (custom field) in step 4, we can't get further than step 2 in the order proces, but we don't get any error message..

What do we do wrong?
 
Reply
Hi

Custom order fields are assumed to be entered in step 2. This means that the server side validation will look for the field when step 2 is submitted.

You should get an error message in the tag:
Ecom:Cart.ValidationError.<YourFieldSystemName>.ErrorMessage

You can also loop through all errors with the loop:
ValidationErrors
 
Reply
We already had server side validation working for step 2, but now we also want server side validation for a checkbox in step 4.

According to http://engage.dynamicweb-cms.com/Order-step-validation-184.aspx - 6. Using the validation functionality with existing cart templates:

Secondly you will have to make some changes to the forms in the cart templates. The templates in question are for step 2 (Customer profile), 3 (Delivery) and 4 (Approval). All forms must use the POST method to ensure a correct flow of data through the order steps.

It looked like it was possible to use the validationGroup also for step 4, but appearantly not.

Any other way to implement server side validation for a checkbox General Conditions in step 4?
 
Reply
Hi

It _is_ possible to use server side validation at step 4, however, custom order fields are validated at step 2, so you can't server side validate custom fields at step 4, only the fields currently located in step 4 (the approval check box).

This is why you get an error at step 2 when you turn on the validation for your custom field located in step 4: The validator misses the field at step 2 and reports an error.

I hope this helps.

 - Lasse
 
Reply
Hi Lasse,

"custom order fields are validated at step 2"
OK, clear.

"so you can't server side validate custom fields at step 4"
OK, clear.

"only the fields currently located in step 4 (the approval check box)."
So the approval check box is a standard field? This is exactly what we need.
However, I don't see this field in the standard tags?
 
Reply
You're absolutely right. The fields the validator supports are:

Custom orderline fields - validated in multiple steps even on step 1 when you add items to thew cart
Custom order fields - step 2
Standard customer specific fields - step 2
Standard payment and shipping fields - step 3

Sorry for the confusion
 
Reply
Hi Lasse,
Ok, thanks for clearing that up.

Back to the original question: How can we implement server side validation for a checkbox General Conditions in step 4?

Because if you don't server side check this, someone that is a bit handy with javascript, could submit an order without agreeing with the general conditions.
 
Reply
The current validation engine doesn't allow for this, so you can report it to us as a feature request.

Another thing you can do is to subscribe to the notification

Notifications.eCommerce.Order.Steps.Confimed and in your custom code redirect to step 4 again if the checkbox isn't checked.

 
Reply

We already subscribed to Dynamicweb.Notifications.eCommerce.Order.Steps.Confimed. See the topic start:

"We’ve made a notification for Dynamicweb.Notifications.eCommerce.Order.Steps.Confimed.
That requests the posted value of the checkbox by using HttpContext.Current.Request.Form. If it’s not checked we throw an exception.
This works fine if we don’t use a paymentprovider.


But if we use a payment provider, the user is redirected from step 4 to the paymentprovider, and then redirected to step 5: the agreedWithCondition checkbox value isn’t posted, so you get an exception.
That’s logical, but not the wanted behavior. ;)
"


I will report a feature request for the possibility to specify the step in which the validation group will validate the custom order fields.

BTW. this forum could use a quote tag. ;)

 

You must be logged in to post in the forum