/** * The default controller * @return void */ public function index() { /** * Load the helper file */ TINA_MVC\include_helper('form'); /** * Create the new form */ $form = new TINA_MVC\form('my_form'); /** * Open a fieldset */ $fset_open = $form->fieldset_open('fset_name_pw', 'Name and password please'); /** * Adds a text field */ $f_name = $form->add_field('your_name', $type = 'TEXT'); $f_name->add_validation(array('required' => NULL)); /** * Adds a password field */ $f_password = $form->add_field('the_password', $type = 'PASSWORD'); /** * Close a fieldset * * This is optional. If you do not close a fieldset, it is closed whenever you open a new one or * when you render the form */ $fset_close = $form->fieldset_close(); /** * add_field() and all field methods return a field object so you can use method chaining */ $f_hidden = $form->add_field('a_hidden_field', 'hidden')->set_value('Hidden field value'); /** * Some sample data for the select type */ $options = array(array('1', 'dog'), array('21', 'cat'), array('1234', 'mouse'), array('3', 'cake'), array('4', 'house'), array('5', 'meh')); /** * Adds the select field */ $f_select = $form->add_field('select_field', 'SELECT')->set_options($options); /** * Adds the radio field using the same options as for the select field above */ $f_radio = $form->add_field('radio_field', 'RADIO')->set_options($options); /** * A checkbox field */ $f_check = $form->add_field('check_field', $type = 'CHECKBOX', $caption = 'This is the checkbox caption'); /** * A textarea field */ $f_textarea = $form->add_field('textarea_field', $type = 'TEXTAREA', $caption = 'This is the textarea caption'); $f_textblock = $form->add_text('textblock_field', 'This is a block of text included in the form using the "textblock" field type.'); /** * A Googlemap location field * * You must enter your API key into app_settings.php */ if (TINA_MVC\get_tina_mvc_setting('google_api_key_v3')) { $f_map = $form->add_field('map_field', 'GOOGLEMAP'); /** * Sets the height and width of the page in CSS units */ $f_map->set_map_height(200); $f_map->set_map_height(400); } else { $f_gmap_note = $form->add_text('gmap_note', 'You must enter your Google API key (v3) into app_settings.php to use the Google Map location field type.'); } /** * A reCaptcha field * * The recaptcha field type requires your API keys to be set in app_settings.php * * @see http://www.reCaptcha.net */ if (TINA_MVC\get_tina_mvc_setting('recaptcha_pub_key') and TINA_MVC\get_tina_mvc_setting('recaptcha_pri_key')) { $f_recaptcha = $form->add_field('recaptcha_field', $type = 'RECAPTCHA', $caption = 'Are you human?'); } else { $f_recaptcha_note = $form->add_text('recaptcha_note', 'You must enter your reCaptcha API keys into app_settings.php to use the reCaptcha field type.'); } /** * A file upload field */ $f_file_upload = $form->add_field('a_file_upload', 'file'); /** * A second file upload field */ $f_second_file_upload = $form->add_field('a_second_file_upload', 'file'); /** * A submit button */ $f_submit = $form->add_field('submit_field', $type = 'SUBMIT', $caption = 'This is the submit caption'); /** * A reset button */ $f_reset = $form->add_field('reset_field', $type = 'RESET', $caption = 'This is the reset caption'); /** * Some data to pre-load into the form. * * This could come from a database query for example. */ $data = array('name' => 'Joe Bloggs', 'textarea_field' => "Some multiline\r\ntext", 'radio_field' => 3); /** * Loads the data into the form, overriding any default values previously set * * You would use this function to load a recordset from (for example a database query) into * the form. First, any keys in the $data array will match field names. After this any 'db_field' * values matching keys in $data have their values set too. */ $form->load_data($data); /** * Returns an array of posted data, FALSE if the form has not been posted. */ if ($posted_data = $form->get_posted_data()) { $content = "Posted Data<br />"; $content .= "<pre>" . print_r($posted_data, TRUE) . "</pre>"; /** * Generally you process your form here and finish off with a wp_redirect() and exit() */ // wp_redirect( 'wherever' ); // exit(); } else { /** * Returns the HTML required to disply the form */ $content = $form->render(); } /** * Assign as template data */ $this->add_var('view_html', $content); /** * Set the post (page) title and contents. */ $this->set_post_title('Tina MVC New Form Helper Example'); $this->set_post_content($this->load_view('test_form')); }
/** * Displays the widget on the screen. * * @param array $args Wordpress widget arguments * @param array $instance Arguments from the Tina MVC Widget */ function widget($args, $instance) { // Our variables from the widget settings are in $instance $controller = $instance['controller']; $role_to_view = TINA_MVC\get_tina_mvc_setting('default_role_to_view'); if (!$instance['no_role_to_view']) { // we have a non FALSE default $role_to_view = TINA_MVC\merge_permissions($role_to_view, $instance['role_to_view']); } $capability_to_view = TINA_MVC\get_tina_mvc_setting('default_capability_to_view'); if ($instance['capability_to_view']) { $capability_to_view = TINA_MVC\merge_permissions($capability_to_view, $instance['capability_to_view']); } $APP = new TINA_MVC\tina_mvc_page_class($controller, $role_to_view, $capability_to_view, $called_from = 'WIDGET'); // content is empty is permissions checks fail $content = $APP->get_post_content(); if ($content) { // Before widget (defined by themes) echo $args['before_widget']; // Display the widget title if one was input (before and after defined by themes) if (!($tina_mvc_title = $APP->get_post_title())) { $tina_mvc_title = $instance['title']; } $tina_mvc_title = apply_filters('widget_title', $tina_mvc_title); echo $args['before_title'] . $tina_mvc_title . $args['after_title']; echo $content; // After widget (defined by themes) echo $args['after_widget']; } }
/** * Trashes any pages set up as front end page controllers and removes the Tina MVC options * * @package Tina-MVC * @subpackage Core */ function plugin_remove() { $pages_done = array(); // each page is listed twice $tina_pages = \TINA_MVC\get_tina_mvc_setting('tina_mvc_pages'); foreach ($tina_pages as $p) { if (!in_array($p['page_id'], $pages_done)) { if ($page = get_page($p['page_id'])) { $page = array('ID' => $p['page_id'], 'post_status' => 'trash'); $_ok = wp_update_post($page); } $pages_done[] = $p['page_id']; } } // the cron event... if (wp_next_scheduled('tina_mvc_cron_hook')) { wp_clear_scheduled_hook('tina_mvc_cron_hook'); } delete_option('tina_mvc_settings'); delete_option('tina_mvc_plugin_active'); return TRUE; }
<li><a href="?page=tina_mvc_code_hooks">Code & Cron Hooks</a></li> <li><a href="?page=tina_mvc_file_locations">File Locations</a></li> <li><a href="?page=tina_mvc_widgets_shortcodes">Widgets, Shortcodes, call_controller()</a></li> <li><a href="?page=tina_mvc_custom_login">Custom Login Functionality</a></li> <li><a href="?page=tina_mvc_helper_functions">Helper Functions</a></li> <li><a href="?page=tina_mvc_form_helper_intro">Form Helper - Introduction</a></li> <li><a href="?page=tina_mvc_form_helper_advanced">Form Helper - Advanced Use</a></li> <li><a href="?page=tina_mvc_form_helper_fields_and_validation">Form Helper - Fields and Validation</a></li> <li><a href="?page=tina_mvc_table_pagination_helpers">Table and Pagination Helpers</a></li> <li><a href="?page=tina_mvc_todo_list">Todo List</a></li> </ol> <h3>Current Tina MVC pages</h3> <?php foreach (TINA_MVC\get_tina_mvc_setting('tina_mvc_pages') as $n => $p) { if (is_int($n)) { foreach ($p as $key => $val) { ?> <strong><?php echo $key; ?> :</strong> <?php echo $val; ?> <br /> <?php } ?> <br /> <?php