download201401 2017-01-08 23:53 采纳率: 0%
浏览 51
已采纳

Drupal 7 - 节点表单 - dsm / dpm不适用于自己的验证/提交功能

I want to add an own validation (or submit) handler/function to my existing node form. I tried multiply things (following), but it does not work properly.

function MY_MODULE_form_alter(&$form, &$form_state, $form_id) { 
  $form['#validate'][] = 'MY_MODULE_handler';
//or
  $form['actions']['submit']['#validate'][] = 'MY_MODULE_handler';
//or
  $form['submit']['#submit'][] = 'MY_MODULE_handler';
//or
  $form['#submit'][] = 'MY_MODULE_handler';
//or
  array_unshift($form['#validate'], 'MY_MODULE_handler');
//or
  $form['actions']['submit']['#submit'][]='MY_MODULE_handler';
}

But none of these attempts seem to work with my handler:

function MY_MODULE_handler($form, &$form_state){
  dsm($form);  
  dsm($form_state);
}

Looking at the $form variable in form_alter I found that $form['actions']['submit']['#submit'] and $form['#validate'] have already a submit/validate handler.

But if I use one of the examples above, nothing is printed by dsm. In addition it does not print the confirmation (of submitting) anymore! But if I use

function MY_MODULE_handler($form, &$form_state){
  die('Handler was hit');
}

I see that the handler was hit.

What can be the reason? I need the handler to read two form fields and save them in one node attribute.

  • 写回答

1条回答 默认 最新

  • doukuanghuan7582 2017-01-09 15:16
    关注

    As @2pha proposed, I used instead of an additional validation/submit handler the hook HOOK_node_presave which allowed me to solve my problem (which was to assign values from the form to one node attribute, see comments).

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 在若依框架下实现人脸识别
  • ¥15 网络科学导论,网络控制
  • ¥100 安卓tv程序连接SQLSERVER2008问题
  • ¥15 利用Sentinel-2和Landsat8做一个水库的长时序NDVI的对比,为什么Snetinel-2计算的结果最小值特别小,而Lansat8就很平均
  • ¥15 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
  • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
  • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同