class myExample extends Component { public $form = null; public function __construct() { // Set component properties $this->setPropertyMap([ 'name' => '', 'age' => 0 ]); // Construct form $this->form = new Form('name_age_form'); $this->form->addField(TextField::Field('Name', 'name')); $this->form->addField(TextField::Field('Age', 'age')); $this->form->addField(SubmitButton::Field('Send', 'send')); // Attach form to component $this->registerForm($this->form); // Redirect the resetcomponent event to the backend $this->registerEvent('resetcomponent'); } public function renderContent() { // Check if name is attached to component if ($this->name) { // Display text echo 'You have entered '.$this->name.' as name and '.$this->age.' as age.'; // Display a link to reset the component $menuitem = new MenuItem('Reset component', '#TRIGGER=resetcomponent'); $menuitem->render(); } else { // Display the form $this->form->render(); } } public function handleIO() { // Check if form is submitted. if ($this->form->isSubmitted()) { // Validate form $result = $this->form->validate(); // Send error if not validated if (! $result) return ['status' => false, 'form_errors' => $form->getAllErrors()]; // Get values and transfer to component properties $values = $this->form->getValues(); $this->name = $values['name']; $this->age = $values['age']; // Return status, updated properties and a redraw request. return ['status' => true, 'properties' => $this->getEncodedProperties(), 'redraw' => true]; } // Check if reset was triggered if ($_POST['event'] == 'resetcomponent') { // Clear properties $this->name = ''; $this->age = 0; // Return updated properties and a redraw request. return ['properties' => $this->getEncodedProperties(), 'redraw' => true]; } } }