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. <br>
<br><div class="gmail_quote">On Mon, Feb 20, 2012 at 2:53 PM, Athanasios Velios <span dir="ltr"><<a href="mailto:a.velios@gmail.com">a.velios@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Do you reckon that the problem is putting the code in template.php instead of a custom module?<br>
<br>
Thanks again,<br>
<br>
Thanasis<div class="im"><br>
<br>
On 20/02/12 08:27, Mukesh Agarwal wrote:<br>
</div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="im">
The place to implement logic based form_set_error should be in the<br>
validate function and not template.php .. I would recommend you use<br>
hook_form_alter<br></div>
<<a href="http://api.drupal.org/api/drupal/modules%21system%21system.api.php/function/hook_form_alter/7" target="_blank">http://api.drupal.org/api/<u></u>drupal/modules%21system%<u></u>21system.api.php/function/<u></u>hook_form_alter/7</a>><div class="im">
<br>
-> $form_id will indicate the form you wish to alter, and there you can<br>
add a custom validate function in $form['#validate'] -- the custom<br>
function should then take care of form_set_error<br>
<br>
<a href="http://api.drupal.org/api/drupal/includes%21form.inc/function/form_set_error/7" target="_blank">http://api.drupal.org/api/<u></u>drupal/includes%21form.inc/<u></u>function/form_set_error/7</a><br>
-- you need to set the element name as first parameter to make sure that<br>
the particular field is highlighted.<br>
<br>
On Mon, Feb 20, 2012 at 1:51 PM, Athanasios Velios <<a href="mailto:a.velios@gmail.com" target="_blank">a.velios@gmail.com</a><br></div><div class="im">
<mailto:<a href="mailto:a.velios@gmail.com" target="_blank">a.velios@gmail.com</a>>> wrote:<br>
<br>
Hello,<br>
<br>
I am trying to alter a form (uc_cart_view_form) with various input<br>
fields (Qty for products). In template.php I am adding some extra<br>
logic which applies across a selection of these fields. Once the<br>
logic is checked I need to display an error message. I am using<br>
form_set_error to show the message. The problem is that the user<br>
then updates the input values and updates the form, but the new<br>
figures are not taken into account. They are shown in the form, but<br>
not used in my template.php extra logic.<br>
<br>
drupal_set_message allows the new values to work but the message<br>
appears twice and it does not, obviously, link to specific fields in<br>
the form which are problematic.<br>
<br>
Setting form_state rebuild to true before form_set_error does not<br>
have an effect.<br>
<br>
Any ideas of what needs to be done for these values to be taken into<br>
account with form_set_error?<br>
<br>
Thanks<br>
<br>
Thanasis<br>
<br>
<br>
<br>
<br>
--<br>
Cheers,<br>
Mukesh Agarwal<br>
______________________________<u></u>__<br></div>
Innoraft Solutions <<a href="http://www.innoraft.com" target="_blank">http://www.innoraft.com</a>> || +91 8017220799<br>
<br>
</blockquote>
</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>