Your function's arguments are wrong. See hook_form_alter docs.
So basically you need to rewrite your function as follows.
First, grab the correct form ID.form_alter functions don't have a $node but in some forms, full node object form is in $form. So use the following code. You will now see at least 2 message on your messages area with form ID and array explanation of $form.
function uc_button_form_alter(&$form, &$form_state, $form_id) {
drupal_set_message($form_id);
drupal_set_message('<pre>'.print_r($form, 1).'</pre>');
};
Now, check if the node ID you are looking for is available in the $form array. (in most cases, it's in $form['#node']). Now you can change the function to the real code.
function uc_button_form_alter(&$form, &$form_state, $form_id) {
if (isset($form['#node']->nid) && $form_id == 'edit-submit-' . $form['#node']->nid) {
$form['submit']['#attributes']['class'] = 'node-add-to-cart';
$form['submit']['#attributes']['xxx'] = 'xxx'; // we don't want to clear existing values.
}
};
However, even this implementation is not necessary. You can make use of default classes with tricky nesting if you only want to add a class to the button.
Update after 3rd comment: Try this: function uc_button_form_alter(&$form, &$form_state, $form_id) { if (isset($form['nid']['#value']) && $form_id == 'edit-submit-' . $form['nid']['#value']) { $form['submit']['#attributes']['class'] = 'node-add-to-cart'; $form['submit']['#attributes']['xxx'] = 'xxx'; // we don't want to clear existing values. } };
function uc_product_add_to_cart_form
is the function I want to override. My aim is to add some additional code inside button's code to track clicks, since I am going to use ajax cart. I tried also a variation of a snippet I found here just to see if it works pastebin.com/btbuELMMfunction xxx_uc_catalog_buy_it_now_form_alter(&$form, &$form_state) { $form['submit']['#value']= t('Yes i want one'); }
none from above works – loparr Sep 9 '12 at 18:07function acquia_prosper_button($element)
put inside template.php. I tried to remove it in case it fights but the html code is not changed at all. – loparr Sep 9 '12 at 18:55