About two months ago, I upgraded a SilverStripe website from 2.3.5 to 2.4.6. Since the upgrade, some of the forms on my site won't send all of the data to the submit function (the POST entry is empty), including "system" forms like the forgot password form for the admin section (and I think even the password field for the admin login form). What I find odd is that I have a nearly identical (but different code) form with the same field, which works just fine, but even copying the field over doesn't work.
Here's the working form and its submit code:
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 = '[email protected]';
$to = '[email protected]';
$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();
}
}
Here's the form that doesn't work, and its submit code:
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 = '[email protected]';
$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();
}
}
I've tried removing the ListboxField, since that's about the only real difference I've found. I also tried testing it locally by removing everything inside the "true" portion of the if statement in the submit function, and it works locally, but not on the server, which leads me to believe it may be a conflict between something in SilverStripe and the server setup (I have limited access to the server). Additionally, these forms worked prior to the upgrade.
Any ideas on what is causing this, and what I can do to fix it?
Edit - Further troubleshooting has found that there is no data in the post array on the non-working forms.
Debug::show($data)insidedoGenericContact()to get a look at what is being submitted from the form. Once you verify that$data['HUMAN']has a value, make sure your email server will send emails as coming from a domain other than your own. I have a feeling the issue is related to the servers email setup and not anything SilverStripe related. - ryanwachtl