In mysite / code / Connectors.php I created a form with a custom template in Page_Controller strong> 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 the inclusion page file_name / 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.
Usually I just created a public function and called it inside the template, but this does not work.
How can I access a function from a custom form template?
I tried various ways to access it, such as $Top.TestFunction, $TestFunction()and$Parent.TestFunction
Thanks - Ash