为什么我的表单没有按预期更新?
无论我在表单中输入什么内容,提交处理程序都会获得相同的表单值。为什么???????
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'];
}
The submit handler gets the same form values no matter what I put in the form. Why???????
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'];
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用
#default_value
设置数据库中存储的值,而不是#value
。当您设置#value
时,无论用户提交什么,该值都将是该值。Use
#default_value
to set the stored values from the database, instead of#value
. When you set#value
, that will be the value regardless of what the user submits.