Beispiel #1
0
 function parseFields($row)
 {
     $html = '';
     if (!isset($_SESSION['formdata'])) {
         $_SESSION['formdata'] = array();
     }
     switch ($row->inputtype) {
         case 'text':
             if (isset($_SESSION['formdata'][$row->name])) {
                 $row->default_value = stripslashes($_SESSION['formdata'][$row->name]);
             }
             $errmsg = forme_HTML::parseErrorMsg($row->name);
             $html = str_replace('{fieldtitle}', $row->title, $row->fieldstyle);
             $html = str_replace('{validationsign}', $row->validation_rule ? ' *' : '', $html);
             $html = str_replace('{field}', '<input type="text" name="form[' . $row->name . ']" value="' . $row->default_value . '" id="' . $row->name . '" ' . $row->params . ' />' . $errmsg, $html);
             $html = str_replace('{fielddesc}', $row->description, $html);
             break;
         case 'button':
             $html = str_replace('{fieldtitle}', $row->title, $row->fieldstyle);
             $html = str_replace('{validationsign}', $row->validation_rule ? ' *' : '', $html);
             $html = str_replace('{field}', '<input type="button" name="form[' . $row->name . ']" value="' . $row->default_value . '" id="' . $row->name . '" ' . $row->params . ' />', $html);
             $html = str_replace('{fielddesc}', $row->description, $html);
             break;
         case 'reset button':
             $html = str_replace('{fieldtitle}', $row->title, $row->fieldstyle);
             $html = str_replace('{validationsign}', $row->validation_rule ? ' *' : '', $html);
             $html = str_replace('{field}', '<input type="reset" name="form[' . $row->name . ']" value="' . $row->default_value . '" id="' . $row->name . '" ' . $row->params . ' />', $html);
             $html = str_replace('{fielddesc}', $row->description, $html);
             break;
         case 'submit button':
             $html = str_replace('{fieldtitle}', $row->title, $row->fieldstyle);
             $html = str_replace('{validationsign}', $row->validation_rule ? ' *' : '', $html);
             $html = str_replace('{field}', '<input type="submit" name="form[' . $row->name . ']" value="' . $row->default_value . '" id="' . $row->name . '" ' . $row->params . ' />', $html);
             $html = str_replace('{fielddesc}', $row->description, $html);
             break;
         case 'image button':
             $html = str_replace('{fieldtitle}', $row->title, $row->fieldstyle);
             $html = str_replace('{validationsign}', $row->validation_rule ? ' *' : '', $html);
             $html = str_replace('{field}', '<input type="image" name="form[' . $row->name . ']" src="' . $row->default_value . '" id="' . $row->name . '" ' . $row->params . ' />', $html);
             $html = str_replace('{fielddesc}', $row->description, $html);
             break;
         case 'hidden':
             $html = str_replace('{fieldtitle}', $row->title, $row->fieldstyle);
             $html = str_replace('{validationsign}', $row->validation_rule ? ' *' : '', $html);
             $html = str_replace('{field}', '<input type="hidden" name="form[' . $row->name . ']" value="' . $row->default_value . '" id="' . $row->name . '" ' . $row->params . ' />', $html);
             $html = str_replace('{fielddesc}', $row->description, $html);
             break;
         case 'file upload':
             $errmsg = forme_HTML::parseErrorMsg($row->name);
             $html = str_replace('{fieldtitle}', $row->title, $row->fieldstyle);
             $html = str_replace('{validationsign}', $row->validation_rule ? ' *' : '', $html);
             $html = str_replace('{field}', '<input type="file" name="form[' . $row->name . ']" value="" id="' . $row->name . '" ' . $row->params . ' />' . $errmsg, $html);
             $html = str_replace('{fielddesc}', $row->description, $html);
             break;
         case 'password':
             $errmsg = forme_HTML::parseErrorMsg($row->name);
             $html = str_replace('{fieldtitle}', $row->title, $row->fieldstyle);
             $html = str_replace('{validationsign}', $row->validation_rule ? ' *' : '', $html);
             $html = str_replace('{field}', '<input type="password" name="form[' . $row->name . ']" value="' . $row->default_value . '" id="' . $row->name . '" ' . $row->params . ' />' . $errmsg, $html);
             $html = str_replace('{fielddesc}', $row->description, $html);
             break;
         case 'radio':
             $errmsg = forme_HTML::parseErrorMsg($row->name);
             if (isset($_SESSION['formdata'][$row->name])) {
                 $row->default_value = str_replace('{checked}', '', $row->default_value);
             }
             $row->default_value = explode(',', $row->default_value);
             $radios = '';
             foreach ($row->default_value as $i => $radioset) {
                 $valTitle = explode('|', $radioset);
                 if (!isset($valTitle[1])) {
                     $valTitle[1] = $valTitle[0];
                 }
                 if (isset($_SESSION['formdata'][$row->name])) {
                     if ($_SESSION['formdata'][$row->name] == $valTitle[0]) {
                         $valTitle[0] = $valTitle[0] . '" checked="checked';
                     }
                 } else {
                     $valTitle[0] = str_replace('{checked}', '" checked="checked', $valTitle[0]);
                 }
                 $radios .= '<span class="radio' . $row->name . '" style="white-space: nowrap"><input type="radio" name="form[' . $row->name . ']" id="' . $row->name . $i . '" value="' . $valTitle[0] . '" ' . $row->params . ' /><label for="' . $row->name . $i . '">' . $valTitle[1] . '</label></span>';
             }
             $html = str_replace('{fieldtitle}', $row->title, $row->fieldstyle);
             $html = str_replace('{validationsign}', $row->validation_rule ? ' *' : '', $html);
             $html = str_replace('{field}', $radios . $errmsg, $html);
             $html = str_replace('{fielddesc}', $row->description, $html);
             break;
         case 'checkbox':
             $errmsg = forme_HTML::parseErrorMsg($row->name);
             if (isset($_SESSION['formdata'][$row->name])) {
                 $row->default_value = str_replace('{checked}', '', $row->default_value);
             }
             $row->default_value = explode(',', $row->default_value);
             $checks = '';
             foreach ($row->default_value as $i => $checkset) {
                 $valTitle = explode('|', $checkset);
                 if (!isset($valTitle[1])) {
                     $valTitle[1] = $valTitle[0];
                 }
                 if (isset($_SESSION['formdata'][$row->name])) {
                     foreach ($_SESSION['formdata'][$row->name] as $val) {
                         if ($val == $valTitle[0]) {
                             $valTitle[0] = $valTitle[0] . '" checked="checked';
                         }
                     }
                 } else {
                     $valTitle[0] = str_replace('{checked}', '" checked="checked', $valTitle[0]);
                 }
                 $checks .= '<span class="check' . $row->name . '" style="white-space: nowrap"><input type="checkbox" name="form[' . $row->name . '][]" id="' . $row->name . $i . '" value="' . $valTitle[0] . '" ' . $row->params . ' /><label for="' . $row->name . $i . '">' . $valTitle[1] . '</label></span>';
             }
             $html = str_replace('{fieldtitle}', $row->title, $row->fieldstyle);
             $html = str_replace('{validationsign}', $row->validation_rule ? ' *' : '', $html);
             $html = str_replace('{field}', $checks . $errmsg, $html);
             $html = str_replace('{fielddesc}', $row->description, $html);
             break;
         case 'textarea':
             if (isset($_SESSION['formdata'][$row->name])) {
                 $row->default_value = stripslashes($_SESSION['formdata'][$row->name]);
             }
             $errmsg = forme_HTML::parseErrorMsg($row->name);
             $html = str_replace('{fieldtitle}', $row->title, $row->fieldstyle);
             $html = str_replace('{validationsign}', $row->validation_rule ? ' *' : '', $html);
             $html = str_replace('{field}', '<textarea name="form[' . $row->name . ']" id="' . $row->name . '" ' . $row->params . '>' . $row->default_value . '</textarea>' . $errmsg, $html);
             $html = str_replace('{fielddesc}', $row->description, $html);
             break;
         case 'select':
             $errmsg = forme_HTML::parseErrorMsg($row->name);
             if (isset($_SESSION['formdata'][$row->name])) {
                 $row->default_value = str_replace('{checked}', '', $row->default_value);
             }
             $options = '';
             $row->default_value = explode(',', $row->default_value);
             foreach ($row->default_value as $optionset) {
                 $valTitle = explode('|', $optionset);
                 if (!isset($valTitle[1])) {
                     $valTitle[1] = $valTitle[0];
                 }
                 if (isset($_SESSION['formdata'][$row->name])) {
                     foreach ($_SESSION['formdata'][$row->name] as $val) {
                         if ($val == $valTitle[0]) {
                             $valTitle[0] = $valTitle[0] . '" selected="selected';
                         }
                     }
                 } else {
                     $valTitle[0] = str_replace('{checked}', '" selected="selected', $valTitle[0]);
                 }
                 $options .= '<option value="' . $valTitle[0] . '">' . $valTitle[1] . '</option>';
             }
             $html = str_replace('{fieldtitle}', $row->title, $row->fieldstyle);
             $html = str_replace('{validationsign}', $row->validation_rule ? ' *' : '', $html);
             $html = str_replace('{field}', '<select name="form[' . $row->name . '][]" ' . $row->params . ' id="' . $row->name . '" >' . $options . '</select>' . $errmsg, $html);
             $html = str_replace('{fielddesc}', $row->description, $html);
             break;
         case 'calendar':
             if (isset($_SESSION['formdata'][$row->name])) {
                 $default_value = $_SESSION['formdata'][$row->name];
             } else {
                 $default_value = '';
             }
             $errmsg = forme_HTML::parseErrorMsg($row->name);
             $html = str_replace('{fieldtitle}', $row->title, $row->fieldstyle);
             $html = str_replace('{validationsign}', $row->validation_rule ? ' *' : '', $html);
             $html = str_replace('{field}', '<div id="' . $row->name . 'Container"></div><input id="txt' . $row->name . '" name="form[' . $row->name . ']" value="' . $default_value . '" type="hidden"/>' . $errmsg, $html);
             $html = str_replace('{fielddesc}', $row->description, $html);
             break;
         case 'free text':
             $html = str_replace('{fieldtitle}', $row->title, $row->fieldstyle);
             $html = str_replace('{validationsign}', '', $html);
             $html = str_replace('{field}', $row->default_value, $html);
             $html = str_replace('{fielddesc}', $row->description, $html);
             break;
         case 'ticket number':
             $length = (int) $row->default_value;
             if ($length < 1 || $length > 255) {
                 $length = 8;
             }
             $key = "";
             $possible = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
             $i = 0;
             while ($i < $length) {
                 $key .= substr($possible, mt_rand(0, strlen($possible) - 1), 1);
                 $i++;
             }
             $html = str_replace('{fieldtitle}', $row->title, $row->fieldstyle);
             $html = str_replace('{validationsign}', '', $html);
             $html = str_replace('{field}', '<input id="' . $row->name . '" name="form[' . $row->name . ']"  value="' . $key . '" type="hidden"/>', $html);
             $html = str_replace('{fielddesc}', $row->description, $html);
             break;
         case 'captcha':
             $errmsg = forme_HTML::parseErrorMsg($row->name);
             $html = str_replace('{fieldtitle}', $row->title, $row->fieldstyle);
             $html = str_replace('{validationsign}', $row->validation_rule ? ' *' : '', $html);
             $html = str_replace('{field}', '<img src="' . JURI::base() . 'index.php?option=com_forme&func=captcha"/><br/><input type="text" name="form[' . $row->name . ']" value="' . $row->default_value . '" id="' . $row->name . '" ' . $row->params . ' style="width:74px;text-align:center;" />' . $errmsg, $html);
             $html = str_replace('{fielddesc}', $row->description, $html);
             break;
     }
     return $html;
 }