function test_render() { $values = array(); $html = WP_Forms_API::render_form(array('text-input' => array('#type' => 'text')), $values); $this->assertContains('type="text"', $html); $this->assertContains('name="text-input"', $html); }
/** * Renders the settings form * * @since 1.0 */ public static function render_form() { self::form(); self::get(); echo '<form method="post">' . WP_Forms_API::render_form(self::$form, self::$values) . '</form>'; }
/** * Renders a meta box * * @since 1.0 * @uses $wpdb * * @param WP_Post $post The current post object. * @param array $args Any additional arguments as passed by add_meta_box() */ public static function render_meta_box($post, $args = array()) { global $wpdb; $meta_box = array_shift($args); $values = array(); $form = array(); switch ($meta_box) { case 'wp-dfp-slot-config': $ad_slot = wp_dfp_ad_slot($post); $values['wp_dfp_slot_name'] = $post->post_name; $values[WP_DFP::META_OOP] = (int) $ad_slot->meta(WP_DFP::META_OOP); $form = array('wp_dfp_slot_name' => array('#label' => __('Slot Name', 'wp-dfp'), '#type' => 'text', '#description' => __('Enter the name of the slot as found in DFP. Do not include your network ID!', 'wp-dfp')), WP_DFP::META_OOP => array('#label' => __('This is an out-of-page slot.', 'wp-dfp'), '#type' => 'checkbox', '#checked' => 1, '#conditional' => array('element' => '#wp-dfp-sizing-rules', 'action' => 'hide', 'value' => 1))); break; case 'wp-dfp-sizing-rules': $ad_slot = wp_dfp_ad_slot($post); $rules = $ad_slot->meta(WP_DFP::META_SIZING_RULES, array()); $index = 0; foreach ($rules as $container_width => $sizes) { $values[WP_DFP::META_SIZING_RULES][$index]['container_width'] = $container_width; $size_parts = array(); foreach ($sizes as $size) { $size_parts[] = join('x', $size); } $values[WP_DFP::META_SIZING_RULES][$index]['sizes'] = join("\n", $size_parts); $index++; } $form = array('sizing_rules' => array('#label' => '', '#description' => __('Click "Add Rule" below to specify a new sizing rule.', 'wp-dfp'), WP_DFP::META_SIZING_RULES => array('#type' => 'multiple', '#add_link' => __('Add Rule', 'wp-dfp'), '#multiple' => array('container_width' => array('#type' => 'text', '#label' => __('Container Width', 'wp-dfp'), '#description' => __('If the calculated ad container width is >= than this value and is less than the next largest specified ad container width, then the ad sizes defined below will be used for this ad slot.', 'wp-dfp')), 'sizes' => array('#type' => 'textarea', '#label' => __('Ad Sizes', 'wp-dfp'), '#attrs' => array('rows' => 5), '#description' => __('One ad size per line. Example: 950x100 where 950 is the width of the ad and 100 is the height of the ad.', 'wp-dfp')))))); break; case 'submitdiv': $delete_markup = ''; if (current_user_can("delete_post", $post->ID)) { $delete_text = !EMPTY_TRASH_DAYS ? __('Delete Permanently') : __('Move to Trash'); $delete_markup = '<div id="delete-action"><a class="submitdelete deletion" href="' . get_delete_post_link($post->ID) . '">' . $delete_text . '</a></div>'; } $markup = ' <div id="minor-publishing"> <div id="misc-publishing-actions"> <div class="misc-pub-section"> <span class="dashicons dashicons-welcome-add-page"></span><a href="' . self::clone_url($post) . '">' . __('Clone this slot', 'wp-dfp') . '</a> </div> </div> </div> <div id="major-publishing-actions">' . $delete_markup . ' <div id="publishing-action"> <span class="spinner"></span>' . get_submit_button(__('Save Ad Slot', 'wp-dfp'), 'primary button-large', 'publish', false) . ' </div> <div class="clear"></div> </div>'; echo $markup; break; } echo WP_Forms_API::render_form($form, $values); }
<!-- Render the form as a POST on /my/form/handler --> <form method="post" action="/my/form/handler"> <?php $form = array('name' => array('#type' => 'text', '#label' => "Enter your name:", '#placeholder' => "Charlie Brown"), 'zipcode' => array('#type' => 'text', '#label' => "Enter your ZIP code:", '#placeholder' => "90210", '#size' => 5), 'save' => array('#type' => 'submit', '#value' => "Save Information")); echo WP_Forms_API::render_form($form, $input); ?> </form> <!-- Then process the form --> <?php WP_Forms_API::process_form($form, $values); ?> <p> Your name is: <?php echo esc_html($form['name']); ?> </p> <p> Your ZIP is: <?php echo esc_html($form['zipcode']); ?> </p>