webCOMAND

\io_comand_web\form

Produce and process web forms based on an object and it's content types.

Example

The following example produces a web form and processes submissions.

// get a new Contact object to work with
$repo = comand::repo();
$contact = $repo->new_object('Contact');

// create a form object to work with a Contact
$form = new \io_comand_web\form($contact);

// update the $contact object based on POST, if any
$form->update(['write'=>'approve']);

// display a new form to update the contact object
echo($form->form());

cMVC Example

controllers/form.php

namespace com_example_www\controllers;

// Validate field values from a form submission
class form extends \io_comand_mvc\controller {
    function web__index() {
        $contact = $this->repo()->new_object('Contact');
        $form = $this->request->form($contact);
        $this->view('contact_form', ['form'=>$form]);
    }
}

views/contact_form.php

<h1>Contact</h1>
<?= $form->form(); ?>

Properties

The following properties can all be set with corresponding options in the Constructor or accessed, set, unset or checked with isset.

  • action - Get or set the form action.
  • method - Get or set the form submit and request method.
  • prefix - Get or set the form field prefix.