/**
* Implementation of hook_form_alter().
*/
function MODULE_form_alter(&$form, $form_state, $form_id) {
$form_nid = $form['nid']['#value'];
if ($form_id == 'uc_product_add_to_cart_form_'.$form_nid) {
global $theme;
$form['submit'] = array(
'#type' => 'image_button',
'#value' => t('Add to Cart'),
'#src' => drupal_get_path('theme', $theme).'/images/submit.gif',
);
}
}
Because i am new to this please say me where to add this code to change the Add to cart button?
possibly, Add this code to your theme's template file
or in uc_product.module file
This kinds of function should imho be in a new module. I always employ a extremely small module for functions like these. If you add/change code in a core file, you changes will be lost every time you update to a new version. So absolutely not in any core (uc_product) or theme file (if possible, Drupal 5 CSS is a small exeption?).
Added a small example (but not tested, I think the hook_form_alter is drupal 6 and my module file was intended for drupal 5, so you might need to check)
| Attachment | Size |
|---|---|
| dinilu.zip | 699 bytes |
I tried the change one for all but didn't work. Changed MODULE to phptemplate and tried the name of my theme and no joy. Is it UC1 or UC2?
Have you tried http://www.ubercart.org/contrib/9512?
I didn't see that - but that is very cool. Will have a look. I did it with CSS in the end but may change back.
http://mydrupalblog.lhmdesign.com/theming-search-submit-button-css-cross...
That module http://www.ubercart.org/contrib/9512 (uc_imgsubmit)
looks exactly the same as the code i pasted above in feb09, the uc_imgsubmit module was uploaded
march09.
Anyhow use uc_imgsubmit, if u want it quickly installed.
I would normaly create one specific module, called themes and edits. etc.
Where i would dump little form and node alters like this one, inside of, instead of having so many little modules.
I tried using the below code it did not work for me, Is that because i am using Ubercart 2.0-beta5?
/**
* Implementation of hook_form_alter().
*/
function MODULE_form_alter(&$form, $form_state, $form_id) {
$form_nid = $form['nid']['#value'];
if ($form_id == 'uc_product_add_to_cart_form_'.$form_nid) {
global $theme;
$form['submit'] = array(
'#type' => 'image_button',
'#value' => t('Add to Cart'),
'#src' => drupal_get_path('theme', $theme).'/images/submit.gif',
);
}
}
@Anand yrh
Yes, you are right. The api for hook_form_alter() changed from 5.x to 6.x.
It got fixed!
Chick this out http://www.ubercart.org/contrib/9512
Hello,
I managed to change ADD TO CART button image thanks to this:
http://www.primalmedia.com/blog/how-to-replace-the-add-to-cart-button-wi...
But I would also like to put this button (or a second one) on top of the product page, could you tell me how to do ?
Thanks a lot.
