/**
 * Handle field stuff
 */
function bum_manage_fields()
{
    $action = isset($_POST['action']) ? $_POST['action'] : $_GET['action'];
    switch ($action) {
        case 'add_edit':
            global $wp_roles, $wp_user_fields;
            if (isset($_POST['fbJson'])) {
                //the fields are seperated by '&frmb'
                $form_fields = array();
                $fields = explode('&frmb', $_POST['fbJson']);
                foreach ($fields as $field) {
                    if ($field != '') {
                        //get info
                        list($the_key, $the_value) = explode('=', $field);
                        preg_match_all('/\\[(.+?)]/', $the_key, $keys);
                        $keys = $keys[1];
                        //checkboxes show up as 'undefined' if unchecked or 'checked', should be saved as bool
                        $the_value = $the_value == 'undefined' ? 'false' : urldecode($the_value);
                        $the_value = $the_value == 'checked' ? 'true' : $the_value;
                        //this is to deal with different depths of values
                        if (count($keys) == 2) {
                            $form_fields[$keys[0]][$keys[1]] = $the_value;
                        } elseif (count($keys) == 3) {
                            $form_fields[$keys[0]][$keys[1]][$keys[2]] = $the_value;
                        } elseif (count($keys) == 4) {
                            $form_fields[$keys[0]][$keys[1]][$keys[2]][$keys[3]] = $the_value;
                        }
                    }
                }
                //generate the json for this form
                $form = new Formbuilder($form_fields);
                $vals = $form->store();
                $json = $form->generate_json();
                $hash = $vals['form_hash'];
                //update or insert the json into hidden taxonomy
                $term = get_term_by('slug', sanitize_title($_GET['ptab']), BUM_HIDDEN_FIELDS);
                if ($term) {
                    wp_update_term($term->term_id, BUM_HIDDEN_FIELDS, array('description' => $json));
                } else {
                    wp_insert_term($_GET['ptab'], BUM_HIDDEN_FIELDS, array('description' => $json));
                }
            }
            break;
    }
    echo bum_get_show_view('bum-manage-fields');
}
示例#2
0
<?php

require 'Formbuilder/Formbuilder.php';
// At this stage, we want to pass in the POST value
// containing the form. In this example we simply
// pass POST directly, but DO NOT use POST without
// proper security in place.
$form_data = isset($_POST['frmb']) ? $_POST['frmb'] : false;
$form = new Formbuilder($form_data);
$for_db = $form->store();
// The store() method returns an array that should be
// used to store the values in the database. This array
// is also what's passed to the class when rendering
// or editing the form.
echo "<pre>";
print_r(unserialize($for_db['form_structure']));
die;
/*
Outputs:
Array
(
   [form_structure] => a:4:{i:0;a:3:{s:8:"cssClass";s:10:"input_text";s:8:"required";s:9:"undefined";s:6:"values";s:4:"Name";}i:1;a:3:{s:8:"cssClass";s:10:"input_text";s:8:"required";s:7:"checked";s:6:"values";s:15:"E-mail Address?";}i:2;a:4:{s:8:"cssClass";s:8:"checkbox";s:8:"required";s:9:"undefined";s:5:"title";s:11:"Choose any:";s:6:"values";a:4:{i:2;a:2:{s:5:"value";s:3:"PHP";s:8:"baseline";s:7:"checked";}i:3;a:2:{s:5:"value";s:6:"jQuery";s:8:"baseline";s:7:"checked";}i:4;a:2:{s:5:"value";s:3:"XML";s:8:"baseline";s:7:"checked";}i:5;a:2:{s:5:"value";s:5:"Aspen";s:8:"baseline";s:9:"undefined";}}}i:3;a:4:{s:8:"cssClass";s:5:"radio";s:8:"required";s:7:"checked";s:5:"title";s:11:"Choose one:";s:6:"values";a:2:{i:2;a:2:{s:5:"value";s:3:"Yes";s:8:"baseline";s:7:"checked";}i:3;a:2:{s:5:"value";s:2:"No";s:8:"baseline";s:9:"undefined";}}}}
   [form_hash] => 360e29fdc91a4a1fa4664b43d914f4b34d4eee6f
)
*/
// Save the two fields above into the database, and provide them
// back to the formbuilder class when rendering/editing.
示例#3
0
 public function test_Store()
 {
     $form = new Formbuilder($this->_form_array);
     $this->assertEquals($this->_container, $form->store());
 }