A collection of View Components for rendering form fields in the Perique Framework. Build forms with a fluent PHP API, automatic HTML rendering, built-in sanitization and validation.
usePinkCrab\Form_Components\Component\Field\Input_Component;usePinkCrab\Form_Components\Element\Field\Input\Text;$this->component(newInput_Component(Text::make('username')->label('Username')->placeholder('Enter your username')->required(true)));
Or use the Make helper for a more concise syntax:
usePinkCrab\Form_Components\Util\Make;$this->component(Make::text('username',fn($f)=>$f->label('Username')->placeholder('Enter your username')->required(true)));
Building a Complete Form
usePinkCrab\Form_Components\Util\Make;usePinkCrab\Form_Components\Element\Field\Input\{Text,Email,Tel,Hidden};usePinkCrab\Form_Components\Element\Field\{Select,Textarea};usePinkCrab\Form_Components\Element\Field\Group\Radio_Group;usePinkCrab\Form_Components\Element\{Fieldset,Form,Nonce,Button,Raw_HTML};$this->component(Make::form('enquiry',fn($f)=>$f->method('POST')->action('/submit')->fields(// Raw HTML for intro textRaw_HTML::make('intro')->html('<p>Fill in the form below and we will get back to you.</p>'),// Fieldset groups related fieldsFieldset::make('personal')->legend('Your Details')->fields(Text::make('name')->label('Name')->required(true),Email::make('email')->label('Email')->required(true),Tel::make('phone')->label('Phone')->placeholder('+44 7700 900000')),// Select and radio groupSelect::make('subject')->label('Subject')->options(array(''=>'Select...','sales'=>'Sales Enquiry','support'=>'Support','other'=>'Other',))->required(true),Radio_Group::make('priority')->label('Priority')->options(array('low'=>'Low','medium'=>'Medium','high'=>'High',))->selected('medium'),Textarea::make('message')->label('Message')->rows(5)->required(true),// Hidden field and nonce for securityHidden::make('form_id')->set_existing('enquiry-v1'),Nonce::make('submit_enquiry','_enquiry_nonce'),Button::make('submit')->type('submit')->text('Send Enquiry'))));
Generated HTML
<!-- Classes abbreviated with ".." for readability. See field docs for full class output. --><formclass=".."method="POST"action="/submit"><p>Fill in the form below and we will get back to you.</p><fieldset><legendclass="..">Your Details</legend><divid="form-field_name"class=".."><labelfor="name"class="..">Name</label><inputtype="text"name="name"class=".."required=""/></div><divid="form-field_email"class=".."><labelfor="email"class="..">Email</label><inputtype="email"name="email"class=".."required=""/></div><divid="form-field_phone"class=".."><labelfor="phone"class="..">Phone</label><inputtype="tel"name="phone"class=".."placeholder="+44 7700 900000"/></div></fieldset><divid="form-field_subject"class=".."><labelfor="subject"class="..">Subject</label><selectname="subject"class=".."required=""><optionvalue="">Select...</option><optionvalue="sales">Sales Enquiry</option><optionvalue="support">Support</option><optionvalue="other">Other</option></select></div><divid="form-field_priority"class=".."><legend>Priority</legend><labelclass=".."><inputtype="radio"name="priority"value="low"/> Low
</label><labelclass=".."><inputtype="radio"name="priority"value="medium"checked/> Medium
</label><labelclass=".."><inputtype="radio"name="priority"value="high"/> High
</label></div><divid="form-field_message"class=".."><labelfor="message"class="..">Message</label><textareaname="message"class=".."rows="5"required=""></textarea></div><inputtype="hidden"name="form_id"value="enquiry-v1"/><inputtype="hidden"name="_enquiry_nonce"value="..."/><divid="form-field_submit"class=".."><buttontype="submit"name="submit"class="..">Send Enquiry</button></div></form>
2.1.5 - Field templates no longer pass a nullbefore_field / after_field to wp_kses_post() when before() / after() weren’t called — the strict empty-string check introduced in 2.1.4 didn’t account for the unset (null) case, which triggered a preg_replace(): Passing null deprecation on PHP 8.1+. Fixed by checking for both null and empty string. (Issue #25)
2.1.4 - Field names containing PHP-style brackets (e.g. wm_loc_coordinates[0][latlong]) and case-sensitive characters are now preserved verbatim rather than being mangled by sanitize_title(). before() / after() adornments now render whether show_wrapper(false) or show_wrapper(true) is set — they were previously dropped when the wrapper was off. (Issue #23) *2.1.3 - Adds description pre and post fields within the field wrapper.
2.1.2 - Fixed label/input accessibility, wrapper class duplication and unnecessary list attribute rendering.
2.1.1 - Added Custom_Field element for rendering arbitrary HTML with full field treatment (wrapper, label, notifications, configurable kses filtering)