1
當我提交表單時未填寫任何必填字段(或任何必填字段的組合)時,沒有顯示狀態消息讓我知道我錯過了必填字段。 我第二次提交表單時,狀態消息顯示我需要哪些字段。 狀態消息似乎是表單提交後的一步。爲什麼第一次提交表單時drupal 6狀態消息沒有顯示需要填寫什麼字段
如果在第一次提交之後,我改變了填充的字段,然後再次提交狀態消息,應該顯示上一次顯示的狀態消息。
當表格填寫正確時,它會正常提交。
表單使用drupal_get_form('otherWaysToRequest'); 這在主題中的模板文件中調用。
有誰知道爲什麼狀態信息落後一步?
這是因爲你在你的模板調用drupal_get_form
文件已經提交當前頁面的消息時正在使用
function otherWaysToRequest(&$form_state)
{
global $base_url;
$pathToTheme = path_to_theme();
$form['top-check'] = array(
'#type' => 'fieldset',
'#attributes' => array('class' => 'checkboxes'),
);
$form['top-check']['gift'] = array(
'#title' => t('Included a gift'),
'#type' => 'checkbox',
'#suffix' => '<br />',
'#required' => false,
);
$form['top-check']['contact'] = array(
'#title' => t('I would like to speak to you'),
'#type' => 'checkbox',
'#suffix' => '<br />',
'#required' => false,
);
$form['name'] = array(
'#title' => t('Name'),
'#type' => 'textfield',
'#required' => true,
);
$form['email'] = array(
'#title' => t('Email Address'),
'#type' => 'textfield',
'#required' => true,
);
$form['bottom-check'] = array(
'#type' => 'fieldset',
'#attributes' => array('class' => 'checkboxes'),
'#description' => t('<p class="Items">If you have ...:</p><p class="Items">I have included .....</p>')
);
$form['bottom-check']['share'] = array(
'#title' => t('A Share'),
'#type' => 'checkbox',
'#suffix' => '<br />',
'#required' => FALSE,
);
$form['submit'] = array(
'#type' => 'image_button',
'#src' => $pathToTheme.'/image.gif',
'#value' => t('Submit Form'),
);
}
function otherWaysToRequest_validate($form, &$form_state)
{
$mail_reg_ex = '/[-a-zA-Z0-9._]+[@]{1}[-a-zA-Z0-9.]+[.]{1}[a-zA-Z]{2,4}/';
if(!preg_match($mail_reg_ex, $form_state['values']['email']))
{
form_set_error('email', t('Invalid email address.'));
}
if(0 == $form_state['values']['gift'] & 0 == $form_state['values']['contact'])
{
form_set_error('gift', t('You must choose one of the first two options on the form'));
}
}
function otherWaysToRequest_submit($form, &$form_state)
{
//mail details
}
優秀!!感謝您的幫助。 – JohnK