hook_form_submit 没有被调用

发布于 2024-09-11 04:10:51 字数 1096 浏览 7 评论 0原文

我正在尝试提交表单并使用 hook_form_submit。

问题是表单是通过 ajax 显示的,这会导致 hook_form_submit 不被调用。

$items['ajaxgetform/%'] = array(  
  'page callback' => 'ajaxgetform',  
  'access arguments' => array('access content'),  
  'type' => MENU_CALLBACK  
);   

function ajaxgetform($form_id) {    
  drupal_get_form($form_id);  
  return drupal_json($panel);  
}  

function_myform_form($form_state) {  
  $form['myform'] = array(  
    '#title' => 'myform value',  
    '#type' => 'textfield',  
    '#default_value' => 'myform default value'  
  );  

  $form['#action'] = url('myurl');

  $form['submit'] = array(  
    '#type' => 'submit',  
    '#value' => 'submit'  
  );

  $form['#ajaxsubmit'] = TRUE;  
    return $form;  
  }  

hook_form_alter() 确实被调用。

下面没有被调用吗?

function myform_form_submit($form, $form_state) {   
  // ...  
} 

我不确定这是否是一个常见问题,但我已经被困了几个小时试图让它发挥作用。

如果我删除 $form['#action'] = url('myurl'); myform_form_submit() 会被调用。但是我得到一个带有杰森脚本的白屏。

I'm trying to submit a form and use hook_form_submit.

The problem is the form is displayed via ajax and this results in hook_form_submit not being called.

$items['ajaxgetform/%'] = array(  
  'page callback' => 'ajaxgetform',  
  'access arguments' => array('access content'),  
  'type' => MENU_CALLBACK  
);   

function ajaxgetform($form_id) {    
  drupal_get_form($form_id);  
  return drupal_json($panel);  
}  

function_myform_form($form_state) {  
  $form['myform'] = array(  
    '#title' => 'myform value',  
    '#type' => 'textfield',  
    '#default_value' => 'myform default value'  
  );  

  $form['#action'] = url('myurl');

  $form['submit'] = array(  
    '#type' => 'submit',  
    '#value' => 'submit'  
  );

  $form['#ajaxsubmit'] = TRUE;  
    return $form;  
  }  

hook_form_alter() does get called.

Below doesn't get called?

function myform_form_submit($form, $form_state) {   
  // ...  
} 

I'm not sure if this is a common problem, but i've been stuck for hours trying to make it work.

If I remove $form['#action'] = url('myurl'); myform_form_submit() gets called. However I get a white screen with jason script.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

无戏配角 2024-09-18 04:10:51

没有 hook_form_submit()。相反,您可以使用 $form['#submit'] 注册提交处理程序。因此,如果您想在提交表单时调用 myform_form_submit(),请

$form['#submit'][] = 'myform_form_submit';

myform_form() 中 添加:查看 5.x 到 6.x 表单更改表单 API 参考了解更多信息。

There is no hook_form_submit(). Instead, you register submit handlers with $form['#submit']. So, if you want to call myform_form_submit() when the form gets submitted, add:

$form['#submit'][] = 'myform_form_submit';

to myform_form(). Take a look at the 5.x to 6.x form changes and the Forms API reference for more info.

忆梦 2024-09-18 04:10:51

您的表单是否显示在 myurl 页面上?为了处理表单提交,要显示表单(使用 drupal_get_form()) 在页面上用作操作。

您也可以尝试使用表单 #redirect 到着陆页 URL,而不是 #action。这样,表单将提交到其生成的 URL,但用户在处理后会重定向到您的目标页面。

Is your form displayed on the page at myurl ? In order for a form submission to be processed, the form as to be displayed (using drupal_get_form()) on the page used as action.

You may also try to se the form #redirect to the landing page URL instead of its #action. This way, the form is submitted to its generating URL but the user is redirected to your destination page after processing.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文