$page = new AnewtPage(); $page->set('title', 'Anewt form test page'); $page->add_stylesheet(ax_stylesheet($css)); $page->append(ax_h1('Test form')); $form = new TestForm(); assert('$form->get_control_value("text5") === "7"'); $form->set_control_value('text5', '8'); if ($form->autofill()) { if ($form->process()) { $page->append(ax_p('Form succesfully processed!')); } else { $page->append(ax_p('Error while processing form!')); } } else { $page->append(ax_p('Form not processed.')); } $fr = new AnewtFormRendererDefault(); $fr->set_form($form); $page->append(ax_h2('The form')); $page->append($fr); if (AnewtRequest::is_post()) { $values = $form->get_control_values(); ob_start(); var_dump($values); $values = ob_get_clean(); $page->append(ax_h2('Form output')); $page->append(ax_pre($values)); $page->append(ax_h2('$_POST values')); $page->append(ax_pre(print_r($_POST, true))); } $page->flush();
/** * Fill form automatically from query data. If the form uses the GET method * the data comes from <code>$_GET</code>. If the form uses the POST method * the data comes from <code>$_POST</code>. * * The return value (see also fill() for an explanation) can be used to * detect incomplete \c $_GET or \c $_POST values. This may happen when * handling different form flavours with different controls using a single * form, e.g. a simple and advanced search form pointing to the same page in * which an instance of the advanced flavour of the form handles the * submitted data. It may also happen when users are messing with the * submitted data. You may then decide to process() the form only if all * values were provided. Example: * <code>if ($form->autofill() && $form->process()) { ...} else { ...}</code> * * \return * True if this fill could be automatically filled from \c $_GET or \c * $_POST, false if this was not the case. * * \see AnewtForm::fill() */ function autofill() { $form_method = $this->_get('method'); if (AnewtRequest::is_get() && $form_method == ANEWT_FORM_METHOD_GET) { return $this->fill($_GET); } elseif (AnewtRequest::is_post() && $form_method == ANEWT_FORM_METHOD_POST) { return $this->fill($_POST); } return false; }