All pastes #67829 Raw Edit

clueless

public text v1 · immutable
#67829 ·published 2006-06-20 17:42 UTC
rendered paste body
****************** 86,92 ****   */  function forms_save_field($field) {    if (is_array($field)) {-     $field = array2object($field);    }      $field_cols = array('ffid','fid','title','explanation','page','type','weight','required','flags','validation','options','multiple');  --- 86,92 ----   */  function forms_save_field($field) {    if (is_array($field)) {+     $field = (object) $field;    }      $field_cols = array('ffid','fid','title','explanation','page','type','weight','required','flags','validation','options','multiple');  ****************** 147,204 ****   * form for editing a field   */  function forms_field_form($field, $exclude = NULL) {  -   $output.= form_hidden('fid', $field->fid);-   $output.= form_hidden('ffid', $field->ffid);  -   $output.= form_select(t('Type'), 'type', $field->type, _forms_get_field_types($exclude));-   $output.= form_textfield(t('Title'), 'title', $field->title, 70, 128, t('The title will be shown in the user interface.'));-   $output.= form_textarea(t('Explanation'), 'explanation', $field->explanation, 70, 3, t("An optional explanation to go with the new field.  The explanation will be shown to the user."));-   $output.= form_textarea(t('Selection options'), 'options', $field->options, 70, 8, t("For select fields only. A list of all options - delimited by semicolons (e.g. red;blue;green). To have different labels from values, use colons e.g. 1:red;2:blue;3:green"));-   $output.= form_checkbox(t('Allow multiple selection'), 'multiple', 1, $field->multiple);-   $output.= form_weight(t('Weight'), 'weight', $field->weight, 5, t("The weights define the order in which the form fields are shown.  Lighter fields \"float up\" towards the top of the category."));-   $output.= form_checkbox(t('Required field'), 'required', 1, $field->required);-   $output.= form_select(t("Validation function"), 'validation', $field->validation, _forms_get_validation_types(), t("Name of a function to test the input value"));      // get extra form fields for 'flags'-   $output.= implode('', forms_invoke_formapi($field, 'edit'));    -   return $output;  }  - function forms_render($form, $edit = array()) {    foreach ($form->fields as $field) {-     $output.= forms_render_field($field, $edit[$field->name]);    }- -   return $output;  }  - function forms_render_field($field, $value = null) {    forms_invoke_formapi($field, 'view');    $func = 'form_' . $field->type;    switch ($field->type) {      case 'radios':-       $output .= $func($field->title, $field->name, $value, _forms_options($field->options), $field->explanation, $field->required);        break;      case 'select':-       $output .= $func($field->title, $field->name, $value, _forms_options($field->options), $field->explanation, NULL, $field->multiple, $field->required);        break;      case 'textarea':-       $output .= $func($field->title, $field->name, $value, 64, 5, $field->explanation, NULL, $field->required);        break;      case 'file':-       $output .= $func($field->title, $field->name, '', $field->explanation, $field->required);        break;      case 'checkbox':-       $output .= $func($field->title, $field->name, 1, $value, $field->explanation, NULL, $field->required);        break;-     case 'textfield':      case 'password':-       $output .= $func($field->title, $field->name, $value, 64, 64, $field->explanation, NULL, $field->required);        break;    }-   return $output;  }    function forms_validate($form, $edit) {--- 147,303 ----   * form for editing a field   */  function forms_field_form($field, $exclude = NULL) {+   $form = array();  +   $form['fid'] = array('#type' => 'hidden', '#value' => $field->fid);+   $form['ffid'] = array('#type' => 'hidden', '#value' => $field->ffid);  +   $form['type'] = array(+     '#type' => 'select', +     '#title' => t('Type'), +     '#default_value' =>  $field->type, +     '#options' => _forms_get_field_types($exclude), +   );+   $form['title'] = array(+     '#type' => 'textfield', +     '#title' => t('Title'), +     '#default_value' =>  $field->title, +     '#description' => t('The title will be shown in the user interface.'),+     '#size' => 70,+     '#maxlength' => 128,+   );+   $form['explanation'] = array(+     '#type' => 'textarea', +     '#title' => t('Explanation'), +     '#default_value' =>  $field->explanation, +     '#description' => t("An optional explanation to go with the new field.  The explanation will be shown to the user."),+     '#cols' => 70,+     '#rows' => 3,+   );+   $form['options'] = array(+     '#type' => 'textarea', +     '#title' => t('Selection options'), +     '#default_value' =>  $field->options, +     '#description' => t("For select fields only. A list of all options - delimited by semicolons (e.g. red;blue;green). To have different labels from values, use colons e.g. 1:red;2:blue;3:green"),+     '#cols' => 70,+     '#rows' => 8,+   );+   $form['multiple'] = array(+     '#type' => 'checkbox', +     '#title' => t('Allow multiple selection'), +     '#default_value' =>  $field->multiple, +   );+   $form['weight'] = array(+     '#type' => 'weight', +     '#title' => t('Weight'), +     '#default_value' =>  $field->weight, +     '#description' => t("The weights define the order in which the form fields are shown.  Lighter fields \"float up\" towards the top of the category."),+     '#delta' => 5,+   );+   $form['required'] = array(+     '#type' => 'checkbox',+     '#title' => t('Required field'),+     '#default_value' => $field->required,+   );+   $form['validation'] = array(+     '#type' => 'select', +     '#title' => t('Validation function'), +     '#description' => t("Name of a function to test the input value"),+     '#default_value' =>  $field->validation, +     '#options' => _forms_get_validation_types($exclude), +   );      // get extra form fields for 'flags'+ //  $output.= implode('', forms_invoke_formapi($field, 'edit'));    +   return $form;  }  + function forms_get_form($form, $edit = array()) {+   $real_form = array();    foreach ($form->fields as $field) {+     $real_form[$field->name] = forms_get_field($field, $edit[$field->name]);    }+   return $real_form;  }  + function forms_get_field($field, $value = null) {    forms_invoke_formapi($field, 'view');    $func = 'form_' . $field->type;    switch ($field->type) {      case 'radios':+       $real_field = array(+         '#type' => 'radios', +         '#title' => $field->title, +         '#default_value' =>  $value, +         '#options' => _forms_options($field->options), +         '#description' => $field->explanation,+         '#required' => $field->required+       );        break;      case 'select':+       $real_field = array(+         '#type' => 'select', +         '#title' => $field->title, +         '#default_value' =>  $value, +         '#options' => _forms_options($field->options), +         '#description' => $field->explanation,+         '#multiple' => $field->multiple,+         '#required' => $field->required+       );        break;      case 'textarea':+       $real_field = array(+         '#type' => 'textarea', +         '#title' => $field->title, +         '#default_value' =>  $value, +         '#cols' => 64,+         '#rows' =>  5, +         '#description' => $field->explanation,+         '#required' => $field->required+       );+       break;+     case 'textfield':+       $real_field = array(+         '#type' => 'textfield', +         '#title' => $field->title, +         '#default_value' =>  $value, +         '#size' => 64,+         '#maxlength' =>  64, +         '#description' => $field->explanation,+         '#required' => $field->required+       );        break;      case 'file':+       $real_field = array(+         '#type' => 'file', +         '#title' => $field->title, +         '#description' => $field->explanation,+         '#required' => $field->required+       );        break;      case 'checkbox':+       $real_field = array(+         '#type' => 'checkbox', +         '#title' => $field->title, +         '#default_value' =>  $value, +         '#description' => $field->explanation,+         '#required' => $field->required+       );        break;      case 'password':+       $real_field = array(+         '#type' => 'password', +         '#title' => $field->title, +         '#default_value' =>  $value, +         '#size' => 64,+         '#maxlength' =>  64, +         '#description' => $field->explanation,+         '#required' => $field->required+       );        break;    }+   return $real_field;  }    function forms_validate($form, $edit) {