Example #1
0
 public function handle_field_editor($form, $field_id, $get, $post, $cookie)
 {
     $field = new Field();
     foreach ($form->fields as $f) {
         if ($f->id == $field_id) {
             $field = $f;
             break;
         }
     }
     if ($post['action'] === 'edit_field') {
         $this->handle_field_editor_post($form, $field, $post);
         return $this->gateway->redirect('form/' . $form->id . '/field');
     }
     $title = sprintf('Form Editor :: %s :: %s', htmlspecialchars($form->title), htmlspecialchars($field->label ? $field->label : "New Field"));
     $out = "<h1>{$title}</h1>";
     $out .= "<form action=\"\" method=\"post\">\n";
     $out .= "<div class=\"row\">\n";
     $out .= "<div class=\"col-sm-6\">\n";
     $out .= "<div class=\"form-group\">\n";
     $out .= "<label for=\"slug\">Slug</label>\n";
     $out .= "<input " . ($field_id > 0 ? 'disabled="disabled"' : 'required="required"') . " type=\"text\" class=\"form-control\" id=\"slug\" name=\"slug\" value=\"" . htmlspecialchars($field->slug) . "\">";
     $out .= "<p class=\"help-block\">The name of the database column to store input into.</p>\n";
     $out .= "</div>\n";
     $out .= "<div class=\"form-group\">\n";
     $out .= "<label for=\"type\">Type</label>\n";
     $out .= "<select class=\"form-control\" id=\"type\" name=\"type\" style=\"width:auto\">";
     $type_names = Field::known_field_types();
     foreach ($type_names as $type => $label) {
         $out .= sprintf("<option value=\"%s\" %s>%s</option>", htmlspecialchars($type), $type == $field->type ? 'selected' : '', htmlspecialchars($label));
     }
     $out .= "</select>\n";
     $out .= "</div>\n";
     $out .= "<div class=\"form-group\">\n";
     $out .= "<label for=\"sort_order\">Sort Order</label>\n";
     $out .= "<input type=\"number\" class=\"form-control\" id=\"sort_order\" name=\"sort_order\" style=\"width:8em\" value=\"" . htmlspecialchars($field->sort_order) . "\">";
     $out .= "<p class=\"help-block\">Controls what order the field will appear in on its form. Low sort orders appear first.</p>\n";
     $out .= "</div>\n";
     $out .= "<div class=\"form-group\">\n";
     $out .= "<label for=\"label\">Label</label>\n";
     $out .= "<input required=\"required\" type=\"text\" class=\"form-control\" id=\"label\" name=\"label\" value=\"" . htmlspecialchars($field->label) . "\">";
     $out .= "</div>\n";
     $out .= "<div class=\"form-group\">\n";
     $out .= "<label for=\"default_value\">Default Value</label>\n";
     $out .= "<input type=\"text\" class=\"form-control\" id=\"default_value\" name=\"default_value\" value=\"" . htmlspecialchars($field->default_value) . "\">";
     $out .= "</div>\n";
     $out .= "<div class=\"form-group\">\n";
     $out .= "<label for=\"help_text\">Help Text</label>\n";
     $out .= "<textarea rows=\"4\" cols=\"60\" class=\"form-control\" id=\"help_text\" name=\"help_text\">" . htmlspecialchars($field->help_text) . "</textarea>";
     $out .= "</div>\n";
     $out .= "</div>\n";
     $out .= "<div class=\"col-sm-6\">\n";
     $out .= "<div class=\"form-group\">\n";
     $out .= "<label for=\"enumeration\">Enumeration</label>\n";
     $out .= "<input type=\"text\" class=\"form-control\" id=\"enumeration\" name=\"enumeration\" value=\"" . htmlspecialchars($field->enumeration) . "\">";
     $out .= "<p class=\"help-block\">Pipe-delimited list of valid values, such as <code>Yes|No|Maybe</code>. Mostly useful for fields where the type is \"Selection\".</p>\n";
     $out .= "</div>\n";
     $out .= "<div class=\"form-group\">\n";
     $out .= "<label for=\"regex\">Validation Regular Expression</label>\n";
     $out .= "<input type=\"text\" class=\"form-control\" id=\"regex\" name=\"regex\" value=\"" . htmlspecialchars($field->regex) . "\">";
     $out .= "<p class=\"help-block\">PHP-compatible regular expression for validating field input. Leave blank if you're not sure what this means.</p>\n";
     $out .= "</div>\n";
     $out .= "<div class=\"row\">\n";
     $out .= "<div class=\"form-group col-sm-6\">\n";
     $out .= "<label for=\"minimum\">Minimum</label>\n";
     $out .= "<input type=\"text\" class=\"form-control\" id=\"minimum\" name=\"minimum\" value=\"" . htmlspecialchars($field->minimum) . "\">";
     $out .= "<p class=\"help-block\">Minimum for numeric inputs.</p>\n";
     $out .= "</div>\n";
     $out .= "<div class=\"form-group col-sm-6\">\n";
     $out .= "<label for=\"maximum\">Maximum</label>\n";
     $out .= "<input type=\"text\" class=\"form-control\" id=\"maximum\" name=\"maximum\" value=\"" . htmlspecialchars($field->maximum) . "\">";
     $out .= "<p class=\"help-block\">Maximum for numeric inputs.</p>\n";
     $out .= "</div>\n";
     $out .= "</div>\n";
     $out .= "<div class=\"row\">\n";
     $out .= "<div class=\"form-group col-sm-6\">\n";
     $out .= "<label for=\"minimum_length\">Minimum Length</label>\n";
     $out .= "<input type=\"text\" class=\"form-control\" id=\"minimum_length\" name=\"minimum_length\" value=\"" . htmlspecialchars($field->minimum_length) . "\">";
     $out .= "<p class=\"help-block\">Minimum length for text inputs.</p>\n";
     $out .= "</div>\n";
     $out .= "<div class=\"form-group col-sm-6\">\n";
     $out .= "<label for=\"maximum_length\">Maximum Length</label>\n";
     $out .= "<input type=\"text\" class=\"form-control\" id=\"maximum_length\" name=\"maximum_length\" value=\"" . htmlspecialchars($field->maximum_length) . "\">";
     $out .= "<p class=\"help-block\">Maximum length for text inputs.</p>\n";
     $out .= "</div>\n";
     $out .= "</div>\n";
     $out .= "<div class=\"form-group\">\n";
     $out .= "<label for=\"format\">Format</label>\n";
     $out .= "<input type=\"text\" class=\"form-control\" id=\"format\" name=\"format\" value=\"" . htmlspecialchars($field->format) . "\">";
     $out .= "<p class=\"help-block\">Formatting code for PHP <code>sprintf</code> or <code>date</code> function. Leave blank if you're not sure what this means.</p>\n";
     $out .= "</div>\n";
     $out .= "</div>\n";
     $out .= "</div>\n";
     $out .= "<div class=\"row\">\n";
     $out .= "<div class=\"col-sm-12\">\n";
     $out .= "<div class=\"form-group\">\n";
     $out .= "<input type=\"hidden\" name=\"action\" value=\"edit_field\">";
     $out .= "<input type=\"submit\" class=\"btn btn-success\" value=\"Save\">";
     $out .= "</div>\n";
     $out .= "</div>\n";
     $out .= "</div>\n";
     $out .= "</form>\n";
     return $this->gateway->respond($title, $out);
 }