欢迎各位兄弟 发布技术文章

这里的技术是共享的

You are here

form js confirm 提示 确认提交 经测试 下面的代码 有大用

shiping1 的头像


I would use the code below for a few reasons:
1) It's properly integrated with the Drupal system
2) It maintains the separation of markup and function (html and javascript) by keeping the javascript external.

function hook_form($node, $form_state)
{
  $msg = t('Do you want to submit this?');
  $jscript = 'Drupal.behaviors.moduleName = function() {$("#confirm_submit").click(function(){return confirm("' . $msg . '")});}';
  drupal_add_js($jscript, 'inline');
  $form['submit'] = array
  (
    '#type' => 'submit',
    '#id' => 'confirm_submit',
    '#value' => t('Submit'),
  );
  return $form;
}

Note: The following variables should be adjusted to match your module:
1) moduleName should be changed to the name of your module
2) $msg should be changed to whatever message you want.

来自 https://www.drupal.org/node/564710
普通分类: