I know this has been covered elsewhere, but I'm not seeing a solution that works for me. This is the closest (http://silverstripe.org/form-questions/show/10686), but that doesn't seem to fix the issue either.
Action:
When a user submits the form, after $validator/capthca and before data is written to the database, the script checks to make sure there isn't a duplicate email already in the database.
Expected result:
If a duplicate email is found, the user is returned to the form with an error message AND their form data re-populated in the form fields.
Actual result:
If a duplicate record is found the user is returned to the form, an error message tells them a duplicate record was found, but none of the form fields are re-populated with the user's input.
Note: Otherwise this works fine. Fields validate and new users are added to the database.
/mysite/code/LandingFormPage.php:
class LandingFormPage_Controller extends Page_Controller {
function LandingForm() {
$fields = new FieldSet(
new TextField('FirstName','First Name*'),
new TextField('LastName','Last Name*'),
new EmailField('Email','Email*'),
new TextField('Company','Company'),
new TextField('Title','Title'),
new TextField('Phone','Phone') )
);
$actions = new FieldSet(
new FormAction('doSignup', 'Sign Up')
);
$validator = new RequiredFields('FirstName', 'LastName', 'Email');
$form = new Form($this, 'LandingForm', $fields, $actions, $validator);
SpamProtectorManager::update_form($form,'','','Help Us Stop Spam By Verifying These Letters');
return $form;
}
function doSignup($data, $form) {
$submission = new LandingFormSubmission();
$form->saveInto($submission);
if(DataObject::get_one('LandingFormSubmission', "Email = '".$submission->getField('Email')."'")) {
$form->addErrorMessage("Email", 'That email address has already been used to register.', "bad");
// Session::set("FormInfo.LandingForm_LandingForm.data", $data);
return Director::redirectBack();
} else {
$submission->write();
Director::redirectBack();
}
}
As you can see I've also tried setting my data, but that doesn't seem to make a difference. A nudge in the right direction would be greatly appreciated.
Chris.b