Hi,
I'm trying to get the value of a checkbox to send in an email form but I can't figure out the logic behind it. Can someone help please.
For the textfields I;m using (<p><strong>Name:</strong> {$data['Name']}</p> ) to display the data but the checkbox looks like it needs a value to be pre-populated beforehand i.e if I set the values to true it works, but it also ticks the checkbox by default.
The error i'm getting once I submit my form is; [Notice] Undefined index: error.
This is the code that I'm using;
public function Form() {
$fields = new FieldList(
new CheckboxField('Teacher'),
new TextField('Name'),
new EmailField('Email'),
new TextareaField('Message')
);
$actions = new FieldList(
new FormAction('submit', 'Submit')
);
$validator = new RequiredFields('Email');
return new Form($this, 'Form', $fields, $actions, $validator);
}
public function submit($data, $form) {
$email = new Email();
$email->setTo('');
$email->setFrom($data['Email']);
$email->setSubject("Contact Message from {$data["Name"]}");
$messageBody = "
<p><strong>Name:</strong> {$data['Name']}</p>
<p><strong>Email:</strong> {$data['Email']}</p>
<p><strong>Message:</strong> {$data['Message']}</p>
<p><strong>Teacher:</strong> {$data['Teacher']}</p>
";
$email->setBody($messageBody);
$email->send();
return array(
'Content' => '<h1>Thank you for getting in touch.</h1>',
'Form' => '<h1>Thank you for getting in touch.</h1>'
);
}
I couldn't get this working?
static $defaults = array (
'MyBoolean' => '0'
);