大约两个月前,我将 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 语句的“真实”部分中的所有内容来在本地对其进行测试,它在本地工作,但在服务器上不工作,这让我相信这可能是 SilverStripe 中的某些内容和服务器设置(我对服务器的访问权限有限)。此外,这些表格在升级之前有效。
关于造成这种情况的任何想法,以及我能做些什么来解决它?
编辑- 进一步的故障排除发现非工作表单上的帖子数组中没有数据。