0

I'm trying to hide the "Save and Add Another" button on the form used to save new products.

I can access the "Save" button in the $form array at $form['actions']['submit']. However, I'm not seeing the "Save and Continue" button in $form.

I looked in commerce_product_ui.module and found the place where this form element is being added. It's called $form['actions']['save_continue']. I would expect to see it in the $form array, but again - it just doesn't seem to be there.

Thanks for your help.

  • 1
    I know it's not the right way but #edit-save-continue {display:none;} it's the only way i found. I've tried with dsm($page) and I don't find the second button either... – Tyler Durden Aug 23 '12 at 15:51
  • @Syd Barret, I am interested of this, where you do dsm($page) - I want to reproduce the situation, for experimental purpose – svetlio Aug 24 '12 at 7:33
  • Do you want to know where to pur dsm($page)? you should put it in your tpl.php file, it could be page.tpl.php or node.tpl.php or node--CONTENT-TYPE.tlp.php or view.tpl.php – Tyler Durden Aug 24 '12 at 8:42
  • my question was about this particular situation as it is, because I put dsm() in custom module in alter or hook_preprocess function, and I use commerce module - not Profile commerce kickstart, it does not matter now, it is still useful – svetlio Aug 24 '12 at 18:06
1

implement hook_form_alter

function hook_form_alter(&$form, &$form_state, $form_id) { 
  if ($form_id == 'commerce_product_ui_product_form') {
    unset($form['actions']['save_continue']);
  }
}
  • While I agree this should work, ['save_continue'] does not exist in $form['actions'] for some reason. – joedougherty Aug 23 '12 at 17:29
  • This answer is technically correct - I just needed to figure out how to alter the form after it was finished being built. – joedougherty Aug 24 '12 at 16:23
1

I finally realized why this element didn't exist in $form at the time.

The Commerce Kickstart module had a higher weight than the module than I wrote, hence it included elements in $form after my call to hook_form_alter().

There are two distinct solutions to this:

1.) Increase the weight of my module (to make sure it's called after Commerce Kickstart.)

2.) Optionally, you can add an #after_build array to $form. This will let you add functions that are called after the form is built.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.