<div>What are you using for the name space for your functions? </div><div><br></div><div>Instead of using MYTHEME_form_alter, you should use {modulename}_form_alter (where &quot;modulename&quot; is anything, as long as it&#39;s not already being used by Drupal).</div>

<div><br></div><div>You&#39;ll also need a .info file.</div><div><br></div><div>So, for instance, your directory structure in /sites/all/modules will look like this, assuming that the module name is &quot;velios&quot; (your last name).</div>

<div><br></div><div>velios [directory]</div><div>+ <a href="http://velios.info">velios.info</a> [See here for info: <a href="http://drupal.org/node/542202">http://drupal.org/node/542202</a>]</div><div>+ velios.module [contains the code below, using the namespace &quot;velios&quot; for your hooks. Ie, &quot;velios_form_alter()&quot;]</div>

<div><br></div><div>Once you have all that added, you&#39;ll have to go to your modules page and enable it and it should alter the form properly.</div><div><br></div><div>Regards,</div><div>Todd</div><br><div class="gmail_quote">

On 20 February 2012 12:09, 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">

Sorry, I will have to accept your offer for editing as I am clearly missing something obvious:<br>
<br>
function MYTHEME_form_alter(&amp;$form, $form_state, $form_id) {<br>
  global $user;<br>
  //alter forms but not for admin account<br>
  if ($user-&gt;uid != 1){ //limit it for some users, let&#39;s say admin only<br>
    //various irrelevant alterations here<br>
  } else {<br>
    if ($form_id == &#39;uc_cart_view_form&#39;) {<br>
      //add extra registration logic<br>
      $form[&#39;#validate&#39;] = array(&#39;congr_afternoon_<u></u>bookings&#39;);<br>
    }<br>
  }<br>
}<br>
<br>
/**<br>
 * Extra logic<br>
 */<br>
function congr_afternoon_bookings(&amp;$<u></u>form, &amp;$form_state){<br>
  //check afternoon tours for a max of 2 bookings<br>
  $congr_highlight_afternoon_<u></u>fields = array();<br>
  $congr_max_afternoon = 0;<br>
  foreach($form[&#39;items&#39;] as $key=&gt;&amp;$val) {<br>
    if (isset($val[&#39;nid&#39;][&#39;#value&#39;])) {<br>
      $node = node_load($val[&#39;nid&#39;][&#39;#value&#39;<u></u>]); //load the node of the corresponding item in the form<br>
      if ($node-&gt;field_product_type[&#39;<u></u>und&#39;][0][&#39;tid&#39;] == 476){ //if the associated term tid is 476<br>
        $congr_max_afternoon = $congr_max_afternoon + $val[&#39;qty&#39;][&#39;#default_value&#39;]; //add the quantity field of the item list to our max value<br>
        $congr_highlight_afternoon_<u></u>fields[] = $key; //also keep the key in an array<br>
      }<br>
    }<br>
  }<br>
  if ($congr_max_afternoon &gt; 2) { //if the max number of quantity items is more than 2<br>
    //$form_state[&#39;rebuild&#39;] = TRUE; //TODO: I am told this is required because otherwise the form is not updated with the newly user inputted figures but it does not work...<br>
    foreach($congr_highlight_<u></u>afternoon_fields as $key=&gt;$val) { //for each item in the list<br>
      if ($key == 0) { //if it is the first one, show the full message which is independent of a specific quantity field<br>
        form_set_error(&#39;&#39;,&#39;You have tried to buy &#39;.$congr_max_afternoon.&#39; items, but the maximum you can buy is 2. See below for a list of items which you can possibly amend.&#39;);<br>
        form_set_error(&#39;items][&#39;.$val,<u></u>&#39;Please amend this item: &#39;.$form[&#39;items&#39;][$val][&#39;title&#39;<u></u>][&#39;#markup&#39;].&#39;.&#39;);<br>
      } else { //for the rest do not show the message only highlight<br>
        form_set_error(&#39;items][&#39;.$val,<u></u>&#39;Please amend this item: &#39;.$form[&#39;items&#39;][$val][&#39;title&#39;<u></u>][&#39;#markup&#39;].&#39;.&#39;);<br>
      }<br>
    }<br>
  }<br>
}<br>
<br>
Thanks for looking into this.<br>
<br>
Thanasis<div class="im"><br>
<br>
On 20/02/12 16:02, 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">
<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><br>


-- the hook takes $form as an argument passed by reference.. so all the<br>
changes you make in $form, it should get reflected in the UI.. Please<br>
share your code if it does not work for you..<br>
<br>
On Mon, Feb 20, 2012 at 8:57 PM, Athanasios Velios &lt;<a href="mailto:a.velios@gmail.com" target="_blank">a.velios@gmail.com</a><br></div><div class="im">
&lt;mailto:<a href="mailto:a.velios@gmail.com" target="_blank">a.velios@gmail.com</a>&gt;&gt; wrote:<br>
<br>
    Hm, I commented the lines in template.php and built a new module<br>
    with the hook_form_alter and additional logic but this does not make<br>
    any difference at all. Exactly the same behaviour...<br>
<br>
    Thanasis<br>
<br>
<br>
    On 20/02/12 09:25, Mukesh Agarwal wrote:<br>
<br>
        Yes, Drupal is quite structured and has defined ways to deal with<br>
        stuff.. template.php and hook_form_alter are for 2 different<br>
        purposes<br>
        and in your case writing a custom module which implements the<br>
        hook is<br>
        the right way.<br>
<br>
        On Mon, Feb 20, 2012 at 2:53 PM, Athanasios Velios<br>
        &lt;<a href="mailto:a.velios@gmail.com" target="_blank">a.velios@gmail.com</a> &lt;mailto:<a href="mailto:a.velios@gmail.com" target="_blank">a.velios@gmail.com</a>&gt;<br></div><div class="im">
        &lt;mailto:<a href="mailto:a.velios@gmail.com" target="_blank">a.velios@gmail.com</a> &lt;mailto:<a href="mailto:a.velios@gmail.com" target="_blank">a.velios@gmail.com</a>&gt;&gt;&gt; wrote:<br>
<br></div><div class="im">
            Do you reckon that the problem is putting the code in<br>
        template.php<br>
            instead of a custom module?<br>
<br>
            Thanks again,<br>
<br>
            Thanasis<br>
<br>
<br>
            On 20/02/12 08:27, Mukesh Agarwal wrote:<br>
<br>
                The place to implement logic based form_set_error should<br>
        be in the<br>
                validate function and not template.php .. I would<br>
        recommend you use<br>
                hook_form_alter<br></div>
        &lt;<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><br>


        &lt;<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>&gt;<div class="im">

<br>
<br>
        &lt;<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><br>


        &lt;<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>&gt;&gt;&gt;<br>


<br>
                -&gt; $form_id will indicate the form you wish to alter,<br>
        and there<br>
                you can<br>
                add a custom validate function in $form[&#39;#validate&#39;] --<br>
        the custom<br>
                function should then take care of form_set_error<br>
<br></div>
        <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>


        &lt;<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>&gt;<div>

<div class="h5"><br>
<br>
        &lt;<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>


        &lt;<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>&gt;&gt;<br>


                -- you need to set the element name as first parameter<br>
        to make<br>
                sure that<br>
                the particular field is highlighted.<br>
<br>
                On Mon, Feb 20, 2012 at 1:51 PM, Athanasios Velios<br>
        &lt;<a href="mailto:a.velios@gmail.com" target="_blank">a.velios@gmail.com</a> &lt;mailto:<a href="mailto:a.velios@gmail.com" target="_blank">a.velios@gmail.com</a>&gt;<br>
        &lt;mailto:<a href="mailto:a.velios@gmail.com" target="_blank">a.velios@gmail.com</a> &lt;mailto:<a href="mailto:a.velios@gmail.com" target="_blank">a.velios@gmail.com</a>&gt;&gt;<br>
        &lt;mailto:<a href="mailto:a.velios@gmail.com" target="_blank">a.velios@gmail.com</a> &lt;mailto:<a href="mailto:a.velios@gmail.com" target="_blank">a.velios@gmail.com</a>&gt;<br>
        &lt;mailto:<a href="mailto:a.velios@gmail.com" target="_blank">a.velios@gmail.com</a> &lt;mailto:<a href="mailto:a.velios@gmail.com" target="_blank">a.velios@gmail.com</a>&gt;&gt;&gt;&gt; wrote:<br>
<br>
                    Hello,<br>
<br>
                    I am trying to alter a form (uc_cart_view_form) with<br>
        various<br>
                input<br>
                    fields (Qty for products). In template.php I am<br>
        adding some<br>
                extra<br>
                    logic which applies across a selection of these<br>
        fields. Once the<br>
                    logic is checked I need to display an error message.<br>
        I am using<br>
                    form_set_error to show the message. The problem is<br>
        that the user<br>
                    then updates the input values and updates the form,<br>
        but the new<br>
                    figures are not taken into account. They are shown<br>
        in the<br>
                form, but<br>
                    not used in my template.php extra logic.<br>
<br>
                    drupal_set_message allows the new values to work but<br>
        the message<br>
                    appears twice and it does not, obviously, link to<br>
        specific<br>
                fields in<br>
                    the form which are problematic.<br>
<br>
                    Setting form_state rebuild to true before form_set_error<br>
                does not<br>
                    have an effect.<br>
<br>
                    Any ideas of what needs to be done for these values<br>
        to be<br>
                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></div></div>
                ______________________________<u></u>______<div class="im"><br>
<br>
                Innoraft Solutions &lt;<a href="http://www.innoraft.com" target="_blank">http://www.innoraft.com</a>&gt;  || +91<br>
        <a href="tel:8017220799" value="+18017220799" target="_blank">8017220799</a><br>
<br>
<br>
<br>
<br>
        --<br>
        Cheers,<br>
        Mukesh Agarwal<br>
        ______________________________<u></u>____<br>
        Innoraft Solutions &lt;<a href="http://www.innoraft.com" target="_blank">http://www.innoraft.com</a>&gt;  || <a href="tel:%2B91%208017220799" value="+918017220799" target="_blank">+91 8017220799</a><br>
<br>
<br>
<br>
<br>
--<br>
Cheers,<br>
Mukesh Agarwal<br>
______________________________<u></u>__<br>
Innoraft Solutions &lt;<a href="http://www.innoraft.com" target="_blank">http://www.innoraft.com</a>&gt;  || <a href="tel:%2B91%208017220799" value="+918017220799" target="_blank">+91 8017220799</a><br>
<br>
</div></blockquote>
</blockquote></div><br>