I need to do this but with Drupal forms:
<input type="button" class="button-user" value="Back" onclick="location.href='edit'"/>
I tried doing this but it did not work:
$form['back']['#prefix'] = "<input type='button' class='button-user' value='Back' onclick='location.href='edit''/>;
and also:
$form['back'] = array(
'#type' => 'button',
'#value' => 'Back',
'#attributes' => array(
'class' => 'button-user',
'onclick' => 'location.href=edit',
)
);
$form['back']['#markup'] = "<input type='button' class='button-user' value='Back' onclick='location.href=\'edit\''/>";
$form['back']['#markup'] = "<input type='button' class='button-user' value='Back' onclick='window.history.go(-1)'/>";
This works for any page.
Just adding my version, which seems to work great in 7, just catch it in the rebuild cycle and redirect instead. Extensible, can add any other buttons to do things, note the spelling of value "Back" is the name of the "op" (operation).. something that confused and annoyed me until I figured it out.
function mymodule_something_form($form,&$form_state){
//... Rest of form
$form['unused_form_id_back'] = array(
'#type' => 'button',
'#value' => 'Back',
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => 'Do Stuff!'
);
return $form;
}
function mymodule_something_form_validate($form, &$form_state)
{
if($form_state['values']['op'] == 'Back'){
drupal_goto('something/that_page');
}
}
Simplest option in Drupal Form API, Using #attributes option.
$form['back-btn'] = array(
'#type' => 'button',
'#value' => t('Back'),
'#attributes' => array('onclick' => onclick='window.history.back();'),
);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With