Drupal 7 FAPI- Adding form elements in validate or submit handlers(Drupal 7 FAPI- 在验证或提交处理程序中添加表单元素)
问题描述
是否可以在 drupal 7 模块的验证或提交功能中添加额外的表单元素?以下代码有效并且图像显示在表单上:
Is it possible to add additional form elements in the validate or submit functions in drupal 7 module? The following code works and image is displayed on the form:
function test1_form($form, &$form_state)
{
$form['image']=array(
'#markup'=>'<img src="sites/all/modules/create_ad/th.jpeg"><br/>', //replace with your own image path
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => 'Submit',
);
}
但是当我尝试在提交功能中提交后显示图像时,如下所示,它不起作用:
but when I try to display image after submission in submit function like following, it doesn't work:
function test1_form($form, &$form_state)
{
$form['submit'] = array(
'#type' => 'submit',
'#value' => 'Submit',
);
}
function test1_form_submit($form,&$form_state)
{
$form['image']=array(
'#markup'=>'<img src="sites/all/modules/create_ad/th.jpeg"><br/>', //replace with your own image path
);
}
欢迎任何积极的帮助.谢谢.
Any positive help is welcome. Thanks.
推荐答案
您可以在提交后按照多步骤表单方法在表单中添加其他字段.
You could follow the multi-step form methodology to add additional fields to your form after submission.
这是一篇博文,其中讨论了一种方法多步骤,可以给你一些洞察力.
Here is a blog post that talks about one approach for multi-step and can give you some insight.
基本上,在您的提交函数中,您存储您的值并设置要重建的表单.然后在您的表单函数中检查这些存储的值并添加新字段(如果存在).
Basically, on your submit function you store your values and set the form to be rebuilt. Then in your form function you check for those stored values and add the new fields if present.
例子:
<?php
function test1_form($form, &$form_state)
{
if (isset($form_state['storage']['show-image'])){
$form['image']=array(
'#markup'=>'<img src="sites/all/modules/create_ad/th.jpeg"><br/>', //replace with your own image path
);
}
$form['submit'] = array(
'#type' => 'submit',
'#value' => 'Submit',
);
}
function test1_form_submit($form,&$form_state)
{
$form_state['rebuild'] = TRUE;
$form_state['storage']['show-image'] = true;
}
这篇关于Drupal 7 FAPI- 在验证或提交处理程序中添加表单元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Drupal 7 FAPI- 在验证或提交处理程序中添加表单元素


基础教程推荐
- 有什么方法可以用编码 UTF-8 而不是 Unicode 返回 PHP`json_encode`? 2021-01-01
- 在PHP中根据W3C规范Unicode 2022-01-01
- Cron Jobs 调用带有变量的 PHP 脚本 2022-01-01
- 学说 dbal querybuilder 作为准备好的语句 2022-01-01
- 如何在 Laravel 5.3 注册中添加动态下拉列表列? 2021-01-01
- YouTube API v3 点赞视频,但计数器不增加 2022-01-01
- PHP 类:全局变量作为类中的属性 2021-01-01
- 如何在 Laravel 中使用 React Router? 2022-01-01
- 如何替换eregi() 2022-01-01
- PHP PDO MySQL 查询 LIKE ->多个关键词 2021-01-01