By artatum on
Hello
I'm trying, in my module 'cartscheduler', to add a validation test on 'delivery_postal_code', into Ubercart cart checkout. Pretty newbie in Drupal dev, I dont really understand what I should do...
My function doesn't work :
function cartscheduler_form_alter(&$form,&$form_state,$form_id) {
if ($form_id == 'uc_cart_checkout_form') {
if ($form_state['panes']['delivery']['delivery_postal_code'] !=='93330') {
form_set_error('delivery_postal_code','we dont deliver in your town');
}
}
}
Maybe my form_set_error cannot find 'delivery_postal_code' as it is nested into another one. But how to specify it into the args of the function ?
Maybe It's possible to override a validate function but I dont know how to achieve this.
Any idea is welcome...
Comments
I think you need to add your
I think you need to add your own validation function, rather than override:
oh, oh !! I'm going to check
oh, oh !! I'm going to check this out. Right now!
Thx a lot Web Assistant :-)
Artatum
www.ixxi-mobility.com
Great! It works! Thx
Great! It works! Thx again.
How can I display the red outline around the faulty field plz?
Artatum
www.ixxi-mobility.com
Just use form_set_error(),
Just use form_set_error(), make sure you've given the correct name of the form field.
I dont copy : as the message
I dont copy : as the message 'we dont deliver in your town' is correctly display on top of the page, so the test on
if ($form_state['values']['delivery_postal_code'] !== '93330') ...
was successfully performed...
Therefore, it seems that 'delivery_postal_code' in
form_set_error('delivery_postal_code',...
is correct ?
(red outline fails in IE and FF...)
Artatum
www.ixxi-mobility.com
Do you have devel installed?
Do you have devel installed? I'd do a variable dump of $form_state['values'] in the validation function to make sure the name is correct:
I'm working in Visual Studio
I'm working in Visual Studio and my spy shows me this tree :
$form_state
['values']
['panes']
['delivery']
['delivery_postal_code'];
...
Artatum
www.ixxi-mobility.com
If the form #tree is set to
If the form #tree is set to true then it would be:
The most bizarre being that
The most bizarre being that if I empty the field then my red outline is displayed. But it is achieved by a validate function which is using $element argument...
Strange...
Artatum
www.ixxi-mobility.com
'form #tree' ? By tree, I
'form #tree' ?
By tree, I mean the hierarchy of the array...
Artatum
www.ixxi-mobility.com
Oh, oh. Bingo! You're right !
Oh, oh. Bingo! You're right ! It works!
I've never seen this strange notation :
'panes][delivery][delivery_postal_code'
but I'm not going to forget it !
It's very cool : I dont need Rules anymore!!!
Thanks a couple of million times !
Artatum
www.ixxi-mobility.com