一部のコンテンツで削除ボタンを押すと、確認ページが表示されます。削除オプションはボタンで、キャンセル オプションはリンクです。それはかなり奇妙に見えます。drupal に form_confirm() 関数があることを知りましたが、使い方がわかりません。キャンセルリンクをボタンにする方法を知っている人はいますか?
2642 次
4 に答える
2
キャンセル リンクがリンクのように見える理由は、それがリンク<a>
であり、確認ボタンがフォーム送信要素であるため<input type="submut>
です。
キャンセル リンクを送信ボタンのように見せたい場合は、純粋な CSS でそれを行うことができます。
于 2010-08-15T14:11:59.920 に答える
1
hook_form_alter()を使用して、これを試してください:
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;';
}
}
于 2010-08-19T16:24:32.023 に答える
0
または、これはJavaScriptを使用せずに(そして eregi() を 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,
);
}
}
と
function mymodule_confirm_form_cancel(&$form,&$form_state) {
$href=$form['href']['#value'];
if ( !is_null($href) ) {
$form['#redirect']=$href;
}
}
于 2010-08-29T21:24:57.753 に答える