http://api.drupal.org/api/drupal/modules%21system%21system.api.php/function/hook_form_alter/7-- the hook takes $form as an argument passed by reference.. so all the changes you make in $form, it should get reflected in the UI.. Please share your code if it does not work for you..
On Mon, Feb 20, 2012 at 8:57 PM, Athanasios Velios <[email protected]>wrote: > Hm, I commented the lines in template.php and built a new module with the > hook_form_alter and additional logic but this does not make any difference > at all. Exactly the same behaviour... > > Thanasis > > > On 20/02/12 09:25, Mukesh Agarwal wrote: > >> Yes, Drupal is quite structured and has defined ways to deal with >> stuff.. template.php and hook_form_alter are for 2 different purposes >> and in your case writing a custom module which implements the hook is >> the right way. >> >> On Mon, Feb 20, 2012 at 2:53 PM, Athanasios Velios <[email protected] >> <mailto:[email protected]>> wrote: >> >> Do you reckon that the problem is putting the code in template.php >> instead of a custom module? >> >> Thanks again, >> >> Thanasis >> >> >> On 20/02/12 08:27, Mukesh Agarwal wrote: >> >> The place to implement logic based form_set_error should be in the >> validate function and not template.php .. I would recommend you use >> hook_form_alter >> <http://api.drupal.org/api/__**drupal/modules%21system%__** >> 21system.api.php/function/__**hook_form_alter/7 >> >> <http://api.drupal.org/api/**drupal/modules%21system%** >> 21system.api.php/function/**hook_form_alter/7<http://api.drupal.org/api/drupal/modules%21system%21system.api.php/function/hook_form_alter/7> >> >> >> >> -> $form_id will indicate the form you wish to alter, and there >> you can >> add a custom validate function in $form['#validate'] -- the custom >> function should then take care of form_set_error >> >> http://api.drupal.org/api/__**drupal/includes%21form.inc/__** >> function/form_set_error/7<http://api.drupal.org/api/__drupal/includes%21form.inc/__function/form_set_error/7> >> >> <http://api.drupal.org/api/**drupal/includes%21form.inc/** >> function/form_set_error/7<http://api.drupal.org/api/drupal/includes%21form.inc/function/form_set_error/7> >> > >> -- you need to set the element name as first parameter to make >> sure that >> the particular field is highlighted. >> >> On Mon, Feb 20, 2012 at 1:51 PM, Athanasios Velios >> <[email protected] <mailto:[email protected]> >> <mailto:[email protected] <mailto:[email protected]>>> wrote: >> >> Hello, >> >> I am trying to alter a form (uc_cart_view_form) with various >> input >> fields (Qty for products). In template.php I am adding some >> extra >> logic which applies across a selection of these fields. Once >> the >> logic is checked I need to display an error message. I am using >> form_set_error to show the message. The problem is that the >> user >> then updates the input values and updates the form, but the new >> figures are not taken into account. They are shown in the >> form, but >> not used in my template.php extra logic. >> >> drupal_set_message allows the new values to work but the >> message >> appears twice and it does not, obviously, link to specific >> fields in >> the form which are problematic. >> >> Setting form_state rebuild to true before form_set_error >> does not >> have an effect. >> >> Any ideas of what needs to be done for these values to be >> taken into >> account with form_set_error? >> >> Thanks >> >> Thanasis >> >> >> >> >> -- >> Cheers, >> Mukesh Agarwal >> ______________________________**____ >> >> Innoraft Solutions <http://www.innoraft.com> || +91 8017220799 >> >> >> >> >> -- >> Cheers, >> Mukesh Agarwal >> ______________________________**__ >> Innoraft Solutions <http://www.innoraft.com> || +91 8017220799 >> >> -- Cheers, Mukesh Agarwal ________________________________ Innoraft Solutions <http://www.innoraft.com> || +91 8017220799
