function buildDestacadosForm($xmlArray) { //krumo($xmlArray); $baseNode = $xmlArray['Destacados']['Destacado']; //krumo(count($baseNode)); $form = new PhpFormBuilder(); $form->set_att('enctype', 'multipart/form-data'); $form->set_att('method', 'post'); $form->set_att('id', 'cr_xml_edit'); $count = 1; foreach ($baseNode as $int => $value) { //krumo($value); $idNodo = $value['@attributes']['id']; $idarr = array_combine(range(1, count($baseNode)), range(1, count($baseNode))); // $form->add_input('<div class="form-group nodoxml">', array('type' => 'html'), "form-group" . $count); $form->add_input('numerocampos', array('type' => 'hidden', 'value' => count($baseNode))); $form->add_input('ID', array('class' => array("form-control id"), 'type' => 'select', 'options' => $idarr, 'selected' => $idNodo), 'id_' . $count); $form->add_input('Título', array('class' => array("form-control titulo"), 'type' => 'textfield', 'value' => $value['Titulo']), 'Titulo_' . $count); $form->add_input('Texto', array('class' => array("form-control texto"), 'type' => 'textarea', 'value' => htmlspecialchars_decode($value['Texto'])), 'Texto_' . $count); $form->add_input('Enlace', array('class' => array("form-control enlace"), 'type' => 'textfield', 'value' => $value['Enlace']), 'Enlace_' . $count); $form->add_input('TextoEnlace', array('label' => "Posibles imágenes para botón - TextoEnlace", 'class' => array("form-control textoenlace"), 'type' => 'textfield', 'value' => $value['TextoEnlace']), 'TextoEnlace_' . $count); $form->add_input('Imagen', array('label' => "Imagen destacado", 'class' => array("form-control imagen"), 'type' => 'textfield', 'value' => $value['Imagen']), 'Imagen_' . $count); $form->add_input('</div>', array('type' => 'html'), "form-group-close" . $count); $count++; } $out = $form->build_form(false); return $out; }
function buildTelevisionsForm($xmlArray) { //krumo($xmlArray); $baseNode = $xmlArray['Televisions']['Television']; //krumo(count($baseNode)); $form = new PhpFormBuilder(); $form->set_att('enctype', 'multipart/form-data'); $form->set_att('method', 'post'); $form->set_att('id', 'cr_xml_edit'); $count = 1; foreach ($baseNode as $int => $value) { //krumo($value); $idNodo = $value['@attributes']['id']; $idarr = array_combine(range(1, count($baseNode)), range(1, count($baseNode))); // $form->add_input('<div class="form-group nodoxml">', array('type' => 'html'), "form-group" . $count); $form->add_input('numerocampos', array('type' => 'hidden', 'value' => count($baseNode))); $form->add_input('Elid', array('wrap_class' => array('form_field_wrap elid'), 'label' => "El id?", 'class' => array("form-control elid"), 'type' => 'hidden', 'value' => $value['Elid'], 'name' => 'Elid[]'), 'Elid_' . $count); $form->add_input('ID', array('wrap_class' => array('form_field_wrap id inline'), 'class' => array("form-control id"), 'type' => 'select', 'options' => $idarr, 'selected' => $idNodo, 'name' => 'id[]'), 'id_' . $count); $form->add_input('Título', array('wrap_class' => array('form_field_wrap titulo'), 'class' => array("form-control titulo"), 'type' => 'textfield', 'value' => $value['Titulo'], 'name' => 'Titulo[]'), 'Titulo_' . $count); $form->add_input('Texto', array('wrap_class' => array('form_field_wrap texto'), 'class' => array("form-control texto"), 'type' => 'textfield', 'value' => htmlspecialchars_decode($value['Texto']), 'name' => 'Texto[]'), 'Texto_' . $count); $form->add_input('Enlace', array('wrap_class' => array('form_field_wrap enlace'), 'class' => array("form-control enlace"), 'type' => 'textfield', 'value' => $value['Enlace'], 'name' => 'Enlace[]'), 'Enlace_' . $count); // $_SESSION['workfolder $form->add_input('Fecha', array('wrap_class' => array('form_field_wrap fecha inline'), 'label' => "Fecha <a href='#' class='fechahoy' style='font-size:0.6em'> > Hoy</a>", 'class' => array("form-control fecha"), 'type' => 'textfield', 'value' => $value['Fecha'], 'name' => 'Fecha[]'), 'Fecha_' . $count); $form->add_input('Imagen', array('wrap_class' => array('form_field_wrap'), 'label' => "Imagen Television", 'class' => array("form-control imagen"), 'type' => 'textfield', 'value' => $value['Imagen'], 'name' => 'Imagen[]'), 'Imagen_' . $count); $form->add_input('</div>', array('type' => 'html'), "form-group-close" . $count); $count++; } $out = $form->build_form(false); return $out; }
/** * Builds the widget admin fields * * @param $fields * @param $instance */ function allonsy_display_widget_form($fields, $instance) { if (!class_exists('PhpFormBuilder')) { require_once ALLONSY_THEME_ROOT . '/inc/classes/PhpFormBuilder.php'; } $widget_form = new PhpFormBuilder(); $widget_form->set_att('add_honeypot', FALSE); $widget_form->set_att('form_element', FALSE); $widget_form->set_att('add_submit', FALSE); $widget_form->set_att('markup', 'html'); foreach ($fields as $field) { $input_args = array('type' => $field['type'], 'name' => $field['field_name'], 'class' => array('widefat'), 'wrap_tag' => '', 'before_html' => '<p class="widget-field field_type_' . $field['type'] . '">', 'after_html' => '</p>'); if (!empty($field['description'])) { $input_args['after_html'] = '<span class="description">' . $field['description'] . '</span>' . $input_args['after_html']; } $field['default'] = isset($field['default']) ? $field['default'] : ''; switch ($field['type']) { case 'text': case 'email': case 'url': case 'number': case 'password': case 'textarea': $input_args['value'] = isset($instance[$field['id']]) ? $instance[$field['id']] : $field['default']; break; case 'checkbox': $input_args['value'] = 1; $input_args['checked'] = isset($instance[$field['id']]) ? (bool) $instance[$field['id']] : (bool) $field['default']; $input_args['class'] = array('checkbox'); break; case 'select': $input_args['type'] = 'select'; $input_args['selected'] = isset($instance[$field['id']]) ? $instance[$field['id']] : $field['default']; if (is_array($field['options'])) { $input_args['options'] = $field['options']; } else { if (function_exists($field['options'])) { $input_args['options'] = $field['options'](); } } break; case 'title': $input_args['before_html'] = sprintf('<div class="widget-field-header field-type-%s" id="widget-%s">', $field['type'], $field['id']); $input_args['after_html'] = '</div>'; unset($input_args['class']); break; } $widget_form->add_input($field['label'], $input_args, esc_attr($field['field_id'])); } $widget_form->build_form(); }
function pirate_forms_display_form($atts, $content = NULL) { /* thank you message */ $pirate_forms_thankyou_message = ''; if (isset($_GET['pcf']) && $_GET['pcf'] == 1) { $pirate_forms_thankyou_message .= ' <div class="pirate_forms_thankyou_wrap"> <p>' . sanitize_text_field(pirate_forms_get_key('pirateformsopt_label_submit')) . '</p> </div>'; } /*********************************/ /********** FormBuilder **********/ /*********************************/ if (!class_exists('PhpFormBuilder')) { require_once dirname(__FILE__) . '/inc/PhpFormBuilder.php'; } $pirate_form = new PhpFormBuilder(); $pirate_form->set_att('id', 'pirate_forms_' . (get_the_id() ? get_the_id() : 1)); $pirate_form->set_att('class', array('pirate_forms')); $pirate_form->set_att('add_nonce', get_bloginfo('admin_email')); $pirate_forms_options = get_option('pirate_forms_settings_array'); if (!empty($pirate_forms_options)) { /* Count the number of requested fields from Name, Email and Subject to add a certain class col-12, col-6 or col-4 */ $pirate_forms_required_fields = 0; if (!empty($pirate_forms_options['pirateformsopt_name_field']) && !empty($pirate_forms_options['pirateformsopt_label_name'])) { $pirateformsopt_name_field = $pirate_forms_options['pirateformsopt_name_field']; $pirateformsopt_name_label = $pirate_forms_options['pirateformsopt_label_name']; if (!empty($pirateformsopt_name_field) && !empty($pirateformsopt_name_label) && $pirateformsopt_name_field != '') { $pirate_forms_required_fields++; } } if (!empty($pirate_forms_options['pirateformsopt_email_field']) && !empty($pirate_forms_options['pirateformsopt_label_email'])) { $pirateformsopt_email_field = $pirate_forms_options['pirateformsopt_email_field']; $pirateformsopt_email_label = $pirate_forms_options['pirateformsopt_label_email']; if (!empty($pirateformsopt_email_field) && !empty($pirateformsopt_email_label) && $pirateformsopt_email_field != '') { $pirate_forms_required_fields++; } } if (!empty($pirate_forms_options['pirateformsopt_subject_field']) && !empty($pirate_forms_options['pirateformsopt_label_subject'])) { $pirateformsopt_subject_field = $pirate_forms_options['pirateformsopt_subject_field']; $pirateformsopt_subject_label = $pirate_forms_options['pirateformsopt_label_subject']; if (!empty($pirateformsopt_subject_field) && !empty($pirateformsopt_subject_label) && $pirateformsopt_subject_field != '') { $pirate_forms_required_fields++; } } $pirate_forms_layout_input = ''; switch ($pirate_forms_required_fields) { case 1: $pirate_forms_layout_input = 'col-lg-12 col-sm-12'; break; case 2: $pirate_forms_layout_input = 'col-lg-6 col-sm-6'; break; case 3: $pirate_forms_layout_input = 'col-lg-4 col-sm-4'; break; default: $pirate_forms_layout_input = 'col-lg-4 col-sm-4'; } /******************************/ /******** Name field *********/ /******************************/ if (!empty($pirateformsopt_name_field) && !empty($pirateformsopt_name_label)) { $required = $pirateformsopt_name_field === 'req' ? TRUE : FALSE; $wrap_classes = array('form_field_wrap', 'contact_name_wrap ' . $pirate_forms_layout_input); // If this field was submitted with invalid data if (isset($_SESSION['pirate_forms_contact_errors']['contact-name'])) { $wrap_classes[] = 'error'; } $pirate_form->add_input('', array('placeholder' => stripslashes(sanitize_text_field($pirateformsopt_name_label)), 'required' => $required, 'wrap_class' => $wrap_classes), 'pirate-forms-contact-name'); } /********************************/ /******** Email field **********/ /********************************/ if (!empty($pirateformsopt_email_field) && !empty($pirateformsopt_email_label)) { $required = $pirateformsopt_email_field === 'req' ? TRUE : FALSE; $wrap_classes = array('form_field_wrap', 'contact_email_wrap ' . $pirate_forms_layout_input); // If this field was submitted with invalid data if (isset($_SESSION['pirate_forms_contact_errors']['contact-email'])) { $wrap_classes[] = 'error'; } $pirate_form->add_input('', array('placeholder' => stripslashes(sanitize_text_field($pirateformsopt_email_label)), 'required' => $required, 'type' => 'email', 'wrap_class' => $wrap_classes), 'pirate-forms-contact-email'); } /********************************/ /******** Subject field ********/ /********************************/ if (!empty($pirateformsopt_subject_field) && !empty($pirateformsopt_subject_label)) { $required = $pirateformsopt_subject_field === 'req' ? TRUE : FALSE; $wrap_classes = array('form_field_wrap', 'contact_subject_wrap' . $pirate_forms_layout_input); // If this field was submitted with invalid data if (isset($_SESSION['pirate_forms_contact_errors']['contact-subject'])) { $wrap_classes[] = 'error'; } $pirate_form->add_input('', array('placeholder' => stripslashes(sanitize_text_field($pirateformsopt_subject_label)), 'required' => $required, 'wrap_class' => $wrap_classes), 'pirate-forms-contact-subject'); } /********************************/ /******** Message field ********/ /********************************/ if (!empty($pirate_forms_options['pirateformsopt_message_field']) && !empty($pirate_forms_options['pirateformsopt_label_message'])) { $pirateformsopt_message_field = $pirate_forms_options['pirateformsopt_message_field']; $pirateformsopt_message_label = $pirate_forms_options['pirateformsopt_label_message']; if (!empty($pirateformsopt_message_field) && !empty($pirateformsopt_message_label)) { $required = $pirateformsopt_message_field === 'req' ? TRUE : FALSE; $wrap_classes = array('form_field_wrap', 'contact_message_wrap col-lg-12 col-sm-12'); // If this field was submitted with invalid data if (isset($_SESSION['pirate_forms_contact_errors']['contact-message'])) { $wrap_classes[] = 'error'; } $pirate_form->add_input('', array('placeholder' => stripslashes(sanitize_text_field($pirateformsopt_message_label)), 'required' => $required, 'wrap_class' => $wrap_classes, 'type' => 'textarea'), 'pirate-forms-contact-message'); } } /********************************/ /******** Submit button ********/ /********************************/ if (!empty($pirate_forms_options['pirateformsopt_label_submit_btn'])) { $pirateformsopt_label_submit_btn = $pirate_forms_options['pirateformsopt_label_submit_btn']; if (!empty($pirateformsopt_label_submit_btn)) { $wrap_classes = array(); $pirate_form->add_input('', array('value' => stripslashes(sanitize_text_field($pirateformsopt_label_submit_btn)), 'wrap_class' => $wrap_classes, 'type' => 'submit', 'wrap_tag' => '', 'class' => 'pirate-forms-submit-button'), 'pirate-forms-contact-submit'); } } /******************************/ /********* ReCaptcha **********/ /******************************/ if (!empty($pirate_forms_options['pirateformsopt_recaptcha_secretkey']) && !empty($pirate_forms_options['pirateformsopt_recaptcha_sitekey']) && !empty($pirate_forms_options['pirateformsopt_recaptcha_field']) && $pirate_forms_options['pirateformsopt_recaptcha_field'] == 'yes') { $pirateformsopt_recaptcha_sitekey = $pirate_forms_options['pirateformsopt_recaptcha_sitekey']; $pirateformsopt_recaptcha_secretkey = $pirate_forms_options['pirateformsopt_recaptcha_secretkey']; $pirate_form->add_input('', array('value' => $pirateformsopt_recaptcha_sitekey, 'type' => 'captcha'), 'pirate-forms-captcha'); } } /* Referring site or page, if any */ if (!empty($_SERVER['HTTP_REFERER'])) { $pirate_form->add_input(__('Contact Referrer', 'pirate-forms'), array('type' => 'hidden', 'value' => $_SERVER['HTTP_REFERER'])); } /* Referring page, if sent via URL query */ if (!empty($_REQUEST['src']) || !empty($_REQUEST['ref'])) { $pirate_form->add_input(__('Referring page', 'pirate-forms'), array('type' => 'hidden', 'value' => !empty($_REQUEST['src']) ? $_REQUEST['src'] : $_REQUEST['ref'])); } /* Are there any submission errors? */ $errors = ''; if (!empty($_SESSION['pirate_forms_contact_errors'])) { $errors = pirate_forms_display_errors($_SESSION['pirate_forms_contact_errors']); unset($_SESSION['pirate_forms_contact_errors']); } /* Display the form */ return $pirate_forms_thankyou_message . ' <div class="pirate_forms_wrap"> ' . $errors . ' ' . $pirate_form->build_form(FALSE) . ' </div>'; }
function proper_contact_form($atts, $content = NULL) { // Looking for a submitted form if not redirect if (isset($_GET['pcf']) && $_GET['pcf'] == 1) { return ' <div class="proper_contact_thankyou_wrap"> <h2>' . sanitize_text_field(proper_contact_get_key('propercfp_label_submit')) . '</h2> </div>'; } // FormBuilder // https://github.com/joshcanhelp/php-form-builder if (!class_exists('PhpFormBuilder')) { require_once dirname(__FILE__) . '/inc/PhpFormBuilder.php'; } $form = new PhpFormBuilder(); // TODO: make a better ID system $form->set_att('id', 'proper_contact_form_' . (get_the_id() ? get_the_id() : 1)); $form->set_att('class', array('proper_contact_form')); $form->set_att('add_nonce', get_bloginfo('admin_email')); if (!proper_contact_get_key('propercfp_html5_no_validate')) { $form->set_att('novalidate', TRUE); } // Add name field if selected on the settings page $propercfp_name_field = proper_contact_get_key('propercfp_name_field'); if ($propercfp_name_field) { $required = $propercfp_name_field === 'req' ? TRUE : FALSE; $wrap_classes = array('form_field_wrap', 'contact_name_wrap'); // If this field was submitted with invalid data if (isset($_SESSION['cfp_contact_errors']['contact-name'])) { $wrap_classes[] = 'error'; } // Build the input with the correct label, options, and name $form->add_input(stripslashes(sanitize_text_field(proper_contact_get_key('propercfp_label_name'))), array('required' => $required, 'wrap_class' => $wrap_classes), 'contact-name'); } // Add email field if selected on the settings page $propercfp_email_field = proper_contact_get_key('propercfp_email_field'); if ($propercfp_email_field) { $required = $propercfp_email_field === 'req' ? TRUE : FALSE; $wrap_classes = array('form_field_wrap', 'contact_email_wrap'); // If this field was submitted with invalid data if (isset($_SESSION['cfp_contact_errors']['contact-email'])) { $wrap_classes[] = 'error'; } // Build the input with the correct label, options, and name $form->add_input(stripslashes(sanitize_text_field(proper_contact_get_key('propercfp_label_email'))), array('required' => $required, 'type' => 'email', 'wrap_class' => $wrap_classes), 'contact-email'); } // Add phone field if selected on the settings page $propercfp_phone_field = proper_contact_get_key('propercfp_phone_field'); if ($propercfp_phone_field) { $required = $propercfp_phone_field === 'req' ? TRUE : FALSE; $wrap_classes = array('form_field_wrap', 'contact_phone_wrap'); // If this field was submitted with invalid data if (isset($_SESSION['cfp_contact_errors']['contact-phone'])) { $wrap_classes[] = 'error'; } // Build the input with the correct label, options, and name $form->add_input(stripslashes(sanitize_text_field(proper_contact_get_key('propercfp_label_phone'))), array('required' => $required, 'wrap_class' => $wrap_classes), 'contact-phone'); } // Add reasons drop-down if any have been entered $options = proper_get_textarea_opts(trim(proper_contact_get_key('propercfp_reason'))); if (!empty($options)) { // Prepare the options array $options = array_map('trim', $options); $options = array_map('sanitize_text_field', $options); array_unshift($options, 'Select one...'); // Build the select with the correct label, options, and name $form->add_input(stripslashes(sanitize_text_field(proper_contact_get_key('propercfp_label_reason'))), array('type' => 'select', 'wrap_class' => array('form_field_wrap', 'contact_reasons_wrap'), 'options' => $options), 'contact-reasons'); } do_action('pcf_field_above_comment', $form); // Comment field, required to be displayed $wrap_classes = array('form_field_wrap', 'question_or_comment_wrap'); if (isset($_SESSION['cfp_contact_errors']['question-or-comment'])) { $wrap_classes[] = 'error'; } $form->add_input(stripslashes(proper_contact_get_key('propercfp_label_comment')), array('required' => TRUE, 'type' => 'textarea', 'wrap_class' => $wrap_classes), 'question-or-comment'); do_action('pcf_field_below_comment', $form); // Add a math CAPTCHA, if desired if (proper_contact_get_key('propercfp_captcha_field')) { $wrap_classes = array('form_field_wrap', 'math_captcha_wrap'); // If this field was submitted with invalid data if (isset($_SESSION['cfp_contact_errors']['math-captcha'])) { $wrap_classes[] = 'error'; } $num_1 = mt_rand(1, 10); $num_2 = mt_rand(1, 10); $sum = $num_1 + $num_2; // Build the input with the correct label, options, and name $form->add_input(stripslashes(sanitize_text_field(proper_contact_get_key('propercfp_label_math'))) . " {$num_1} + {$num_2}", array('required' => TRUE, 'wrap_class' => $wrap_classes, 'request_populate' => false), 'math-captcha'); $form->add_input('Math CAPTCHA sum', array('type' => 'hidden', 'value' => $sum, 'request_populate' => false), 'math-captcha-sum'); } do_action('pcf_field_above_submit', $form); // Submit button $submit_btn_text = stripslashes(sanitize_text_field(proper_contact_get_key('propercfp_label_submit_btn'))); $form->add_input($submit_btn_text, array('type' => 'submit', 'wrap_class' => array('form_field_wrap', 'submit_wrap'), 'value' => $submit_btn_text), 'submit'); // Referring site or page, if any if (!empty($_SERVER['HTTP_REFERER'])) { $form->add_input('Contact Referrer', array('type' => 'hidden', 'value' => $_SERVER['HTTP_REFERER'])); } // Referring page, if sent via URL query if (!empty($_REQUEST['src']) || !empty($_REQUEST['ref'])) { $form->add_input('Referring page', array('type' => 'hidden', 'value' => !empty($_REQUEST['src']) ? $_REQUEST['src'] : $_REQUEST['ref'])); } // Are there any submission errors? $errors = ''; if (!empty($_SESSION['cfp_contact_errors'])) { $errors = proper_display_errors($_SESSION['cfp_contact_errors']); unset($_SESSION['cfp_contact_errors']); } // Display that beautiful form! return ' <div class="proper_contact_form_wrap"> ' . $errors . ' ' . $form->build_form(FALSE) . ' </div>'; }
<body> <?php require_once 'PhpFormBuilder.php'; /* Create a new instance Pass in a URL to set the action */ $form = new PhpFormBuilder(); /* Form attributes are modified with the set_att function. First argument is the setting Second argument is the value */ $form->set_att('method', 'post'); $form->set_att('enctype', 'multipart/form-data'); $form->set_att('markup', 'html'); $form->set_att('class', 'class_1'); $form->set_att('class', 'class_2'); $form->set_att('id', 'a_contact_form'); $form->set_att('novalidate', true); $form->set_att('add_honeypot', true); $form->set_att('add_nonce', 'a_contact_form'); $form->set_att('form_element', true); $form->set_att('add_submit', true); /* Uss add_input to create form fields First argument is the name Second argument is an array of arguments for the field Third argument is an alternative name field, if needed
First argument is the setting Second argument is the value */ /* * $form->set_att('method', 'post'); * $form->set_att('enctype', 'a_contact_form'); * $form->set_att('markup', 'html'); * $form->set_att('class', 'class_1'); * $form->set_att('class', 'class_2'); * $form->set_att('id', 'a_contact_form'); * $form->set_att('novalidate', true); * $form->set_att('add_honeypot', false); * $form->set_att('add_nonce', 'a_contact_form'); * $form->set_att('form_element', false); */ $form->set_att('enctype', 'multipart/form-data'); $form->set_att('method', 'post'); /* Uss add_input to create form fields First argument is the name Second argument is an array of arguments for the field Third argument is an alternative name field, if needed */ $form->add_input('Name', array(), 'contact_name'); $form->add_input('Email', array('type' => 'email'), 'contact_email'); $form->add_input('Filez', array('type' => 'file'), 'filez_here'); $form->add_input('Reason for contacting', array('type' => 'checkbox', 'options' => array('say_hi' => 'Just saying hi!', 'complain' => 'I have a bone to pick', 'offer_gift' => 'I\'d like to give you something neat'))); $form->add_input('Bad Headline', array('type' => 'radio', 'options' => array('say_hi_2' => 'Just saying hi! 2', 'complain_2' => 'I have a bone to pick 2', 'offer_gift_2' => 'I\'d like to give you something neat 2'))); $form->add_input('Reason for contact', array('type' => 'select', 'options' => array('' => 'Select...', 'say_hi' => 'Just saying hi!', 'complain' => 'I have a bone to pick', 'offer_gift' => 'I\'d like to give you something neat'))); $form->add_input('Question or comment', array('required' => true, 'type' => 'textarea', 'value' => 'Type away!')); $form->add_inputs(array(array('Field 1'), array('Field 2'), array('Field 3')));