为什么我的表单不应该更新?

时间:2010-08-12 08:30:22

标签: drupal drupal-6 drupal-fapi

无论我在表单中放置什么,提交处理程序都会获得相同的表单值。为什么???????

function edit_schoolinfo_form() {
    global $user;
    $result = db_query("SELECT * FROM {db} where userid=%d", $user->uid);
    $sas_school_info = db_fetch_array($result);
    $form = array();
    $form['school'] = array('#type' => 'fieldset', '#title' => t('School Information'), '#weight' => - 17,);
    $form['school']['principlename'] = array('#type' => 'textfield', '#title' => t('Principle Name '), '#required' => TRUE, '#size' => 45, '#weight' => - 11, '#value' => $sas_school_info['principlename'],);
    $form['school']['schoolname'] = array('#type' => 'textfield', '#title' => t('School Name '), '#required' => TRUE, '#size' => 45, '#weight' => - 10,'#value' => $sas_school_info['schoolname'],);
    $form['school']['address1'] = array('#type' => 'textfield', '#title' => t('Address 1'), '#required' => TRUE, '#size' => 45, '#weight' => - 9.1,'#value' => $sas_school_info['address1'],);
    $form['school']['address2'] = array('#type' => 'textfield', '#title' => t('Address 2'), '#required' => FALSE, '#size' => 45, '#weight' => - 9,'#value' => $sas_school_info['address2'],);
    $form['school']['city'] = array('#type' => 'textfield', '#title' => t('City'), '#required' => TRUE, '#size' => 30, '#weight' => - 12, '#weight' => - 5.2,'#value' => $sas_school_info['city'],);

    $form['school']['state'] = array('#type' => 'select', '#options' => greenopolis_sasapp_states_list(), '#title' => t('State'), '#required' => TRUE, '#weight' => - 5.0,'#default_value'=>$sas_school_info['state'],);
    $form['school']['zipcode'] = array('#type' => 'textfield', '#title' => t('School Zip Code'), '#required' => TRUE, '#size' => 20, '#weight' => - 4.9,'#value' => $sas_school_info['zipcode'],);
    $form['school']['terminalid'] = array('#type' => 'hidden', '#title' => t('Terminal ID'), '#required' => TRUE, '#size' => 20, '#weight' => - 4.8, '#value' => $terminalid, '#disabled' => TRUE);


    $form['admin'] = array('#type' => 'fieldset', '#title' => t('School Administrator Contact Information'), '#weight' => - 16,);
    $form['admin']['adminfname'] = array('#type' => 'textfield', '#title' => t('Administrator First Name'), '#required' => TRUE, '#size' => 45,'#value' => $sas_school_info['admin_first_name'],);
    //   $form['account']['mail'] = array('#type' => 'textfield', '#title' => t('Administrator Email'), '#required' => TRUE, '#size' => 45,);
    $form['admin']['adminlname'] = array('#type' => 'textfield', '#title' => t('Administrator Last Name'), '#required' => TRUE, '#size' => 45,'#value' => $sas_school_info['admin_last_name'],);
    $form['admin']['phoneno'] = array('#type' => 'textfield', '#title' => t('Phone Number'), '#required' => TRUE, '#size' => 45,'#value' => $sas_school_info['admin_phone'],);
    //  $form['account']['name'] = array('#type' => 'textfield', '#title' => t('Username'), '#required' => TRUE, '#size' => 45,);
    // $form['account']['pass'] = array('#type' => 'password_confirm', '#size' => 25, '#description' => t(''), '#required' => TRUE);


    $form['submit'] = array('#type' => 'submit', '#value' => t('Save Information'));

    return $form;


} //end of the function



function edit_schoolinfo_form_submit($form_id, &$form_state) {


    $principlename = $form_state['values']['principlename'];
    $schoolname = $form_state['values']['schoolname'];
    $address1 = $form_state['values']['address1'];
    $address2 = $form_state['values']['address2'];
    $city = $form_state['values']['city'];
    $state = $form_state['values']['state'];
    $zipcode = $form_state['values']['zipcode'];
    $admin_first_name = $form_state['values']['adminfname'];
    $admin_last_name = $form_state['values']['adminlname'];
    $admin_email = $form_state['values']['mail'];
    $admin_phone = $form_state['values']['phoneno'];



}

1 个答案:

答案 0 :(得分:7)

使用#default_value设置数据库中的存储值,而不是#value。当您设置#value时,无论用户提交什么,这都是值。