3 replies [Last post]
nickbits's picture
Offline
Joined: 04/15/2009
Juice: 205
Was this information Helpful?

Hi All,

Again I expect I am missing the obvious here. I want to add a wrapper around the quantity section of the "add to cart" form. Now I could hard code this by adding the following line to "uc_product.module" (around line1476):

$form['div_tag'] = array('#type' => 'markup', '#value' => '<div class="qty-wrapper">');

This does indeed work and gives me the following code:

<div class="qty-wrapper">
  <div id="edit-qty-11-wrapper" class="form-item">
   <label for="edit-qty-11">Quantity: </label>
   <input type="text" class="form-text" value="1" size="5" id="edit-qty-11" name="qty" maxlength="6">
  </div>
</div>

This is exactly what I want. Now I want to do this properly and not hack core files. Hence I have created my own module with form alter:

function mymodule_form_alter(&$form, &$form_state, $form_id) {
  if (substr($form_id, 0, 27) == 'uc_product_add_to_cart_form') {
$form['div_tag'] = array('#type' => 'markup', '#value' => '<div class="qty-wrapper">');
  }
}

I know this is being called and I can see the new item in the list when I do a DPM / DSM. However, it fails to wrap around, or indeed print at all. The only difference I can see is the position in the list.

So the question is, what am I doing wrong?

I would be very greatful for any pointers.

Regards,
Nick

nickbits's picture
Offline
Joined: 04/15/2009
Juice: 205
Re: Form Alter and Quantity Field

Okay so the so called working code above doesn't work. It messess up views where it is not inserting the correct divs.

Any suggestions?

thedecline's picture
Offline
Joined: 10/26/2008
Juice: 44
Re: Re: Form Alter and Quantity Field

I think you want something like this:

function modulename_form_alter(&$form, $form_state, $form_id) {
   switch ($form_id) {
        case 'uc_product_add_to_cart_form_'.arg(1):

   $form['qty']['#prefix'] = '<div id="qty-wrapper">';
   $form['qty']['#suffix'] = '</div>';

break;

  }

maslachak@gmail.com's picture
Offline
Joined: 02/13/2012
Juice: 7
Re: Re: Re: Form Alter and Quantity Field

Thanks for this one! You saved me!