Alejandro 924 Posted January 18 Share Posted January 18 There are several inquiries hooks that can be used together to add extra fields to the form, validate them, and then include their content in the emails. Below you can find sample code that includes several different field types. This isn't a tutorial on using hooks. If you need help getting started refer to the Hooks developer documentation <?php defined('MVC_FRAMEWORK') or die; Clickfwd\Hook\Action::add('inquiry_form_top', function($params) { $Form = new FormHelper(); ?> <div class="jrFieldDiv"> <label for="jr-inquiry-phone"> <?php __t("Phone Number");?><span class="jrIconRequired"></span> </label> <?php echo $Form->text('data[Inquiry][phone]',[ 'id'=>'jr-inquiry-phone', 'class'=>'jrText', ]);?> </div> <div class="jrFieldDiv"> <label for="jr-inquiry-checkbox_example"> <?php __t("Checkbox Example");?> <span class="jrIconRequired"></span> </label> <?php echo $Form->checkbox('data[Inquiry][checkbox_example]', [ 'one'=>'One', 'two'=>'Two', 'three'=>'Three' ], [ 'id'=>'jr-inquiry-checkbox_example', 'option_class'=>'jr-option jrFieldOption', ] );?> </div> <div class="jrFieldDiv"> <label for="jr-inquiry-select_example"> <?php __t("Select Example");?>: </label> <?php echo $Form->select('data[Inquiry][select_example]', [ ''=>'Select Option', 'one'=>'One', 'two'=>'Two', 'three'=>'Three' ],$selected = '', [ 'id'=>'jr-inquiry-select_example', 'class'=>'jrSelect', ] );?> </div> <div class="jrFieldDiv"> <label for="jr-inquiry-date_example"> <?php __t("Date Example");?> </label> <?php echo $Form->text('data[Inquiry][date_example]',[ 'id'=>'jr-inquiry-date_example', 'class'=>'jrDate jr-date' ]);?> </div> <?php }); Clickfwd\Hook\Filter::add('inquiry_submit_validation', function($validation, $params) { $required = [ 'phone' => 'Phone Number', 'checkbox_example' => 'Checkbox Example', 'select_example' => 'Select Example', ]; foreach($required as $key => $text) { $found = S2Array::get($params,"data.Inquiry.{$key}"); if ( !$found ) { $validation[] = "{$text} is required"; } } return $validation; }, 10); Clickfwd\Hook\Action::add('inquiry_email_extra_fields', function($extra_fields, $params) { $fieldLabels = [ 'phone' => 'Phone Number', 'checkbox_example' => 'Checkbox Example', 'select_example' => 'Select Example', 'date_example' => 'Date Example' ]; if (empty($extra_fields)) { return; } foreach ($extra_fields as $key => $value): ?> <p><?php echo $fieldLabels[$key]; ?>: <?php echo is_array($value) ? implode(', ',$value) : $value; ?></p> <?php endforeach; }); admin-1501540824 1 Link to post
Alejandro 924 Posted January 24 Author Share Posted January 24 This section is only visible with a valid subscription. If you have a valid subscription, please login. Link to post
Recommended Posts