1

Observer Server Side Validation

Plan: Use observer to see if a checkbox is correctly set.. but how do i do this?

Does anyone know how I can call the session singleton in Javascript? I have a validation to a form like this which, everytime it validates the checkbox element, I want to to update a value in the session model.

Validation.add(
 'validate-tax', 'This is only applicable to certain states.', function(v) {
 var dropDown = document.getElementById("billing:region_id").querySelector('option:checked').text;
 if ((dropDown != 'New York' && document.getElementById("billing:tax_exempt").checked == false) || (dropDown == 'New York')) {
 Mage::getSingleton('core/session')->setYourNameSession($session_value);
 return true;
 }
 }
);

But I don't know if this is possible.

Additional Information I want to do a server-side validation on a checkbox. To do this my plan is to see if the value in the session is true or false. Alternatively, I was thinking to check the HTML elements directly from an observer, but I do not know how to do it.

asked May 25, 2015 at 15:15
1
  • Maybe it's Memorial Day fog, but it looks to me like you have php code in your javascript Commented May 25, 2015 at 17:11

1 Answer 1

2

Too long for a comment, but I think this is what you mean to do:

Validation.add(
 'validate-tax', 'This is only applicable to certain states.', function(v) {
 var dropDown = document.getElementById("billing:region_id").querySelector('option:checked').text;
 if ((dropDown != 'New York' && document.getElementById("billing:tax_exempt").checked == false) || (dropDown == 'New York')) {
 <?php Mage::getSingleton('core/session')->setYourNameSession($session_value); ?>
 return true;
 }
 }
);

Notice that Mage::getSingleton('core/session')->setYourNameSession($session_value); is php code, so above is wrapped with <?php ?>

Keep in mind, your file should be saved with the .php extension

answered May 25, 2015 at 17:14

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.