In mysite/code/Connectors.php I've created a form with a custom template in the Page_Controller here is the code:
class Connectors_Controller extends Page_Controller {
private static $allowed_actions = array (
'TestForm',
'TestFunction'
);
public function TestFunction(){
return 'Hello World!';
}
public function TestForm(){
$fields = new FieldList(
new TextField('Test', 'Test')
);
$actions = new FieldList(
new FormAction('doSubmit', 'Submit')
);
$form = new Form($this, 'TestForm', $fields, $actions);
$form->setTemplate('ContactForm');
return $form;
}
}
I created an include page themename/templates/Includes/ContactForm.ss
<form $FormAttributes id="contactform" action="$Link/Connectors" method="post" class="validateform AjaxForm">
<% loop $Fields %>
$Field
<% end_loop %>
$Actions.dataFieldByName(action_doSubmit)
// I want this function to print Hello World but it doesn't
$TestFunction
</form>
This works fine until I want to run another function from the same controller in the template.
Normally I'd simply create a public function and call it within the template - but this doesn't work.
How can I access a function from within a custom form template?
I've tried various methods of accessing it such as $Top.TestFunction
, $TestFunction()
and $Parent.TestFunction
Thanks - Ash