6 replies [Last post]
jary's picture
Offline
Joined: 07/16/2009
Juice: 22
Was this information Helpful?

hi im trying to add fields like checkbox in the attributes form using hook_form_alter its working and i can view the checkboxes i created but the problem is when I submit the form it redirects back to the page instead of the shopping cart, please help.

here is my code

<?php
function addq_form_alter($form_id, &$form) {

 
  if(

$form_id == "uc_product_add_to_cart_form_22"){

 

$form['form_id'] = array(
     array(
       
'#type' => 'checkbox',
       
'#title' => t('Option1'),
       
'#weight'=> -10,
       
'#value'=>t('test'),
       
'#id'=>t('edit-uc-product-add-to-cart-form-23'),
       
'#name'=> t('attributes[30]')
    ),
    array(
       
'#type' => 'checkbox',
       
'#title' => t('Option2'),
       
'#weight'=> -10,
       
'#value'=>t('test'),
       
'#id'=>t('edit-uc-product-add-to-cart-form-23'),
       
'#name'=> t('attributes[30]')
    ),
       
'#weight'=> -10
   
);

  }
 
  }

?>
deepakg83's picture
Offline
Joined: 07/24/2009
Juice: 187
Re: modifying attributes using hook_form_alter

remove the extra array( , and chk if it helps. or add comma (,) in EOF at '#name' .

Deepak Gupta

jary's picture
Offline
Joined: 07/16/2009
Juice: 22
not working :(

Hi deepakg83,
Thanks for your reply. I tried your suggestion but still doing the same thing, when I click the add to cart button its not going to the shopping cart page.\

Cheers,

Jary

jary's picture
Offline
Joined: 07/16/2009
Juice: 22
help

guys hope you can help me with this one

Lyle's picture
Offline
AdministratoreLiTe!
Joined: 08/07/2007
Juice: 6846
Re: help

Whoa, $form['form_id'] is an important part of the Form API, and you can't really just go changing it like that.

I think what you're trying to do is add a couple of fields to the form, right? To do that, you need to add the form element arrays to new keys in $form.

<?php
$form
['new_thing'] = array(
 
'#type' => 'checkbox',
 
'#title' => t('New thing'),
);
$form['second_part'] = array(
 
// ...
);
?>

It's probably a good idea for you to inspect $form to see what is there and how it is structured.

<?php
 
// If you have the devel module, you can use
 
dpm($form);

 

// otherwise use the regular Drupal functions
 
drupal_set_message('<pre>'. print_r($form, TRUE) .'</pre>');
?>
rak
rak's picture
Offline
Internationalizationizer
Joined: 11/07/2007
Juice: 310
adding another column to the cart

--closed--
instead of hook_form_alter() sometimes it's wiser to use hook_tapir_table_alter()
--
RAk

jary's picture
Offline
Joined: 07/16/2009
Juice: 22
hi lyle

thank you so much for your reply really need your help regarding this one.

yes I want to create a add additional fields for the attributes, i created this one

<?php
$form
['quantity'] = array(
 
'#type' => 'textbox',
 
'#title' => t('New thing'),
);
?>

but the values are not computed with the "total" on the add to cart form, do you have any idea how to pass value on the cart?
what im trying to do is to add a custom field for the attribute with a quantity .

THanks again lyle

Jary