InputfieldForm class

Contains one or more fields in a form

Here is an example of creating an InputfieldForm using Inputfield modules. This particular example is an email subscription form.

$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 InputfieldForm class also inherits all the methods and properties of: InputfieldWrapper, Inputfield, WireData and Wire.

Show class?             Show args?        

Common

NameReturnSummary 
InputfieldForm::action string Form action attribute (default="./") 
InputfieldForm::appendMarkup string Optional markup to append to the form output 
InputfieldForm::columnWidthSpacing int Optionally set the column width spacing (pixels) 
InputfieldForm::confirmText string Confirmation text that precedes list of changes when class InputfieldFormConfirm is active 
InputfieldForm::description string Optionally set a description headline for the form 
InputfieldForm::getFormName()
stringGet name for this form 
InputfieldForm::getInput()
WireInputData nullReturn WireInputData provided to processInput() method or null if not yet applicable 
InputfieldForm::isSubmitted()
bool stringIs form submitted and ready to process? 
InputfieldForm::method string Form method attribute (default="post") 
InputfieldForm::prependMarkup string Optional markup to prepend to the form output 
InputfieldForm::process()
boolProcess the form
InputfieldForm::processInput(WireInputData $input)
InputfieldWrapperProcess input
InputfieldForm::protectCSRF bool Set to false to disable automatic CSRF protection 
InputfieldForm::render()
stringRender form
InputfieldForm::renderOrProcessReady($type)
(nothing)Hook called before form render or process (3.0.171+)

Errors

NameReturnSummary 
InputfieldForm::getErrors()
arrayReturn 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, InputfieldForm also inherits the methods and properties of these classes:

API reference based on ProcessWire core version 3.0.244

Latest news

  • ProcessWire Weekly #559
    The 559th issue of ProcessWire Weekly brings in all the latest news from the ProcessWire community. Modules, sites, and more. Read on!
    Weekly.pw / 25 January 2025
  • ProcessWire 3.0.244 new main/master version
    ProcessWire 3.0.244 is our newest main/master/stable version. It's been more than a year in the making and is packed with tons of new features, issue fixes, optimizations and more. This post covers all the details.
    Blog / 18 January 2025
  • Subscribe to weekly ProcessWire news

“Indeed, if ProcessWire can be considered as a CMS in its own right, it also offers all the advantages of a CMF (Content Management Framework). Unlike other solutions, the programmer is not forced to follow the proposed model and can integrate his/her ways of doing things.” —Guy Verville, Spiria Digital Inc.