2

I have heavily modified an Ubercart form.

I have tried to remove the initial validation placed on this because I'm using a whole host of different fields.

For some reason, however, the validation is still getting executed.

Why would this be the case? Am I removing all sources of validation correctly?

  array_unshift($form['#submit'], 'client_mod_uc_cart_checkout_handler');
  $form['#validate'][] = 'client_mod_uc_cart_checkout_validate';

I have also tried setting $form['#validate'] to array();

However, upon submission, I get:

First name field is required.
Last name field is required.
Street address field is required.
City field is required.
Postal code field is required.
First name field is required.
Last name field is required.
Street address field is required.
City field is required.
Postal code field is required.

Why would this be the case?

1 Answer 1

1
$form['#validate'][] = 'client_mod_uc_cart_checkout_validate';

Will only append your function to the list of functions in the validation array.

I'm fairly certain using = array() won't work because that's how you define an array, not how you empty one.

Modified answer from Stack Overflow:

Use unset, if you need the array later on just instantiate it again.

unset($form['#validate']);
$form['#validate'] = array();
3
  • The PHP docs you've quoted don't apply here - it means if you unset($form); that $form won't be removed from memory, just the local scope. unset($form['anything']); when $form is passed by reference will remove $form['anything'], and update that fact in memory
    – Clive
    Mar 24, 2015 at 23:29
  • This solution doesn't seem to work.
    – Jack Ryan
    Mar 25, 2015 at 12:29
  • Used this in a different context and it did work. Thank you.
    – Jack Ryan
    Mar 25, 2015 at 16:51

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.