Contains one or more fields in a form
Here is an example of creating an Inputfield
$form = $modules->get('InputfieldForm');
$f = $form->InputfieldText;
$f->attr('name', 'your_name');
$f->label = 'Your Name';
$form->add($f);
$f = $form->InputfieldEmail;
$f->attr('name', 'your_email');
$f->label = 'Your Email Address';
$f->required = true;
$form->add($f);
$f = $form->InputfieldSubmit;
$f->attr('name', 'submit_subscribe');
$f->val('Subscribe');
$form->add($f);
// ProcessWire versions 3.0.205+
if($form->isSubmitted('submit_subscribe')) {
if($form->process()) {
$name = $form->getValueByName('your_name');
$email = $form->getValueByName('your_email');
echo "<h3>Thank you, you have been subscribed!</h3>";
} else {
echo "<h3>There were errors, please fix</h3>";
echo $form->render();
}
} else {
// form not submitted, just display it
echo $form->render();
}
// same as above but works in any ProcessWire version
if($input->post('submit_subscribe')) {
// form submitted
$form->processInput($input->post);
$errors = $form->getErrors();
if(count($errors)) {
// unsuccessful submit, re-display form
echo "<h3>There were errors, please fix</h3>";
echo $form->render();
} else {
// successful submit (save $name and $email somewhere)
$name = $form->getChildByName('your_name')->attr('value');
$email = $form->getChildByName('your_email')->attr('value');
echo "<h3>Thank you, you have been subscribed!</h3>";
}
} else {
// form not submitted, just display it
echo $form->render();
}
Click any linked item for full usage details and examples. Hookable methods are indicated with the icon. In addition to those shown below, the Inputfield
class also inherits all the methods and properties of: InputfieldWrapper, Inputfield, WireData and Wire.
Common
Name | Return | Summary | |
---|---|---|---|
Inputfield | string | Form action attribute (default="./") | |
Inputfield | string | Optional markup to append to the form output | |
Inputfield | int | Optionally set the column width spacing (pixels) | |
Inputfield | string | Confirmation text that precedes list of changes when class Inputfield | |
Inputfield | string | Optionally set a description headline for the form | |
Inputfield Inputfield Inputfield | string | Get name for this form | |
Inputfield Inputfield Inputfield | WireInputData null | Return WireInputData provided to processInput() method or null if not yet applicable | |
Inputfield Inputfield Inputfield | bool string | Is form submitted and ready to process? | |
Inputfield | string | Form method attribute (default="post") | |
Inputfield | string | Optional markup to prepend to the form output | |
Inputfield Inputfield Inputfield | bool | Process the form | |
Inputfield Inputfield Inputfield | InputfieldWrapper | Process input | |
Inputfield | bool | Set to false to disable automatic CSRF protection | |
Inputfield Inputfield Inputfield | string | Render form | |
Inputfield Inputfield Inputfield | (nothing) | Hook called before form render or process (3.0.171+) |
Errors
Name | Return | Summary | |
---|---|---|---|
Inputfield Inputfield Inputfield | array | Return an array of errors that occurred on any of the children during input processing. |
Additional methods and properties
In addition to the methods and properties above, Inputfield
API reference based on ProcessWire core version 3.0.244