function widget($args, $instance)
 {
     extract($args);
     wp_enqueue_script('jquery-forms', THEME_ADMIN_JS_URI . '/jqueryforms.js');
     wp_enqueue_script('jquery-validate', THEME_JS . '/jquery.validate.min.js', array('jquery-forms'));
     require_once THEME_ADMIN . '/interfaces/wonder-forms/formbuilder-front.php';
     $fb = new Formbuilder();
     global $wpdb;
     $table = $wpdb->prefix . 'ultimatum_forms';
     $query = "SELECT * FROM {$table} WHERE `id`='{$instance['form']}'";
     $form = $wpdb->get_row($query, ARRAY_A);
     if ($form) {
         $fields = unserialize($form['fields']);
         foreach ($fields['properties'] as $field => $data) {
             foreach ($data as $key => $value) {
                 if ($key == 'label') {
                     $fields['properties'][$field][$key] = wpml_t('Ultimatum Forms', 'Form-' . $form['name'] . '- Label (' . $value . ')', $value);
                 }
                 if ($key == 'values') {
                     $fields['properties'][$field][$key] = wpml_t('Ultimatum Forms', 'Form-' . $form['name'] . '- Values (' . $data['label'] . ')', $value);
                 }
             }
         }
         $items = $fb->build($fields);
         $html = '';
         // Start the form and put in hidden fields for referral tracking
         if (stripos($form['thank'], 'http')) {
             $html .= '<div class="uforms"><form id="uform_' . $form['id'] . '" method="post" action="' . THEME_AJAX . '/sendmail.php">';
         } else {
             $html .= '<div class="uforms"><form id="uform_' . $form['id'] . '" method="post" action="' . THEME_AJAX . '/sendmail.php" class="ultimate_form">';
         }
         if ($items) {
             foreach ($items as $id => $item) {
                 if ($item['type'] != 'text') {
                     //	$item['label']=wpml_t('Ultimatum Forms', 'Form-'.$form[name].'- Label ('.$item['label'].')', $item['label']);
                     $html .= '<div class="' . $id . ' ' . $item['type'] . '"><label for="' . $item['label'] . '">' . $item['label'] . '</label><br />';
                 }
                 $html .= str_replace($id, $item['label'], $item['html']);
                 if ($item['type'] != 'text') {
                     $html .= '</div>';
                 }
             }
         }
         $html .= '<div class="form-submit"><input type="hidden" name="uformid" value="' . $form["id"] . '" />';
         $html .= '<input type="submit" class="button hover" value="' . $form["button"] . '" /></div>';
         $html .= '</form></div>';
         $html = str_replace('"', "'", $html);
         $html = str_replace('\\n', "", $html);
         echo $before_widget;
         if ($instance["title"]) {
             echo $before_title . $instance["title"] . $after_title;
         }
         echo $html;
         echo $after_widget;
     }
 }
Esempio n. 2
0
 public function previewAction()
 {
     $form_post_array = isset($_POST['frmb']) ? $_POST : false;
     if ($form_post_array != false) {
         K_Loader::load('formbuilder', APP_PATH . '/plugins');
         $form_builder = new Formbuilder($form_post_array);
         $this->putAjax($form_builder->generate_html());
     } else {
         $this->putAjax('ERROR');
     }
 }
Esempio n. 3
0
 public function loadAction()
 {
     $typeClientForm = new Admin_Model_ClientForm();
     $clientFormKey = $this->getParam('key');
     $clientFormData = $typeClientForm->fetchRow(K_Db_Select::create()->where("type_clientform_id={$clientFormKey}"));
     if ($clientFormData) {
         K_Loader::load('formbuilder', APP_PATH . '/plugins');
         $formBuilder = new Formbuilder(unserialize($clientFormData['type_clientform_content']));
         $this->putAjax($formBuilder->render_json());
     } else {
         $this->putAjax('ERROR');
     }
 }
Esempio n. 4
0
function shortcode_form($atts, $content = null, $code)
{
    extract(shortcode_atts(array('id' => ''), $atts));
    wp_enqueue_script('jquery-forms', THEME_ADMIN_JS_URI . '/jqueryforms.js');
    wp_enqueue_script('jquery-validate', THEME_JS . '/jquery.validate.min.js', array('jquery-forms'));
    require_once THEME_ADMIN . '/interfaces/wonder-forms/formbuilder-front.php';
    $fb = new Formbuilder();
    global $wpdb;
    $table = $wpdb->prefix . 'ultimatum_forms';
    $query = "SELECT * FROM {$table} WHERE `id`='{$id}'";
    $form = $wpdb->get_row($query, ARRAY_A);
    if ($form) {
        $fields = unserialize($form['fields']);
        foreach ($fields['properties'] as $field => $data) {
            foreach ($data as $key => $value) {
                if ($key == 'label') {
                    $fields['properties'][$field][$key] = wpml_t('Ultimatum Forms', 'Form-' . $form['name'] . '- Label (' . $value . ')', $value);
                }
                if ($key == 'values') {
                    $fields['properties'][$field][$key] = wpml_t('Ultimatum Forms', 'Form-' . $form['name'] . '- Values (' . $data['label'] . ')', $value);
                }
            }
        }
        $items = $fb->build($fields);
        $html = '';
        if (stripos($form['thank'], 'http')) {
            $html .= '<div class="uforms"><form id="uform_' . $form['id'] . '" method="post" action="' . THEME_AJAX . '/sendmail.php">';
        } else {
            $html .= '<div class="uforms"><form id="uform_' . $form['id'] . '" method="post" action="' . THEME_AJAX . '/sendmail.php" class="ultimate_form">';
        }
        if ($items) {
            foreach ($items as $id => $item) {
                if ($item['type'] != 'text') {
                    $html .= '<div class="' . $id . ' ' . $item['type'] . '"><label for="' . wpml_t('Ultimatum Forms', 'Form-' . $form["name"] . '- Label (' . $item['label'] . ')', $item['label']) . '">' . wpml_t('Ultimatum Forms', 'Form-' . $form["name"] . '- Label (' . $item['label'] . ')', $item['label']) . '</label><br />';
                }
                $html .= str_replace($id, $item["label"], $item['html']);
                if ($item['type'] != 'text') {
                    $html .= '</div>';
                }
            }
        }
        $html .= '<div class="form-submit"><input type="hidden" name="uformid" value="' . $form["id"] . '" />';
        $html .= '<input type="submit" class="button hover" value="' . $form["button"] . '" /></div>';
        $html .= '</form>';
        $html .= '</div>';
        $html = str_replace('"', "'", $html);
        $html = str_replace('\\n', "", $html);
        return $html;
    }
}
<?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.
// The get_encoded_form_array() 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.
$form_data = isset($_POST['frmb']) ? $_POST : false;
$form = new Formbuilder($form_data);
$for_db = $form->get_encoded_form_array();
$for_db_raw = $form->open311_form();
//------------------------------------------------------------------------------
// OR, you could use our database object with some database connection
// information to automatically save everything to the database.
// You could do that like so:
require 'Formbuilder/Formbuilder_pdo.php';
//$form_data = isset($_POST['frmb']) ? $_POST : false;
$form = new Formbuilder_pdo($for_db);
$form->connect();
$form->save_form();
//$form->save_form_open311();
//------------------------------------------------------------------------------
// Here's the example output of get_encoded_form_array()
print_r($for_db_raw);
//Array
//(
//    [form_id] => 1
/**
 * 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');
}
<?php

define('BASEPATH', 'WHATEVER');
//used so dont have to edit CI libraries.
include "lib/form_helper.php";
$fb = new Formbuilder();
$action = isset($_GET['action']) ? $_GET['action'] : null;
switch ($action) {
    case 'properties':
        $fb->properties($_GET);
        break;
    case 'element':
        $fb->element($_GET);
        break;
    default:
        break;
}
/**
 * Filemanager
 */
class Formbuilder
{
    /*
    Build is used to output the forms data as a html form
    $data is an array generated on post from the builder.
    */
    function build($data)
    {
        if (!isset($data['properties'])) {
            return false;
        }
Esempio n. 8
0
<?php

require 'Formbuilder/Formbuilder.php';
// IF you have a db setup, remove the following line. it's for demo only
print_r(json_decode(file_get_contents('php://input'), true));
exit;
// Grab the incoming form JSON
$form = Formbuilder::readFromStream();
/**
 * Save the JSON to a database, identified by $json['form_id']
 * In these examples, we use MongoDB
 */
// Connect to a Mongo DB
$m = new MongoClient();
$forms_collection = $m->formbuilder->forms;
// Insert or update a record
$json = $form->getJSON();
$forms_collection->update(array('form_id' => $json['form_id']), $json, array('upsert' => true, 'fsync' => true));
// anything other than 200 ok will cause the formbuilder UI to show an error
 public static function salvar()
 {
     $objetoFormulario = new Formulario();
     $objetoFormulario->selecionarPorId($_GET['id']);
     $form = new Formbuilder($_POST);
     $html = $form->generate_html(Configuracao::$baseUrl . '../salvar.html');
     $json = json_encode($form->get_encoded_form_array());
     $dom = new DOMDocument('1.0', 'utf-8');
     $dom->loadHTML(mb_convert_encoding($html, 'html-entities', 'utf-8'));
     $formulario = $dom->getElementsByTagName('form')->item(0);
     $ol = $dom->getElementsByTagName('ol')->item(0);
     $inputHidden = $dom->createElement('input');
     $inputHidden->setAttribute('type', 'hidden');
     $inputHidden->setAttribute('name', 'id_evento');
     $inputHidden->setAttribute('value', $objetoFormulario->fkEvento);
     $formulario->insertBefore($inputHidden, $ol);
     //$inputHidden = $dom->createElement('input');
     //$inputHidden->setAttribute('type', 'hidden');
     //$inputHidden->setAttribute('name', 'id_ingresso');
     //$inputHidden->setAttribute('value','$INGRESSO');
     //$formulario->insertBefore($inputHidden, $ol);
     $inputHidden = $dom->createElement('input');
     $inputHidden->setAttribute('type', 'hidden');
     $inputHidden->setAttribute('name', 'id_formulario');
     $inputHidden->setAttribute('value', $_GET['id']);
     $formulario->insertBefore($inputHidden, $ol);
     $inputHidden = $dom->createElement('input');
     $inputHidden->setAttribute('type', 'hidden');
     $inputHidden->setAttribute('name', 'passo_ordem');
     $inputHidden->setAttribute('value', $_GET['passo']);
     $formulario->insertBefore($inputHidden, $ol);
     //$inputHidden = $dom->createElement('input');
     //$inputHidden->setAttribute('type', 'hidden');
     //$inputHidden->setAttribute('name', 'quantidade_ingressos');
     //$inputHidden->setAttribute('value','$QUANTIDADE');
     //$formulario->insertBefore($inputHidden, $ol);
     $html = $formulario->ownerDocument->saveHtml();
     $passo = new Passo();
     $passo = $passo->getByFormularioPasso($_GET['id'], $_GET['passo']);
     $passo->html = $html;
     $passo->estrutura = $json;
     $passo->salvar();
     $resposta = new stdClass();
     $resposta->html = $html;
     echo @json_encode($resposta);
 }
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
	<head>
		<title>jQuery FormBuilder Demo (Submission)</title>
		<meta http-equiv="content-type" content="text/html; charset=utf-8" />
	</head>
	<body>

<?php 
require 'Formbuilder/Formbuilder.php';
// At this stage, we simulate getting an array of the
// form_structure and hash from our database. This is
// how the form data would have been saved using
// the $form->store() method.
include 'fake-form-db-vals.php';
$form = new Formbuilder($fake_db_vals);
$results = $form->process();
print '<pre>';
var_dump($results);
print '</pre>';
?>

	</body>
</html>
<?php

echo Form::open(Formbuilder::getFormAttributes());
?>
    <?php 
echo Formbuilder::openWrapper();
?>
        <?php 
foreach (Formbuilder::getFormFields() as $field) {
    ?>
            <?php 
    echo Formbuilder::openSection();
    ?>
                <?php 
    echo Formbuilder::getField($field);
    ?>
            <?php 
    echo Formbuilder::closeSection();
    ?>
        <?php 
}
?>
        <?php 
echo Form::button('Submit', array('type' => 'submit'));
?>
        <?php 
echo Form::button('Reset', array('type' => 'reset'));
?>
    <?php 
echo Formbuilder::closeWrapper();
echo Form::close();
Esempio n. 12
0
    public static function addField($form, $type, $element, $elementData, $formData)
    {
        switch ($type) {
            case 'text':
                $form->{$type}($element->values->name, !empty($elementData) ? $elementData : (!empty($element->values->default) ? $element->values->default : ''), array('class' => $element->values->class, 'id' => $element->values->id, 'placeholder' => $element->values->placeholder));
                break;
            case 'textarea':
                $form->{$type}($element->values->name, !empty($elementData) ? $elementData : (!empty($element->values->default) ? $element->values->default : ''), array('class' => $element->values->class, 'id' => $element->values->id, 'placeholder' => $element->values->placeholder));
                break;
            case 'wysiwyg':
                $form->textarea($element->values->name, !empty($elementData) ? $elementData : (!empty($element->values->default) ? $element->values->default : ''), array('class' => $element->values->class . ' wysiwyg-redactor', 'id' => $element->values->id));
                echo '
				<script type="text/javascript">
            
                  $(function() {
                 	$(".wysiwyg-redactor").ckeditor({
                   	                allowedContent: true,
   									toolbar: "Standard",
   								   removePlugins : "resize,about,save",
                        		filebrowserBrowseUrl : "/adm/plugins/ckfinder/ckfinder.html",
            						filebrowserImageBrowseUrl : "/adm/plugins/ckfinder/ckfinder.html?Type=Images",
            						filebrowserFlashBrowseUrl : "/adm/plugins/ckfinder/ckfinder.html?Type=Flash",
            						filebrowserUploadUrl : "/adm/plugins/ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Files",
            						filebrowserImageUploadUrl : "/adm/plugins/ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Images",
            						filebrowserFlashUploadUrl : "/adm/plugins/ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Flash",
						
                              editorConfig : function( config )
                                                {
                                                   CKEDITOR.replace( "content_id", {
                                                        allowedContent: true})
                                                   config.protectedSource.push(/<(style)[^>]*>.*<\\/style>/ig);
                                                   return config;
                                                   
                                                }
                   	});
                     
                     
                     
                  });
                  
                 </script>';
                /*
                				$(".wysiwyg-redactor").redactor({
                				        
                				        imageUpload: "/admin/api/uploadImage",
                				        autoformat: true,
                            cleanUp: true,
                					    convertDivs: false,
                            removeClasses: true,
                            removeStyles: true,
                            convertLinks: false,
                            buttons: ["html", "|", "formatting", "|", "bold", "italic" , "deleted","|","norderedlist", "orderedlist", "outdent", "indent", "|","image","video","table", "link", "|","fontcolor", "backcolor", "|","alignleft", "aligncenter", "alignright", "justify", "|","horizontalrule", "fullscreen"] 
                				});
                */
                break;
            case 'formbuilder':
                K_Loader::load('formbuilder', APP_PATH . '/plugins');
                $form_builder = new Formbuilder(unserialize($elementData));
                echo '
				<div id="my-form-builder"></div>
				<input type="hidden" name="' . $element->values->name . '" id="f_' . $element->values->name . '"></div>
				
				<script type="text/javascript">		
					$("#my-form-builder").formbuilder({
						"save_url": false,
						"load_url": false,
						"preview_url": false,
						"saveInDom": true,
						' . (!empty($elementData) ? '"load_source": ' . $form_builder->render_json(false) . ',' : '') . '
						"domElementId": "f_' . $element->values->name . '",
						"useJson" : true 
					});
				</script>
				';
                break;
            case 'file':
                $form->{$type}($element->values->name, array('class' => $element->values->class, 'id' => $element->values->id));
                if (self::$adminka) {
                    echo ' <input type="checkbox" name="' . $element->values->name . '_delete">Удалить файл</input>';
                }
                if ($elementData) {
                    echo '<div>' . (preg_match('/^.*\\.(jpg|png|jpeg|gif|bmp)$/im', $elementData) ? '<br /><img  src="/images/' . $elementData . '?h=120" style="margin-top:5px" /></div>' : '<span class="file_address_text"><a href="/upload/' . htmlentities(urlencode($elementData)) . '">' . $elementData . '</a></span></div>');
                }
                break;
            case 'multifile':
                echo '<div id = ' . $element->values->id . ' data-filename = ' . $element->values->name . ' class = "multifile">';
                $i = 0;
                if ($elementData) {
                    $fileArr = unserialize($elementData);
                    if (count($fileArr)) {
                        foreach ($fileArr as $v) {
                            echo '<div style="margin:15px 0"  id="' . $element->values->id . '_a_' . $i . '">';
                            echo '<input type="text" value="' . $v['t'] . '" style="width:150px;margin-right:5px" name="' . $element->values->name . '_t_' . $i . '" id="' . $element->values->id . '_t_' . $i . '"/>';
                            $form->file($element->values->name . '_f_' . $i, array('class' => $element->values->class, 'id' => $element->values->id . '_f_' . $i));
                            if (self::$adminka) {
                                echo '<br/> <input type="checkbox" name="' . $element->values->name . '_delete_' . $i . '">Удалить файл</input>';
                            }
                            echo '<div>' . (preg_match('/^.*\\.(jpg|png|jpeg|gif|bmp)$/im', $v['f']) ? '<br /><img  src="/images/' . $v['f'] . '?w=150&h=150&zc=C" style="margin-top:5px" /></div><br/>' : '<span class="file_address_text"><a href="/upload/' . htmlentities(urlencode($v['f'])) . '">' . ($v['t'] ? $v['t'] : $v['f']) . '</a></span></div><br/>');
                            $i++;
                            echo '</div>';
                        }
                    }
                }
                if (!$i) {
                    echo '<div style="margin:15px 0"  id="' . $element->values->id . '_a_0">';
                    echo '<input type="text"  style="width:150px;margin-right:5px" name="' . $element->values->name . '_t_0" id="' . $element->values->id . '_t_0"/>';
                    $form->file($element->values->name . '_f_0', array('style' => 'width:220px', 'class' => $element->values->class, 'id' => $element->values->id . '_f_0'));
                    echo '<a data-fileid="' . $element->values->id . '_0' . '" class="file_field_delete" href="javascript:void(0);" title="Убрать лишний"></a>';
                    echo '</div>';
                }
                echo '</div>';
                echo "<script type=\"text/javascript\"> \n                            \$(function(){\n                                 \$('#" . $element->values->id . "').multifile(); \n                            });\n                         </script>";
                break;
            case 'select':
                $listOptions = self::getListOptions($element);
                $listAttr = array('class' => $element->values->class, 'id' => $element->values->id);
                if ($element->multiple == "checked") {
                    $listAttr['multiple'] = 'multiple';
                }
                //  var_dump($element);
                $treeIds = array();
                if ($element->values->method) {
                    $params = json_decode($element->values->method, true);
                    // var_dump($params);
                    // $params = explode(':',$element->values->method);
                    $source = trim($params['node']);
                    $field = 'tree_' . $params['field'];
                    if (strpos($params['field'], 'type') !== false) {
                        $field = str_replace('type_', '', $params['field']);
                    }
                    if (preg_match('/^\\/.*\\/$/', $source)) {
                        //  var_dump($params);
                        $goParams = array_merge($params['go'], array('orderby' => $params['order'][1]));
                        // var_dump($goParams);
                        $nodeChilds = K_TreeQuery::crt($source)->types($params['filter'])->limit($params['limit'])->order($params['order'][0])->go($goParams);
                        //   var_dump($nodeChilds);
                        // var_dump($nodeChilds);
                        //   $start=$nodeChilds[1]['tree_level'];
                        //  var_dump($treeBrach);
                        // str_repeat('&nbsp;&nbsp;',$v['tree_level']).$v['tree_title']
                        $firstNode = true;
                        foreach ($nodeChilds as $v) {
                            if ($firstNode == true) {
                                $startLevel = $v['tree_level'];
                            }
                            $firstNode = false;
                            $title = $v[$field];
                            $treeIds[$title] = $v['tree_id'];
                            // str_repeat('&nbsp;&nbsp;',$v['tree_level']-$start).
                            if ($params['title'] && count($params['title'])) {
                                $optTitle = array();
                                foreach ($params['title'] as $tile) {
                                    $optTitle[] = $v[$tile];
                                }
                                $listOptions[0][$title] = str_repeat('&nbsp;&nbsp;', $v['tree_level'] - $startLevel) . implode(' - ', $optTitle);
                            } else {
                                $listOptions[0][$title] = str_repeat('&nbsp;&nbsp;', $v['tree_level'] - $startLevel) . $v['tree_title'];
                            }
                        }
                        //var_dump( $listOptions[0] );
                    } else {
                        $node = K_Tree::getNode($elementData);
                        $nodesBro = K_Tree::getChilds($node['tree_pid']);
                        foreach ($nodesBro as $v) {
                            $title = $v[$field];
                            $treeIds[$title] = $v['tree_id'];
                            $listOptions[0][$title] = $v['tree_title'];
                        }
                        echo "<script type=\"text/javascript\"> \n                           \$('#" . $source . "').off('.formsel'); \n                           \$('#" . $source . "').on('change.formsel',function(){selectLoad(this,'#{$listAttr['id']}','{$params['0']}','')});\n                           </script>";
                        /*
                                               if(! empty($elementData)){
                              $checkJs="if(v.value=='$elementData'){cheked='selected=\"selected\"}";
                        //  $this->loadSelect[$source]=array('select'=>$listAttr['id'],'field'=>$params['0'],'opt'=>$elementData);
                           
                          echo "selectLoad('#".$source ."','#{$listAttr['id']}','{$params['0']}','$elementData',);";  
                          } 
                        */
                    }
                }
                $form->{$type}($element->values->name . (isset($listAttr['multiple']) && $listAttr['multiple'] ? '[]' : ''), $listOptions[0], !empty($elementData) ? $elementData : $listOptions[0], $listAttr, $treeIds);
                break;
            case 'checkbox':
                $listOptions = self::getListOptions($element);
                $listAttr = array('class' => $element->values->class, 'id' => $element->values->id);
                if (count($listOptions[0]) > 0) {
                    $i = 1;
                    foreach ($listOptions[0] as $key => $value) {
                        echo '<label>';
                        $form->{$type}($element->values->name . (count($listOptions[0]) > 1 ? '[]' : ''), $listOptions[1] == $i || count($listOptions[0]) == 1 && $elementData == 'on' ? true : false, $key, $listAttr);
                        echo $key . ' &nbsp;' . '</label>';
                        $i++;
                    }
                }
                break;
            case 'radio':
                $listOptions = self::getListOptions($element);
                $listAttr = array('class' => $element->values->class, 'id' => $element->values->id);
                if (count($listOptions[0]) > 0) {
                    $i = 1;
                    foreach ($listOptions[0] as $key => $value) {
                        echo '<label>';
                        $form->{$type}($element->values->name . (count($listOptions[0]) > 1 ? '[]' : ''), $listOptions[1] == $i || count($listOptions[0]) == 1 && $elementData == 'on' ? true : false, $key, $listAttr);
                        echo $key . ' &nbsp;' . '</label>';
                        $i++;
                    }
                }
                //  var_dump($listOptions[0]);
                // $form->$type($element->values->name . (''), $listOptions[0], $listOptions[1], $listAttr);
                break;
            case 'submit':
                $form->{$type}($element->values->label, array('class' => $element->values->class, 'id' => $element->values->id));
                break;
            case 'reset':
                $form->{$type}($element->values->label, array('class' => $element->values->class, 'id' => $element->values->id));
                break;
            case 'hidden':
                $form->{$type}($element->values->name, $element->values->value, array('class' => $element->values->class, 'id' => $element->values->id));
                break;
        }
    }
Esempio n. 13
0
<?php

require 'Formbuilder/Formbuilder.php';
// At this stage, we simulate loading JSON from the db.
// Remove these few lines when you have a real DB in place
$form = Formbuilder::readFromFile(dirname(__FILE__) . '/fake-form-db-vals.json');
print $form;
exit;
/**
 * Load the JSON from a database, identified by a form_id
 * In these examples, we use MongoDB
 */
// The form id of the form we need to load
$form_id = 'frmb-1402703162109';
// Connect to a Mongo DB
$m = new MongoClient();
$forms_collection = $m->formbuilder->forms;
// Find the form data
$form = $forms_collection->findOne(array('form_id' => $form_id));
if ($form) {
    print json_encode($form);
}
// anything other than a 200 will prevent loading
Esempio n. 14
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.
// The get_encoded_form_array() 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.
$form_data = isset($_POST['frmb']) ? $_POST : false;
$form = new Formbuilder($form_data);
$for_db = $form->generate_html();
//------------------------------------------------------------------------------
// OR, you could use our database object with some database connection
// information to automatically save everything to the database.
// You could do that like so:
//require('Formbuilder/Formbuilder_pdo.php');
//$form_data = isset($_POST['frmb']) ? $_POST : false;
//$form = new Formbuilder_pdo($form_data);
//$form->connect();
//$form->save_form();
//------------------------------------------------------------------------------
// Here's the example output of get_encoded_form_array()
$dom = new DOMDocument();
$dom->loadHTML($for_db);
$form = $dom->getElementsByTagName('form')->item(0);
$ol = $dom->getElementsByTagName('ol')->item(0);
$inputHidden = $dom->createElement('input');
$inputHidden->setAttribute('type', 'hidden');
Esempio n. 15
0
<?php

require 'Formbuilder/Formbuilder.php';
// At this stage, we simulate getting an array of the
// form_structure and hash from our database. This is
// how the form data would have been saved using
// the $form->store() method.
include 'fake-form-db-vals.php';
$form = new Formbuilder($fake_db_vals);
$form->render_xml();
<!DOCTYPE html>
<html>
	<head>
		<title>jQuery FormBuilder Demo (Output)</title>
		<meta charset="utf-8" />
		<link href="../../../css/jquery.formbuilder.css" media="screen" rel="stylesheet" />
	</head>
	<body>

<?php 
require 'Formbuilder/Formbuilder.php';
// At this stage, we simulate getting an array of the
// form_structure and hash from our database. This is
// how the form data would have been saved using
// the $form->get_encoded_form_array() method.
include 'fake-form-db-vals.php';
$form = new Formbuilder($fake_db_vals);
$form->render_html('example-submit.php');
// OR to load a form saved to the db:
//require('Formbuilder/Formbuilder_pdo.php');
//$form = new Formbuilder_pdo();
//$form->connect();
//$form->render_html( 1, 'example-submit.php' );
?>

	</body>
</html>
Esempio n. 17
0
 public function updateAction()
 {
     $this->disableRender = true;
     $typesTable = new K_Tree_Types_Model();
     $typeId = $this->getParam('id');
     $types = $typesTable->select()->where('`type_id`=' . (int) $typeId)->fetchRow();
     $types = $types->toArray();
     $form = new K_Form();
     $allowedkeys = array('type_desc', 'type_fields');
     $values = array();
     $formData = $form->getData();
     $formPostArray = isset($_POST['type_fields']) ? $_POST['type_fields'] : false;
     parse_str(substr($_POST['type_fields'], 1), $formPostArray);
     if ($formPostArray != false) {
         K_Loader::load('formbuilder', APP_PATH . '/plugins');
         $formBuilder = new Formbuilder($formPostArray);
         $formArray = $formBuilder->get_encoded_form_array();
     } else {
         throw new Exception("Не заданы поля для нового типа!");
     }
     if (!$formData) {
         throw new Exception("Невозможно обработать форму без данных!");
     }
     foreach ($formData as $elementKey => $elementValue) {
         if (in_array($elementKey, $allowedkeys)) {
             if (is_string($elementValue)) {
                 $elementValue = trim($elementValue);
             }
             $values[$elementKey] = $elementValue;
             if ($elementKey == 'type_fields' && json_decode($formArray['form_structure']) == null && !empty($formArray['form_structure'])) {
                 throw new Exception("Поля переданы не в json-формате! " . json_last_error());
             }
         }
     }
     K_Tree_Types::update($types['type_name'], $values['type_desc'], $formArray['form_structure'], $formArray);
     echo 'Тип успешно обновлён!';
 }
Esempio n. 18
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.
// The get_encoded_form_array() 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.
$form_data = isset($_POST['frmb']) ? $_POST : false;
$form = new Formbuilder($form_data);
$for_db = $form->get_encoded_form_array();
//------------------------------------------------------------------------------
// OR, you could use our database object with some database connection
// information to automatically save everything to the database.
// You could do that like so:
//require('Formbuilder/Formbuilder_pdo.php');
//$form_data = isset($_POST['frmb']) ? $_POST : false;
//$form = new Formbuilder_pdo($form_data);
//$form->connect();
//$form->save_form();
//------------------------------------------------------------------------------
// Here's the example output of get_encoded_form_array()
print_r($for_db);
//Array
//(
//    [form_id] => 1
//    [form_structure] => [{"cssClass":"input_text","required":"undefined","values":"First Name"},{"cssClass":"input_text","required":"undefined","values":"Last Name"},{"cssClass":"textarea","required":"undefined","values":"Bio"},{"cssClass":"checkbox","required":"undefined","title":"What's on your pizza?","values":{"2":{"value":"Extra Cheese","baseline":"undefined"},"3":{"value":"Pepperoni","baseline":"undefined"},"4":{"value":"Beef","baseline":"undefined"}}}]
//)
<?php

require 'Formbuilder/Formbuilder.php';
// At this stage, we simulate getting an array of the
// form_structure and hash from our database. This is
// how the form data would have been saved using
// the $form->get_encoded_form_array() method.
$get_form_id = $_REQUEST['form_id'];
$schema = $_REQUEST['schema'];
include 'fake-form-db-vals.php';
$form = new Formbuilder($fake_db_vals);
if ($schema == 'open311') {
    $form->render_open311_service_definition();
} else {
    $form->render_json();
}
// OR, if you're using the database extension class you can load a form
// by passing in the record id:
//require('Formbuilder/Formbuilder_pdo.php');
//$form = new Formbuilder_pdo();
//$form->connect();
//$form->render_json( 1 );
 /**
  *
  * @param type $form_db_id
  * @param type $form_action 
  */
 public function process($form_db_id = false)
 {
     if ($form_db_id) {
         $form = $this->loadFormRecord($form_db_id);
         if ($form) {
             parent::__construct($form);
         }
     }
     return parent::process();
 }
Esempio n. 21
0
<?php

require 'Formbuilder/Formbuilder.php';
// At this stage, we simulate getting an array of the
// form_structure and hash from our database. This is
// how the form data would have been saved using
// the $form->store() method.
include 'fake-form-db-vals.php';
$form = new Formbuilder($fake_db_vals);
$form->render_json();
Esempio n. 22
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.
Esempio n. 23
0
 public function test_GenerateHtml_customAction()
 {
     $form = new Formbuilder($this->_container);
     $this->_form_html = sprintf($this->_form_html, 'fake/url/to/post/to');
     $this->assertEquals($this->_form_html, $form->generate_html('fake/url/to/post/to'));
 }