Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Although it's possible I'm Doing It Wrong&trade;, here's how I'm doing what I think you want.</p> <pre><code>&lt;?php class Thing_Controller extends Page_Controller { /** * Controller action for the page with the form on it */ public function page() { $this-&gt;ThingForm = $this-&gt;page_form(); // Render using custom template templates/Layout/ThingFormPage.ss // which contains $ThingForm to output return $this-&gt;renderWith(array('ThingFormPage','Page')); } /** * Return form definition * Used both to display it and for validation */ public function page_form() { $fields = new FieldList( new TextboxField('MyFormInput', 'Input Your Kerjiggers') ); $actions = new FieldList($this-&gt;forwardButton()); $required_fields = new RequiredFields(array('MyFormInput')); $form = new Form($this, 'Thing_Form', $fields, $actions, $required_fields); $form-&gt;setTemplate("Thing_Form"); $form-&gt;setFormAction("Thing/page_save"); $this-&gt;setFormMessageIfErrors($form); return $form; } /** * Validation, save and redirect */ public function page_save() { $data = $this-&gt;request-&gt;postVars(); $form = $this-&gt;page_form(); $form-&gt;loadDataFrom($data); if ($form-&gt;validator-&gt;validate() === NULL) { // All good, proceed $this-&gt;redirect('another_action'); } else { $errors = $form-&gt;validator-&gt;validate(); foreach ($errors as $e) { $form-&gt;addErrorMessage($e['fieldName'], $e['message'], $e['messageType']); } $this-&gt;redirectBack(); } } /** * If there are any errors on any RequiredFields, also set a form-level message at the top * so people know to scroll down and look for the specific errors. */ protected function setFormMessageIfErrors($form) { $s = $this-&gt;getSession()-&gt;get_all(); if (@$s['FormInfo']['Thing_Form']['errors']) { $form-&gt;setMessage("Please see the messages about your information below", 'info'); } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload