The place to implement logic based form_set_error should be in the validate function and not template.php .. I would recommend you use <a href="http://api.drupal.org/api/drupal/modules%21system%21system.api.php/function/hook_form_alter/7">hook_form_alter</a> -&gt; $form_id will indicate the form you wish to alter, and there you can add a custom validate function in $form[&#39;#validate&#39;] -- the custom function should then take care of form_set_error <div>
<br></div><div><a href="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</a> -- you need to set the element name as first parameter to make sure that the particular field is highlighted.<br>
<br><div class="gmail_quote">On Mon, Feb 20, 2012 at 1:51 PM, Athanasios Velios <span dir="ltr">&lt;<a href="mailto:a.velios@gmail.com">a.velios@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hello,<br>
<br>
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.<br>

<br>
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.<br>
<br>
Setting form_state rebuild to true before form_set_error does not have an effect.<br>
<br>
Any ideas of what needs to be done for these values to be taken into account with form_set_error?<br>
<br>
Thanks<br>
<br>
Thanasis<br>
</blockquote></div><br><br clear="all"><div><br></div>-- <br>Cheers,<div>Mukesh Agarwal</div><div>________________________________</div><div><font color="#999999"><a href="http://www.innoraft.com" target="_blank">Innoraft Solutions</a>  || </font><span style="color:rgb(153,153,153)">+91 8017220799</span></div>
<br>
</div>