【问题标题】:Modifying Webform module修改网络表单模块
【发布时间】:2010-02-26 23:14:59
【问题描述】:

我需要一些帮助来修改Webform Module,以便它可以用于我的项目。 我现在将 Webform 用于单页、基本表单,而且效果非常好。 我需要能够根据用户所做的一些初始选择来获取多个网络表单并将它们串在一起。 举个例子吧。

用户会被发送到“一般信息”网络表单,他们会在其中输入姓名和生日等信息。还有 3 个带有复选框的问题:

“你有房子吗”

“你有车吗”

“你有孩子吗”

用户可以选择全部、部分或不选择任何选项。根据用户的选择,一旦他们按下提交按钮,他们将被发送到“房屋表格”、“汽车表格”和/或“儿童表格”。

当他们填写完所有表单后,会向管理员发送一封电子邮件,就像现在的 webforms 一样。信息不需要存储在网站的数据库中,邮箱就足够了。

那么,关于如何做到这一点有什么建议吗?除了 Webform 之外的其他东西会更合适吗?或者(如果我非常幸运的话)有一个模块可以满足我的需要吗?

【问题讨论】:

    标签: php drupal drupal-webform


    【解决方案1】:

    为什么不根据需要简单地显示或隐藏表单元素,而不是重定向到其他潜在的多个后续表单?

    使用以下 (x)html:

    <form enctype="form/multipart" method="post" action="">
    
        <fieldset>
    
            <legend>Cars:</legend>
    
            <label for="cars">Do you have one, or more, cars?</label><input name="cars" id="cars" class="test" type="checkbox" />
            <fieldset class="subSection" id="cars">
                <input type="radio" name="numCars" value="1" />One
                <input type="radio" name="numCars" value="2" />Two
                <input type="radio" name="numCars" value="3" />Three
            </fieldset>
    
        </fieldset>
    
        <fieldset>
    
            <legend>Children:</legend>
    
            <label for="kids">Do you have one, or more, children</label><input name="kids" id="kids" class="test" type="checkbox" />
            <fieldset class="subSection" id="kids">
                <input type="radio" name="numKids" value="1" />One
                <input type="radio" name="numKids" value="2" />Two
                <input type="radio" name="numKids" value="3" />Three
            </fieldset>
    
        </fieldset>
    
        <fieldset>
    
            <legend>Houses:</legend>
    
            <label for="houses">Do you have one, or more, houses</label><input name="houses" id="houses" class="test" type="checkbox" />
            <fieldset class="subSection" id="houses">
                <input type="radio" name="numHouses" value="1" />One
                <input type="radio" name="numHouses" value="2" />Two
                <input type="radio" name="numHouses" value="3" />Three
            </fieldset>
    
        </fieldset>
    
    </form>
    

    还有 jQuery(可以整理,但我自己还是新手……所以恐怕只是“概念证明”):

    $(document).ready(
        function() {
            // hide the sub-sections
            $('fieldset.subSection').hide();
    
            // show subsections onClick of the .test checkboxes
            $('input.test').click(
                function() {
                    $(this).next('fieldset.subSection').slideToggle('slow');
                }
            )
        }
    );
    

    现场演示目前位于:http://davidrhysthomas.co.uk/so/subForms.html

    【讨论】:

    • 难以置信,谢谢。然而,要填写的表格非常大,将所有这些信息放在一个页面上对于用户来说将是非常令人生畏的。再次,谢谢你。我从来没有通过现场演示得到答案。
    • 我只能根据经验说话,但我从来不喜欢从一页到另一页填写一张表格。值得研究 javascript 实现,将一个整体形式分解为更小的部分或类似轮播界面的“页面”。
    • @Davey,谢谢。但它是相当基本的 jQuery。我衷心推荐,如果你喜欢这个,请访问docs.jquery.com 并在那里阅读相关主题。 =)
    【解决方案2】:

    条件字段是即将发布的 Webform 版本 3 的一项功能。请参阅相关的 issue 和两周前发布的 beta version

    【讨论】:

    • 感谢您指出这一点。我还没有看到测试版,但它可以满足我的一切需求。
    【解决方案3】:

    创建自定义模块,它将通过 hook_nodeapi 捕获提交并重定向到正确的表单或页面...

    【讨论】:

      猜你喜欢
      • 2011-09-04
      • 2016-04-28
      • 2010-12-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-18
      • 1970-01-01
      • 2012-09-10
      相关资源
      最近更新 更多