1

I'm using braintree.js with a custom form. For those not familiar, braintree.js does client side encryption of the form fields before submission to the server. On my end I get a bunch of gibberish (this is expected). If a form validation error occurs, I want the form displayed again alerting the user of the error but I don't want any of the fields pre-populated because the pre-populated values are now the client side encrypted gibberish. Is there a method of doing this in the _validate function?

1 Answer 1

1

I was able to unset the value from within the form validation function. In my case the element is named foo and it only validates if it's set to bar:

function mymodule_myform_validate($form, &$form_state) {
  if ($form_state['input']['foo'] != 'bar') {
    unset($form_state['complete form']['foo']['#value']);
    form_error($form['foo'], 'foo is not equal to bar');
  }
}

If the user enters anything but bar in foo, we set a form error and they presented with the form again without anything in the foo field.

I'm not sure how/if the form state array is affected by, for example, the i18n or locale modules, but this should get you started.

1
  • This, whether it is correct or not, indeed gives me the results I want.
    – user23977
    Nov 25, 2013 at 22:49

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.