When I press the delete button on some content, I'm taken to a confirmation page. The delete option is a button, while the cancel option is a link. That looks pretty weird. I found that there's a form_confirm() function in drupal, but I can't understand how to use it. Does anyone know how to make the cancel link into a button?
+1
A:
The reason the cancel link looks like a link, is because it is a link <a>
, while the confirm button, is a form submit element <input type="submut>
.
If you want to make the cancel link, to look like a submit button, you can do that with pure CSS.
googletorp
2010-08-15 14:11:59
In Safari (and Chrome?), it's as easy as using `-webkit-appearance: push-button`.
Mark Trapp
2010-08-15 20:45:06
I've been looking around on the internet but can't find the proper css code. All I find is how to make stylish buttons, but I simply want a regular system button.
Toxid
2010-08-16 21:41:37
A:
Using hook_form_alter() , try this :
if($form['#theme'] == 'confirm_form') {
$no = $form['actions']['cancel']['#value'];
if (!is_null($no)) {
// Get the text to put on the cancel button
$value = preg_replace('/(<\/?)(\w+)([^>]*>)/e', '', $no);
eregi('m|href\s*=\s*\"([^\"]+)\"|ig', $no, $href);
$form['actions']['cancel']['#value'] = '';
// Add our own button
$form['actions']['docancel'] = array(
'#type' => 'button',
'#button_type' => 'reset',
'#name' => 'cancel',
'#submit' => 'false',
'#value' => $value,
'#attributes' => array(
'onclick' => '$(this).parents("form").attr("allowSubmission", "false");window.location = "'.$href[1].'";',
),
);
// Prevent the form submission via our button
$form['#attributes']['onsubmit'] = 'if ($(this).attr("allowSubmission") == "false") return false;';
}
}
Vodde
2010-08-19 16:24:32
A:
Or this using no javascript (and replacing eregi() with preg_match()...
if ( $form['#theme'] == 'confirm_form' ) {
$no = $form['actions']['cancel']['#value'];
if (!is_null($no)) {
// Get the text to put on the cancel button
$value = preg_replace('/(<\/?)(\w+)([^>]*>)/e', '', $no);
preg_match('/href\s*=\s*\"([^\"]+)\"/', $no, $href);
$form['actions']['cancel']['#value'] = '';
$form['href']=array(
'#type'=>'value',
'#value'=>$href[1],
);
// Add our own button
$form['actions']['docancel'] = array(
'#type' => 'submit',
'#name' => 'cancel',
'#submit' => array('mymodule_confirm_form_cancel'),
'#value' => $value,
);
}
}
and
function mymodule_confirm_form_cancel(&$form,&$form_state) {
$href=$form['href']['#value'];
if ( !is_null($href) ) {
$form['#redirect']=$href;
}
}
Chris
2010-08-29 21:24:57