1

下面提到的代码不起作用

function yourModuleName_form_alter(&$form, $form_state, $form_id) {
  if ((strpos($form_id, 'contact_mail_page') === 0)) {
    $form['reset'] = array(
      '#value' => '<input class="form-button" type="reset" value=" Reset " />',
      '#weight' => 1001,
    );
  }
}
4

3 回答 3

0

Option1 如果您想使用自定义 html,您应该使用 'markup' 或 'item' 表单元素

$form['reset'] = array(
  '#type' => 'markup'
  '#markup' => '<input class="form-button" type="reset" value=" Reset " />',
  '#weight' => 1001,
);

选项 2使用 javascript 和按钮

$form['actions']['reset'] = array(
  '#type' => 'button',
  '#value' => t('Reset'),
  '#weight' => 1001,
  '#validate' => array(),
  '#attributes' => array('onclick' => 'this.form.reset(); return false;'),
);

Optoin 3您可以将链接添加到同一页面并将其设置为按钮

$form['reset'] = array(
   '#type' => 'markup'
   '#markup' => '<a href="/contact">' .t('Reset') . '<a/>',
   '#weight' => 1001,
);

选项 4添加在提交时不会执行任何操作的提交或按钮。

于 2013-06-28T06:52:06.250 回答
0

这对我有用:

$form['reset'] = array(
        '#type' => 'markup',
        '#markup' => '<input type="reset" value="Reset All Values" class="form-submit">',
    );

谢谢 :-)

于 2013-08-06T14:42:10.537 回答
0
function mymodule_form_alter(&$form, &$form_state, $form_id) {

switch ($form_id) {

case 'myform':
  $form['buttons']['reset_button'] = array(
    '#type' => 'markup',
    '#value' => '<input class="form-button" value="Reset" type="reset">',
    '#weight' => 2000,
  );
  break;
 }

return $form;

}
于 2013-12-25T06:14:57.933 回答