示例#1
0
 function display($args)
 {
     $show = array_get_default($args, 'show', 'home');
     $page = null;
     foreach ($this->pages as $page) {
         if ($page['name'] == $show) {
             break;
         }
     }
     if (!$page) {
         $show = 'home';
         $main_show = 'home';
     } else {
         $main_show = array_key_exists('parent', $page) ? $page['parent'] : $show;
     }
     $args['show'] = $show;
     // Go to monitor if no id is specified
     $id = array_get_default($args, 'id', '');
     if ($id == '') {
         header('Location: ../?' . http_build_query($args));
         exit;
     }
     // Display menu
     $menu = $this->display_menu($main_show);
     $this->append(ax_ul_items($menu, array('id' => 'tablist')));
     foreach ($this->forms as $form) {
         if ($form['name'] == $show) {
             break;
         }
     }
     if (!$form or $form['name'] != $show) {
         return;
     }
     $title = $form['descr'];
     $form = new $form['class']($args);
     if ($form->get_data($id)) {
         // Editing existing entity
         $title .= " {$id}";
     } else {
         // Adding new entity
         $form->set_control_value('id', '');
         $id = "";
         unset($args['id']);
         $title .= " (new)";
     }
     if (Request::is_post()) {
         $form->fill($_POST);
         $msg = $form->save_data();
         $id = $form->get_control_value('id');
         $form->get_data($id);
         if ($msg != "") {
             $this->append(ax_p($msg));
         }
     }
     $fr = new AnewtFormRendererDefault();
     $fr->set_form($form);
     $this->append(ax_h2($title));
     $this->append($fr);
 }
示例#2
0
$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();