Hey, this is my first post on this forum so please indulge my noobyness. ;)
My issue:
I created a simple contact form based on Uncle Cheese's tutorial (http://www.silverstripe.org/learn/lessons/introduction-to-frontend-forms#tabpane-tutorial) with the only difference being, that i want to send an email upon submission and not save a comment. The form in general looks fine, but on submission I get a "Page not found".
Some more details:
- I'm using SilverStripe 3.2.1
- The contact-form is accessible (on /contact) and shows all fields as expected.
- Upon submission the form redirects to /contact/ContactForm –as I would expect– but the 404 page is shown
- nested_urls in the config.yml is set to true
- further code is attached below
- I tried to rewrite everything once, to make sure i did not screw up on any typos, but with the same result
My code:
Contact.php
class Contact extends Page {
static $description = 'Default contact form';
static $db = array('SubmitText' => 'HTMLText');
public function getCMSFields() {
$fields = parent::getCMSFields();
$fields->addFieldToTab('Root.Main', new HtmlEditorField('SubmitText', 'Thank you text'));
return $fields;
}
}
class Contact_Controller extends Page_Controller {
private static $allowed_actions = array(
'ContactForm'
);
public function init() {
parent::init();
}
public function ContactForm() {
$fields = FieldList::create(
TextField::create('Name', 'Your name'),
EmailField::create('Email', 'Your eMail-address'),
DropdownField::create('Subject', 'Subject', array(
'' => 'Select one option',
'Question about an order',
'Foo',
'Bar',
'Just say "Hi"'
)),
TextareaField::create('Message', 'Your message')
);
$actions = FieldList::create(
FormAction::create('submitContact', 'Submit')
->setUseButtonTag(TRUE)
->addExtraClass('button')
);
$validator = RequiredFields::create('Name', 'Email', 'Message');
return Form::create($this, __FUNCTION__, $fields, $actions, $validator);
}
public function submitContact($data, $form) {
$config = SiteConfig::current_site_config();
$email = new Email();
$email->setTo($config->ContactMail);
$email->setFrom($data['Email']);
$email->setSubject("xxxxxxxx :: Contact from {$data["Name"]}");
$messageBody = sprintf(
"<p><strong>Name:</strong> %s</p><p><strong>Message:</strong><br>%s</p>",
$data['Name'],
$data['Message']
);
$email->setBody($messageBody);
$email->send();
return array(
'Content' => $this->SubmitText,
'ContactForm' => ''
);
}
}
routes.yml (not sure it this affects the issue)
---
Name: myroutes
After: framework/routes#coreroutes
---
Director:
rules:
'shorturl': 'Page_Controller'
'item//$Action/$ID': 'Item_Controller'
'editorial//$Action/$ID': 'Editorial_Controller'
I hope that covers all the needed infos, and i am really thankful for any hints or suggestions that can get me on the right track.