Created
March 22, 2016 12:49
-
-
Save Lazerproof/fd29c839b83f4605b260 to your computer and use it in GitHub Desktop.
ProcessWire fields
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
hidden | |
------ | |
$field = $this->modules->get('InputfieldHidden'); | |
$field->label = __('Some Label'); | |
$field->attr('name+id','some_label'); | |
$field->attr('value', 'some value'); | |
submit | |
------ | |
$submit = $this->modules->get('InputfieldSubmit'); | |
$submit->name = 'submit'; | |
$submit->attr('value', __('Send')); | |
$submit->attr('class', 'button'); | |
select | |
------ | |
$select = $this->modules->get('InputfieldSelect'); | |
$selectType->name = 'select-name'; | |
$selectType->addOption('B', $this->_('Option B')); | |
$selectType->addOption('A', $this->_('Option A')); | |
$selectType->value = 'B'; // if you want to set a predefined value | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$field->columnWidth = 50; | |
$field->required = 1; | |
$field->requiredIf = 'some=selector'; | |
$field->description = $this->_('some description'); | |
$field->notes = $this->_('some notes'); | |
$field->class = 'additional-class'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$form = $this->modules->get('InputfieldForm'); | |
$form->action = './'; | |
$form->method = 'post'; | |
$form->attr('id+name','newsletter'); | |
$form->description = $this->_('Optionally set a description headline for the form'); | |
// prepend, append markup | |
$form->prependMarkup = "<div>Some HTML</div>"; | |
$form->appendMarkup = "<div>{$page->field}</div>"; | |
// adapt classes and markup | |
$form->setMarkup($markup); | |
$form->setClasses($classes); | |
// @see: https://github.com/ryancramerdesign/ProcessWire/blob/master/wire/core/InputfieldWrapper.php#L34 | |
$markup' => array( | |
'InputfieldSelect' => array( | |
'item' => "{out}" | |
) | |
); | |
$classes' => array( | |
'form' => 'form form__super-special-class', | |
'InputfieldRadios' => array( | |
'item' => 'form__item--options' | |
) | |
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// create and append fields | |
$form->append($field); | |
// or create fieldset and add fields there | |
$fieldset = $this->modules->get('InputfieldFieldset'); | |
$fieldset->label = 'Some Label'; | |
$fieldset->add($field); | |
$form->append($fieldset); | |
$form->render(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$form->processInput($this->input->post); | |
// add additional error checks | |
// email unique | |
$email = $form->get('email'); | |
$unique = $this->users->get("email=$email"); | |
if ($unique->count() > 0) $email->error(__('This email address is already registered.')); | |
if ($form->getErrors()) { | |
// the form contains errors | |
return $form->render(); | |
} else { | |
// do with the form what you like, create and save it as page | |
// or send emails. to get the values you can use | |
// $email = $form->get("email")->value; | |
// to sanitize input | |
// $email = $sanitizer->email($form->get("email")->value); | |
return "<p>You submission was completed! Thanks for your time."; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment