I had a rule of 'After saving new content' of type, redirect to url. I need to add second submit button to the content type so I decided to add the redirect to a custom module so I can have different actions depending on the button. The redirect works on the submit button but I only want this to happen when adding/inserting a new node. Right now it redirects every time the submit button is clicked.
In mymodule_form_alter:
$form['actions']['submit']['#submit'][] = 'submission_form_submit';
Then:
function mymodule_form_submit($form, &$form_state) {
$form_state['redirect'] = 'info-received';
}
Code suggestions needed. But if there is a way to have rules perform different actions based on which button is clicked I can use that advice also.
ETA: the code used for the second button
$form['actions']['submit_another'] = array(
'#type' => 'submit',
'#name' => 'save_another',
'#value' => t('Save, and Add Another.'),
'#submit' => array('node_form_submit','submission_form_create_duplicate_form_submit'),
'#weight' => 40,
);
ETA2: Trying is_new
function mymodule_form_submit($form, &$form_state) {
$node = $form_state['node'];
if(isset($node->type) && $node->type == 'submission') {
dsm('Reached Node Type Check!'); // <- this works
if (isset($node->is_new)) {
dsm('Reached New Node Check!'); // <- this does not work
$form_state['redirect'] = 'info-received';
}
}
}
Changed the if statement checking for new node to
if ($node->is_new) {
Results in 'Notice: Undefined property: stdClass::$is_new in mymodule_form_submit()'
It seems the value for is_new is not set.