SilverStripe表示不发送所有数据?

时间:2012-04-06 13:34:39

标签: forms silverstripe

大约两个月前,我将SilverStripe网站从2.3.5升级到2.4.6。自升级以来,我网站上的一些表单不会将所有数据发送到提交功能(POST条目为空),包括“系统”表单,如管理部分的忘记密码表单(我认为甚至管理员登录表单的密码字段)。我觉得奇怪的是,我有一个几乎相同(但不同的代码)形式的相同字段,工作得很好,但即使复制字段也不起作用。

这是工作表单及其提交代码:

function ContactUsForm() {
        // Create fields
        $fields = new FieldSet(
                        new HeaderField('Send Us a Message:', '2'),
                        new TextField('NAME', 'Full Name:'),
                        new EmailField('EMAIL', 'E-mail Address:'),
                        new TextField('PHONE', 'Phone:'),
                        new TextField('COMPANYNAME', 'Company Name:'),
                        new TextareaField('MESSAGE', 'Message/Note:'),
                        new TextField('HUMAN', '1+1 =')
        );

        // Create actions
        $actions = new FieldSet(
                        new FormAction('doContactUs', 'Submit')
        );

        return new Form($this, 'ContactUsForm', $fields, $actions);
    }

    function doContactUs($data, $form) {

        $human = $data['HUMAN'];
        if ($human == '2') {
            $from = 'contact@example.com';
            $to = 'contact@example.com';
            $subject = 'General Contact  Submission';
            $body = $data['NAME'] . ' has submitted a General Inquiry, their info: ' . $data['NAME'] . ' | ' . $data['EMAIL'] . ' | ' . $data['PHONE'] . ' | ' . $data['COMPANYNAME'] . ' and they have included the following note (if they included a note): ' . $data['MESSAGE'];
            $email = new Email($from, $to, $subject, $body);
            $email->send();


            Director::redirect('thankyou/');
        } else {
            $form->addErrorMessage('Message', 'Incorrect answer to the human check.','error');
            return Director::redirectBack();
        }
    }

以下是不起作用的表单及其提交代码:

function GenericContactForm() {

    global $contactmessage;

    // Create fields
    $fields = new FieldSet(
            new TextField('NAME', 'Full Name:'),
            new EmailField('EMAIL', 'Email:'),
            new TextField('TELEPHONE', 'Work Phone:'),
            new ListboxField(
                $name = "TYPEOFCONTACT",
                $title = "Office Type:",
                $source = array(
                "Single Person Office" => "Single Person Office",
                "Team Room" => "Team Room",
                "Open Plan" => "Open Plan"
                ),
                $value = 1
            ),
                    new TextField('HUMAN', '1+1 =')
    );

    // Create actions
    $actions = new FieldSet(
            new FormAction('doGenericContact', 'Submit')
    );

    return new Form($this, 'GenericContactForm', $fields, $actions);
}

function doGenericContact($data, $form) {
    $human = $data['HUMAN'];
    if ($human == '2') {
        $from = $data['EMAIL'];
        $to = 'contact@example.com';
        $subject = 'Contact Request';
        $body = 'The following individual has requested to be contacted: ' . $data['NAME'] . ' | ' . $data['EMAIL'] . ' | ' . $data['TELEPHONE'] . ' and they have made contact to inquire about the following: ' . $data['TYPEOFCONTACT'];
        $email = new Email($from, $to, $subject, $body);
        $email->send();

        Director::redirect('/thankyou/');
    } else {
        $form->addErrorMessage('Message', "Incorrect answer to the human check. (Your answer: $human)", 'error');
        return Director::redirectBack();
    }
}

我已经尝试删除ListboxField,因为这是我发现的唯一真正的区别。我还尝试通过删除提交函数中if语句的“true”部分内的所有内容来本地测试它,它在本地工作,但不在服务器上,这使我相信它可能是SilverStripe和服务器设置(我对服务器的访问权限有限)。此外,这些表单在升级之前有效。

关于导致这种情况的原因,以及我可以采取哪些措施来解决这个问题?

修改 - 进一步的问题排查发现,非工作表单上的帖子数组中没有数据。

1 个答案:

答案 0 :(得分:0)

事实证明,SilverStripe 2.4执行模块的方式与2.3模块的方式有关。我不是那个解决它的人,所以我没有关于这个问题的细节,但是让模块符合2.4的预期已经修复了它。