Someone help! I have a problem creating form template.
I checked:
http://doc.silverstripe.org/sapphire/en/topics/forms
http://silverstripe.org/form-questions/show/8333
but I still confused all process. Here are my code:
input code is not showing, not sure where I am missing,,,,
thanks
Contact.php
<?php
class Contact extends Page { ...}
class Contact _Controller extends Page_Controller {
static $allowed_actions = array(
'ContactForm'
);
function ContactForm(){
$fields = new FieldSet(
new TextField('Name', 'name: *', '', '20'),
new EmailField('Email', 'email: *', '', '50')
);
$actions = new FieldSet(new FormAction('sendContactForm', 'Submit'));
$validatior = new RequiredFields('Name’, 'Email');
return new Form($this, 'ContactForm', $fields, $actions, $validatior);
}
public function MyForm() {
return new MyForm($this, 'MyForm');
}
function SendContactForm($data, $form){ … }
}
?>
MyForm.php
<?php
class MyForm extends Form{
function __construct($controller, $name){
$fields = new FieldSet(
new TextField('Name', 'name: *', 'first', '20'),
new EmailField('Email', 'email: *', '', '50')
);
$actions = new FieldSet(new FormAction('sendContactForm', 'Submit'));
$validatior = new RequiredFields('FirstName', 'LastName', 'Email', 'Details');
parent::__construct($controller, $name, $fields, $actions, $validatior);
}
function forTemplate(){
return $this->renderWith( array(
$this->class,
'Form'
));
}
function sendContactForm($data, $form){ ... }
}
?>
Contact.ss
…
<% include MyForm %>
...
MyForm.ss
<form $FormAttributes id="contactForm">
<table class="contactTable" cellpadding="0" cellspacing="0">
<tr><th> <table class="formLft" cellpadding="0" cellspacing="0">
<tr><th><label>name <span>*</span></label></th>
<td>
<div class="inputField fltLft" style="margin-right:3px;">
<div class="inputField2">
<div class="inputField3">
$dataFieldByName(Name)
</div></div></div>
<div class="clr"></div>
</td> </tr>
<tr><th><label for="$FormName_Email">email <span>*</span></label></th>
<td><div class="inputField"><div class="inputField2"><div class="inputField3">
$dataFieldByName(Email)
</div></div></div></td>
</tr></table>
</form>