首先,我创建了10个文本框,并且在zend框架中设置required是正确的。 正文onload它禁用所有文本框。
我有一个显示0到10个数字的下拉框,当我选择一个数字时,它创建选定数量的文本框,如果我选择8它创建8个文本框。(使用javascript disable true)
之后,如果我从下拉列表中选择5,则只创建5个文本框。 现在,如果我在所有文本框中输入值。它没有提交到数据库的数据。有什么问题?
首先,如果我没有更改下拉2次数据提交。 如果我改变下拉2次数据没有提交。
这个
的PHP代码<?php
class Application_Form_Astroappointment extends Zend_Form {
public function init() {
/* Form Elements & Other Definitions Here ... */
$this->setName('form_fixappointment');
$this->setAction("");
$this->setAttrib('enctype', 'multipart/form-data');
$this->setAttrib('onsubmit', "javascript:hide(document.getElementById(\'no_of_item\').value)");
$firstname = $this->createElement('text', 'first_name');
$firstname->setLabel('First Name:')
->setRequired(true);
$lastname = $this->createElement('text', 'last_name');
$lastname->setLabel('Last Name:')
->setRequired(true);
$email = $this->createElement('text', 'email');
$email->setLabel('Email:')
->setRequired(true)
->addValidator('EmailAddress', true);
$countries = new Application_Model_DbTable_Countries;
$countriesList = $countries->getCountriesList();
$country = new Zend_Form_Element_Select('country_id');
$country->setLabel('Countries:')
->addMultiOptions($countriesList);
$states = $this->createElement('text', 'state');
$states->setLabel('States:')
->setRequired(true);
$cities = $this->createElement('text', 'city');
$cities->setLabel('Cities:')
->setRequired(true);
$cor_address = $this->createElement('textarea', 'cor_address');
$cor_address->setAttrib('rows', '6');
$cor_address->setAttrib('cols', '20');
$cor_address->setLabel('Corresponding Address:')
->setRequired(true);
$per_address = $this->createElement('textarea', 'per_address');
$per_address->setAttrib('rows', '6');
$per_address->setAttrib('cols', '20');
$per_address->setLabel('Permanent Address:');
$landline = $this->createElement('text', 'landline');
$landline->setLabel('Landline:');
$mobile_no = $this->createElement('text', 'mobile_no');
$mobile_no->setLabel('Mobile No:')
->setRequired(true);
$fax_no = $this->createElement('text', 'fax_no');
$fax_no->setLabel('Fax No:');
$dob = $this->createElement('text', 'dob');
$dob->setLabel('Date Of birth:')
->setRequired(true);
$tob = $this->createElement('text', 'tob');
$tob->setLabel('Time Of birth:')
->setRequired(true);
$birth_place = $this->createElement('text', 'birth_place');
$birth_place->setLabel('Birth Place:')
->setRequired(true);
$marriage_date = $this->createElement('text', 'marriage_date');
$marriage_date->setLabel('Marriage date:')
->setRequired(false);
$religion = $this->createElement('text', 'religion');
$religion->setLabel('Religion:')
->setRequired(false);
$deity = $this->createElement('text', 'deity');
$deity->setLabel('Deity (isth dev):')
->setRequired(false);
$occupation = $this->createElement('text', 'occupation');
$occupation->setLabel('Occupation:')
->setRequired(true);
$commu_mode = $this->createElement('radio', 'commu_mode');
$commu_mode->setLabel('Communication Mode:')
->addMultiOptions(array(
'Courier' => 'Courier',
'Mail' => 'Mail',
'Phone' => 'Phone',
'Handdelivery' => 'Hand Delivery',
))
->setSeparator('')
->setValue("Courier");
$appo_date = $this->createElement('text','appo_date');
$appo_date->setLabel('Appointment Date:')
->setRequired(true);
$comm_time_from = $this->createElement('text','commu_time_from');
$comm_time_from->setLabel('Communication time: From:')
->setRequired(true);
$comm_time_to = $this->createElement('text','commu_time_to');
$comm_time_to->setLabel('Communication time: To:')
->setRequired(true);
$kundli = new Zend_Form_Element_File('kundli');
$kundli->setLabel('Upload Kundli:')
->setRequired(false);
$kundli->addValidator('Extension', false, 'jpg,jpeg,png,gif,doc,pdf,docx,txt,rtf')
->addValidator('Size', false, array('min' => 20, 'max' => 409600));
$gen_query = $this->createElement('textarea', 'gen_query');
$gen_query->setAttrib('rows', '6');
$gen_query->setAttrib('cols', '20');
$gen_query->setLabel('General Query:');
$item_array = Array();
for ($i = 0; $i <= 10; $i++) {
$item_array[$i] = $i;
}
$items = new Zend_Form_Element_Select('no_of_item');
$items->setLabel('No of spiritual items you wore:')
->addMultiOptions($item_array)
->setAttrib('onchange', "javascript:show(this.options[this.selectedIndex].value)");
$item1 = $this->createElement('text','item1')
->setLabel('Enter Item 1:')
->setRequired(false)
->addDecorator('Label',array('tag' => 'dt','class'=>'required'));
$item2 = $this->createElement('text','item2')
->setLabel('Enter Item 2:')
->setRequired(true)
->addDecorator('Label',array('tag' => 'dt','class'=>'required'));
$item3 = $this->createElement('text','item3')
->setLabel('Enter Item 3:')
->setRequired(true)
->addDecorator('Label',array('tag' => 'dt','class'=>'required'));
$item4 = $this->createElement('text','item4')
->setLabel('Enter Item 4:')
->setRequired(true)
->addDecorator('Label',array('tag' => 'dt','class'=>'required'));
$item5 = $this->createElement('text','item5')
->setLabel('Enter Item 5:')
->setRequired(true)
->addDecorator('Label',array('tag' => 'dt','class'=>'required'));
$item6 = $this->createElement('text','item6')
->setLabel('Enter Item 6:')
->setRequired(true)
->addDecorator('Label',array('tag' => 'dt','class'=>'required'));
$item7 = $this->createElement('text','item7')
->setLabel('Enter Item 7:')
->setRequired(true)
->addDecorator('Label',array('tag' => 'dt','class'=>'required'));
$item8 = $this->createElement('text','item8')
->setLabel('Enter Item 8:')
->setRequired(true)
->addDecorator('Label',array('tag' => 'dt','class'=>'required'));
$item9 = $this->createElement('text','item9')
->setLabel('Enter Item 9:')
->setRequired(true)
->addDecorator('Label',array('tag' => 'dt','class'=>'required'));
$item10 = $this->createElement('text','item10')
->setLabel('Enter Item 2:')
->setRequired(true)
->addDecorator('Label',array('tag' => 'dt','class'=>'required'));
$div_element = $this->createElement(
'hidden', 'dummy', array(
'required' => false,
'ignore' => true,
'autoInsertNotEmptyValidator' => false,
'decorators' => array(
array(
'HtmlTag', array(
'tag' => 'div',
'id' => 'TextBoxes',
'class' => 'TextBoxes'
)
)
)
)
);
$image = new Zend_Form_Element_File('doc_path');
$image->setLabel('Upload Your Image');
// ->setRequired(true);
$image->addValidator('Extension', false, 'jpg,jpeg,png,gif')
->addValidator('Size', false, array('min' => 20, 'max' => 409600));
$captchaDir = rtrim(APPLICATION_PATH, '/application') . 'public\captcha\\';
$font = rtrim(APPLICATION_PATH, '/application') . 'public\captcha\arial.ttf';
// echo $_SERVER['DOCUMENT_ROOT'];
$captcha = new Zend_Form_Element_Captcha(
'captcha', // This is the name of the input field
array('label' => 'Write the chars to the field',
'captcha' => array(// Here comes the magic...
// First the type...
'captcha' => 'Image',
// Length of the word...
'wordLen' => 6,
// Captcha timeout, 5 mins
'timeout' => 300,
// What font to use...
'font' => $font,
// Where to put the image
'imgDir' => $captchaDir,
// URL to the images
// This was bogus, here's how it should be... Sorry again :S
'imgUrl' => 'http://localhost/vastuprem/public/captcha/',
)));
$register = $this->createElement('submit', 'register');
$register->setLabel('Submit')
->setIgnore(true);
// ->setAttrib('onclick', "javascript: validate(document.getElementById('no_of_item').value)");
$this->addElements(array(
$firstname,
$lastname,
$email,
$country,
$states,
$cities,
$cor_address,
$per_address,
$landline,
$mobile_no,
$fax_no,
$dob,
$tob,
$birth_place,
$marriage_date,
$religion,
$deity,
$occupation,
$commu_mode,
$appo_date,
$comm_time_from,
$comm_time_to,
$kundli,
$gen_query,
$items,
$item1,
$item2,
$item3,
$item4,
$item5,
$item6,
$item7,
$item8,
$item9,
$item10,
$div_element,
$image,
$captcha,
$register
));
//$this->dummy->clearValidators();
}
}
的javascript代码
function show(count){
// document.getElementById("item1").style.display="none" ;
document.getElementById("item1").disabled = true ;
document.getElementById("item1-label").style.display="none" ;
document.getElementById("item1-element").style.display="none";
// document.getElementById("item2").style.display="none" ;
document.getElementById("item2").disabled = true ;
document.getElementById("item2-label").style.display="none" ;
document.getElementById("item2-element").style.display="none";
// document.getElementById("item3").style.display="none" ;
document.getElementById("item3").disabled = true ;
document.getElementById("item3-label").style.display="none";
document.getElementById("item3-element").style.display="none";
//
// document.getElementById("item4").style.display="none" ;
document.getElementById("item4").disabled = true ;
document.getElementById("item4-label").style.display="none" ;
document.getElementById("item4-element").style.display="none";
// document.getElementById("item5").style.display="none" ;
document.getElementById("item5").disabled = true ;
document.getElementById("item5-label").style.display="none";
document.getElementById("item5-element").style.display="none";
//
// document.getElementById("item6").style.display="none" ;
document.getElementById("item6").disabled = true ;
document.getElementById("item6-label").style.display="none" ;
document.getElementById("item6-element").style.display="none";
// document.getElementById("item7").style.display="none" ;
document.getElementById("item7").disabled = true ;
document.getElementById("item7-label").style.display="none" ;
document.getElementById("item7-element").style.display="none";
// document.getElementById("item8").style.display="none" ;
document.getElementById("item8").disabled = true ;
document.getElementById("item8-label").style.display="none" ;
document.getElementById("item8-element").style.display="none";
// document.getElementById("item9").style.display="none" ;
document.getElementById("item9").disabled = true ;
document.getElementById("item9-label").style.display="none" ;
document.getElementById("item9-element").style.display="none";
// document.getElementById("item10").style.display="none" ;
document.getElementById("item10").disabled = true ;
document.getElementById("item10-label").style.display="none" ;
document.getElementById("item10-element").style.display="none" ;
for (i=1;i<=count;i++){
document.getElementById("item"+i).style.display="block";
document.getElementById("item"+i).disabled = false ;
document.getElementById("item"+i+"-label").style.display="block";
document.getElementById("item"+i+"-element").style.display="block";
}
}
function hide(count){
// document.getElementById("item1").style.display="none" ;
document.getElementById("item1").disabled = true ;
document.getElementById("item1-label").style.display="none" ;
document.getElementById("item1-element").style.display="none";
// document.getElementById("item2").style.display="none" ;
document.getElementById("item2").disabled = true ;
document.getElementById("item2-label").style.display="none" ;
document.getElementById("item2-element").style.display="none";
// document.getElementById("item3").style.display="none" ;
document.getElementById("item3").disabled = true ;
document.getElementById("item3-label").style.display="none";
document.getElementById("item3-element").style.display="none";
//
// document.getElementById("item4").style.display="none" ;
document.getElementById("item4").disabled = true ;
document.getElementById("item4-label").style.display="none" ;
document.getElementById("item4-element").style.display="none";
// document.getElementById("item5").style.display="none" ;
document.getElementById("item5").disabled = true ;
document.getElementById("item5-label").style.display="none";
document.getElementById("item5-element").style.display="none";
//
// document.getElementById("item6").style.display="none" ;
document.getElementById("item6").disabled = true ;
document.getElementById("item6-label").style.display="none" ;
document.getElementById("item6-element").style.display="none";
// document.getElementById("item7").style.display="none" ;
document.getElementById("item7").disabled = true ;
document.getElementById("item7-label").style.display="none" ;
document.getElementById("item7-element").style.display="none";
// document.getElementById("item8").style.display="none" ;
document.getElementById("item8").disabled = true ;
document.getElementById("item8-label").style.display="none" ;
document.getElementById("item8-element").style.display="none";
// document.getElementById("item9").style.display="none" ;
document.getElementById("item9").disabled = true ;
document.getElementById("item9-label").style.display="none" ;
document.getElementById("item9-element").style.display="none";
// document.getElementById("item10").style.display="none" ;
document.getElementById("item10").disabled = true ;
document.getElementById("item10-label").style.display="none" ;
document.getElementById("item10-element").style.display="none" ;
//
//
show(count);
}
答案 0 :(得分:0)
尝试手动调试,如下所示,
echo
打印这些值。