有人可以用这个保存表格协助我吗?

时间:2015-05-12 08:25:35

标签: php forms drupal drupal-7 drupal-modules

这里是我的用户表格的admin.inc文件。在这个例子中我有return system_settings_form($pppp_form);我真正想要的是自己制作一个保存按钮并在用户保存所有值按保存....这个表格代码下面做同样的事情,它的工作,但我想做我自己的保存表格,因为这个表格不保存我想要的复选框值,有人可以帮我制作自己的表格吗? ?我真的需要帮助!!非常感谢你..!

/**
 * Settings form for the user.
 */
function pppp_admin_settings() {

  $pppp_form['pppp_key'] = array(
      '#type'          => 'textfield',
      '#title'         => t('pppp'),
      '#default_value' => variable_get('pppp_key', ''),
      '#description'   => t('pppp.'),
      '#required'      => TRUE,
      '#size'          => 28,
      '#required'      => TRUE,
    );

    $pppp_options = array(
      '0'       => 'No Values',
      '100'     => '100',
      '500'     => '500',
      '1000'    => '1000',
      '5000'    => '5000',
      '50000'   => '50000',
      '1000000' => '1000000'
    );
    $pppp_form['pppp_number_select'] = array(
      '#type'          => 'select',
      '#options'       => $pppp_options,
      '#description'   => t('Select how many values you want to check.'),
      '#default_value' => variable_get('pppp_number_select', '0'),
    );

    $pppp_severity_levels = variable_get('pppp_severity_levels', array());

    $pppp_severity_options = array();

    foreach (watchdog_severity_levels() as $pppp_severity_number => $pppp_severity) {
      $pppp_options[$pppp_severity_number] = check_plain(drupal_ucfirst(
        $pppp_severity));
    }

    $pppp_form['pppp_severity'] = array(
      '#type'        => 'fieldset',
      '#title'       => t('pppp.'),
      '#collapsible' => TRUE,
      '#collapsed'   => TRUE,
    );

    $pppp_form['pppp_severity']['pppp_severity_levels'] = array(
      '#type'          => 'checkboxes',
      '#title'         => t('Type of log messages'),
      '#options'       => $pppp_severity_options,
      '#default_value' => array_values($pppp_severity_levels),
      '#required'      => TRUE,
    );

    return system_settings_form($pppp_form);

}

3 个答案:

答案 0 :(得分:1)

system_settings_form($ form)函数是一个快捷方式,允许您构建表单而不必担心保存按钮/提交处理程序(这些是自动添加的)。

如果你想构建一个完整的表单,包括提交处理程序等,你必须定义一个表单函数和一个表单提交处理程序,然后通过drupal_get_form调用它(' MY_FORM_NAME_admin_settings_form'); 所以

定义表单函数

这可以有你想要的任何名字

MY_FORM_NAME_admin_settings_form($form, &$form_state){
  //Put your form array here- 
  //Add a submit button
  $form['submit'] = array(
    '#type' => 'submit', 
    '#value' => 'Save'
  ); 
  return $form; 
}

定义提交处理程序

提交此表单后,它会自动尝试调用MY_FORM_NAME_admin_settings_form_submit,因此我们必须定义提交处理程序

  MY_FORM_NAME_admin_settings_form_submit($form, &$form_state){
    //All the input is in the $form_state['input'] so we'll put it in a message to see what's happening. 
    drupal_set_message('<pre>' . print_r($form_state['input'], true) . '</pre>'); 
    //Do your thing with the data 
    //Save it via variable set
  }

打印此表单

通过您需要的drupal_get_form调用此表单。

drupal_get_form('MY_FORM_NAME_admin_settings_form'); 

答案 1 :(得分:0)

你的问题有点模糊,但我认为你正在寻找提交按钮,它允许你定义一个自定义回调函数来处理数据。

$pppp_form['actions']['submit'] = array(

'#type' => 'submit',

'#value' => t('Delete'),

'#weight' => 15,

'#submit' => array('pppp_form_submit_callback'),
);

答案 2 :(得分:0)

在您发布的代码中,您有1个额外的右括号}。 对于表单提交,您可以添加

$pppp_form['submit'] = array(
    '#type' => 'submit',
    '#value' => 'Submit'
  );