Forums

Customer Server Side Validation

wibadd 07 Feb, 2012
I wanted to use the required option for the description field in my form, but it throws a validation error when it should not. For example, there are three levels - Software, Gold and Silver. Silver is the only level that does not display the description, but a validation error is still displayed even though the field is hidden.

I have added custom server side validation to run a couple of different checks in my form and they are working, so I figured I would try to do it for the description as well. When I add the following code to check if a description field is not empty, I get a validation error regardless if it has characters inputted or not. What am I missing?

<?php
if (($_POST['level'] == "Software" && empty($POST['description'])) || ($_POST['level'] == "Gold" && empty ($POST['description']))) {
$form->validation_errors['description'] = "Please enter up to a 650 character (including spaces) description of your company/organization";
return false;
}
?>

Also, is there a reason why the JS seems to not load on the Event Loop after Fail? The form initially loads several scripts, including one that populates price. However, when validation fails the scripts seem not to function any longer. I tried adding a JS Load on the Fail above the Event Loop but that isn't working either.
GreyHead 07 Feb, 2012
Hi wibadd,

The $POST['description'] need the _ in $_POST

Also, is there a reason why the JS seems to not load on the Event Loop after Fail?

No there isn't. Is there a JavaScript error on the page?

Bob
wibadd 07 Feb, 2012
Thanks, once again, Bob. Good thing I don't code for a living or I'd be starving by now!

Attached are screen shots of the following JS before and after validation:
window.addEvent('load', function() {
  var orgname = $('legal_name');

  // execute the check after each keystroke
  orgname.addEvent('keyup', function() {
    $('disclaimer_org_name1').innerHTML = orgname.value;
    $('disclaimer_org_name2').innerHTML = orgname.value;
    $('disclaimer_org_name3').innerHTML = orgname.value;
  });
});

window.addEvent('load', function() {
    var sponsorship_amount;
$('level').addEvent('change', function() {
if ($('level').value == 'Software') {
    sponsorship_amount = 2500;
} else if ($('level').value == 'Gold') {
    sponsorship_amount = 1000;
} else if ($('level').value == 'Silver') {
    sponsorship_amount = 500;
} else {
sponsorship_amount = "";
}
    $('total_amount').innerHTML = sponsorship_amount;
});
});


[attachment=1]Completed Form.png[/attachment]

[attachment=0]After Validation.png[/attachment]
GreyHead 07 Feb, 2012
Hi wibadd,

The code to update the name only runs when the name box is edited. You also need it to run when the page loads. Here's the simplest way:
window.addEvent('load', function() {
  var orgname = $('legal_name');
  $('disclaimer_org_name1').innerHTML = orgname.value;
  $('disclaimer_org_name2').innerHTML = orgname.value;
  $('disclaimer_org_name3').innerHTML = orgname.value;
  // execute the check after each keystroke
  orgname.addEvent('keyup', function() {
    $('disclaimer_org_name1').innerHTML = orgname.value;
    $('disclaimer_org_name2').innerHTML = orgname.value;
    $('disclaimer_org_name3').innerHTML = orgname.value;
  });
});
. . .

Bob
This topic is locked and no more replies can be posted.