[development] form_set_error and updating form values

Athanasios Velios a.velios at gmail.com
Mon Feb 20 09:23:14 UTC 2012


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>
> -> $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
> -- 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 <a.velios at gmail.com
> <mailto:a.velios at gmail.com>> 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
>


More information about the development mailing list