gpt4 book ai didi

php - 如何在 Drupal 7 中提交 AJAX 表单之前显示确认框?

转载 作者:行者123 更新时间:2023-12-01 06:36:56 26 4
gpt4 key购买 nike

使用 Drupal 7 表单 API,如何在提交 AJAX 表单之前提示 javascript 确认框?我尝试了不同的可能方法来做到这一点,但没有成功。这是代码:

function create_list_form($form, &$form_state) {

$form['list_name'] = array(
'#type' => 'textfield',
'#required' => TRUE,
'#title' => 'List Name'
'#attributes' => array()
);

$form['list_desc'] = array(
'#type' => 'textfield',
'#required' => TRUE,
'#title' => 'List Desc'
'#attributes' => array()
);

$form['actions']['submit'] = array(
'#type' => 'submit',
'#attributes' => array('class' => array('use-ajax-submit')),
'#value' => 'Create List'
);


return $form;
}

这是 JavaScript 代码:

Drupal.behaviors.module = {
attach: function() {

jQuery('#edit-submit').click(function(){
if(!confirm('Are you sure?'))
return false;
});

}
}

最佳答案

我已经找到解决办法了。我们可以通过重写 beforeSerialize() 函数来做到这一点:

 Drupal.behaviors.module = {
attach: function() {

Drupal.ajax['edit-submit'].beforeSerialize = function () {

if(confirm('Are you sure?'))
return true;
else
return false;

}
}
}

关于php - 如何在 Drupal 7 中提交 AJAX 表单之前显示确认框?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12479118/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com