| | |
| | | { |
| | | $id = $options['form-id'] ?? $endpoint; |
| | | $classes = isset($options['classes']) ? ' class="' . implode(' ', $options['classes']) . '"' : ''; |
| | | $formID = isset($options['showFormID']) && $options['showFormID']!== false; |
| | | |
| | | $output = '<form id="' . esc_attr($endpoint) . '"' . $classes . ' data-save="' . esc_attr($endpoint) . '" data-form-id="' . esc_attr($id) . '">'; |
| | | $output = sprintf( |
| | | '<form id="%s"%s data-save="%s"%s>', |
| | | esc_attr($endpoint), |
| | | $classes, |
| | | esc_attr($endpoint), |
| | | $formID ? ' data-form-id="'.esc_attr($id).'"' : '', |
| | | ); |
| | | |
| | | if (!empty($options['heading'])) { |
| | | $output .= '<h2>' . esc_html($options['heading']) . '</h2>'; |
| | |
| | | $output .= '<p>' . esc_html($d) . '</p>'; |
| | | } |
| | | } |
| | | error_log('[Form]::renderFormFrom getting fields: '.print_r($fields, true)); |
| | | $allFields = $meta->getAll($fields); |
| | | error_log('[Form]::renderFormFrom field values: '.print_r($allFields, true)); |
| | | foreach ($allFields as $name => $value) { |
| | | $config = $meta->config($name); |
| | | $output .= static::render($name, $value, $config); |
| | |
| | | $checked = in_array($optValue, $values) ? ' checked' : ''; |
| | | $checkboxes .= sprintf( |
| | | ' |
| | | <input type="checkbox" name="%s[]" id="%s-%s" value="%s"%s /> |
| | | <input type="checkbox" name="%s" id="%s-%s" value="%s"%s/> |
| | | <label class="checkbox-option" for="%s-%s"> |
| | | <span>%s</span> |
| | | </label>', |
| | | esc_attr($name), |
| | | esc_attr($name), |
| | | $optValue, |
| | | esc_attr($optValue), |
| | | esc_attr($optValue), |
| | | $checked, |
| | | esc_attr($name), |
| | | $optValue, |
| | | esc_attr($optValue), |
| | | esc_html($optLabel) |
| | | ); |
| | | } |
| | |
| | | |
| | | foreach ($fields as $fieldName => $fieldConfig) { |
| | | $fieldValue = $values[$fieldName] ?? ''; |
| | | $fullName = array_key_exists('wrap', $config) ? $fieldName : "{$name}:{$fieldName}"; |
| | | $fullName = "{$name}|{$fieldName}"; |
| | | $output .= static::render($fullName, $fieldValue, $fieldConfig); |
| | | } |
| | | |