1778 Posts in 581 Topics by 555 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 875 Views |
-
Subclassing Form

14 January 2010 at 4:46am
I'm having trouble understanding the purpose of extending the Form object.
I thought creating a form Subclass would allow me to call it from any PageType, I'm trying to create a form that I can use on it Originally Intended page type as well as a Virtual Page
Below is the as it exists on my original PageType
function UserProductReviewForm() {
// Create fields
$fields = new FieldSet(
new TextField('Name','Name:'),
new EmailField('Email','E-Mail Address:'),
new TextField('Location','Location:'),
new OptionsetField('Rating','Rating',array(
'1' => '1',
'2' => '2',
'3' => '3',
'4' => '4',
'5' => '5',
)),
new TextField('Title','Review Title:'),
new TextareaField('Review'),
new HiddenField('ProductID', '', $this->ID),
new HiddenField('ProductName','',$this->Title)
);
// Create actions
$actions = new FieldSet(
new FormAction('doReview', 'Submit')
);return new Form($this, 'UserProductReviewForm', $fields, $actions);
}And the New Custom Form
class NewReviewForm extends Form {
/**Create Review Form****
************************
************************/
function __construct($controller, $name) {
// Create fields
//$recaptchaField = new RecaptchaField('MyCaptcha');
$fields = new FieldSet(
new TextField('Name','Name:'),
new EmailField('Email','E-Mail Address:'),
new TextField('Location','Location:'),
new OptionsetField('Rating','Rating',array(
'1' => '1',
'2' => '2',
'3' => '3',
'4' => '4',
'5' => '5',
),
new TextField('Title','Review Title:'),
new TextareaField('Review'),
new HiddenField('ProductID', '', $this->ID),
new HiddenField('ProductName','',$this->Title)
);
// Create actions
$actions = new FieldSet(
new FormAction('doReview', 'Submit')
);
parent::__construct($controller, $name, $fields, $actions);
}How would I call this form in template?
And where do I define the new Action?Thanks
-
Re: Subclassing Form

14 January 2010 at 9:22am
Well you would need to have a function on your page controller to load the form like
function UserProductReviewForm() {
return new NewReviewForm($this, 'UserProductReviewForm');And you can then include it in the template with $UserProductReviewForm.
Your submission method would go on that same Page_Controller.
| 875 Views | ||
|
Page:
1
|
Go to Top |


