多步形式与上传&保存到节点类型 [英] multi step form with upload & save to node type

查看:141
本文介绍了多步形式与上传&保存到节点类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在drupal 6中,尝试大约一个星期来做多步骤形式的api,而在步骤2中有2个上传字段,然后应该继续进行到第5步,在用户填写第1步后,他可以跳过整个表单,提交数据...
我试图做到这一点,而不是成功,我粘贴一些代码,而不是工作,而多边形插件是有点bug
任何人做了类似的事情,可以共享代码或者只是解释一下我应该使用什么功能,如何?

解决方案

尝试多样,但要小心,因为它仍然在dev状态。



如果您想自己做,请使用表示当前步骤的形式称为步骤的存储变量,并在每次调用此函数时增加它

  //如果**步骤**未设置,使其为0,否则将其递增1. 
$ step = isset($ form_state ['values'])? (int)$ form_state ['storage'] ['step']:0;
$ form_state ['storage'] ['step'] = $ step + 1;

使用switch case来呈现当前步骤的表单元素。如果不是最后一步显示下一个按钮,否则提交按钮。将值从 $ form_state ['values']移动到$ form_state ['storage']



在提交功能,如果是刚刚返回的最后一步,则执行数据库插入。


im trying about a week to do multistep form usin form api in drupal 6 and in the step 2 there is 2 upload fields and then its should proceed until step 5, after user fill the step 1 he can skip the whole form and submit the data... im trying to do it and im not success, i glue some pices of code and its not work , and multiform plugin is kinda buggy anyone did something like that and can share the code or just explain me what functions i should use and how?

解决方案

Try multiform, but be careful as it is still in dev state.

If you want to do it on your own, have a storage variable called step in the form which represents the current step, and increment it everytime this function is called.

// if **step** is not set, make it 0, else increment it by 1.
$step = isset($form_state['values']) ? (int)$form_state['storage']['step'] : 0;
$form_state['storage']['step'] = $step + 1; 

Use a switch case to render the form elements for the current step. If it is not last step dispaly next button, else submit button. Move the values from $form_state['values'] to $form_state['storage']

In the submit function, perform the database insertion if it is the last step else just return.

这篇关于多步形式与上传&保存到节点类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆