Add input field in Zend Framework


Text Field:

$title = new Zend_Form_Element_Text('title');
$title->setLabel($this->_trans->translate('lblTenantRentalTitle').' * :')->setRequired()->setOrder(1)
->setAttribs(array('class' => 'post_input_text', 'id' => 'text_title'))
->addErrorMessage('Title is required!');
$this->addElement($title);

Text Area:

$detail = new Zend_Form_Element_Textarea('detail');
$detail->setLabel($this->_trans->translate('lblTenantRentalDetail').' * :')->setRequired()->setOrder(2)
->setAttribs(array('cols' => 50, 'rows' => 5, 'class' => 'post_input_textarea', 'id' => 'text_detail'))
->addErrorMessage('Detail is required!');
$this->addElement($detail);

Select Option:

$rental_type_id = new Zend_Form_Element_Select('rental_type_id');
$rental_type_id->setLabel($this->_trans->translate('lblTenantRentalType').' * :')->setRequired()->setOrder(3)
->addMultiOptions($rental_type_list)
->setAttribs(array('class' => 'input input_select select_rental_type_id', 'id' => 'select_rental_type_id'))
->addErrorMessage('Position is required!');
$this->addElement($rental_type_id);

Check Box:

$is_price_per_sqfeet = new Zend_Form_Element_Checkbox('is_price_per_squre_feet');
$is_price_per_sqfeet->setLabel($this->_trans->translate('lblRentPerSquareFeet').' :')->setOrder(27)
->setValue(array_search($boolean_options_no, $boolean_options))
->setAttribs(array('class' => 'input input_checkbox checkbox_is_price_per_sqfeet', 'id' => 'checkbox_is_price_per_sqfeet'));
$this->addElement($is_price_per_sqfeet);

Radio Button:

$is_security_deposit = new Zend_Form_Element_Radio('is_security_deposit');
$is_security_deposit->setLabel($this->_trans->translate('lblSecurityDeposit').':')->setOrder(35)->setSeparator(' ')
->addMultiOptions($boolean_options)
->setValue(array_search($boolean_options_no, $boolean_options))
->setAttribs(array('class' => 'input input_radio', 'id' => 'radio_is_security_deposit'));
$this->addElement($is_security_deposit);

Input Type File:

$image = new Zend_Form_Element_File('image');
$image->setLabel($this->_trans->translate("lblImage").':')
->setAttribs(array('class' => 'input input_file file_image', 'id' => 'file_image'))
->addValidator('Count', false, 1)->addValidator('Size', false, 52000000)->addValidator('Extension', false, 'jpg,jpeg,png,gif')
->addErrorMessage('Image is required!');
$this->addElement($image);

Input Type Submit:
$submit = new Zend_Form_Element_Submit('save');
$submit->setLabel($this->_trans->translate('btnSave'))->setDecorators(array('ViewHelper'))
->setAttribs(array('class' => 'input input_button btn_submit btn_black_normal', 'id' => 'btn_submit'));
$this->addElement($submit);

Input Type Button:
$cancel = new Zend_Form_Element_Button('cancel');
$cancel->setLabel($this->_trans->translate('btnCancel'))->setDecorators(array('ViewHelper'))
->setAttribs(array('class' => 'input input_button btn_cancel btn_black_normal', 'id' => 'btn_cancel'));
$this->addElement($cancel);

Date:

$lease_start = new Zend_Form_Element_Text('lease_start');
$lease_start->setLabel($this->_trans->translate('lblStartDate').' * :')->setRequired()->setOrder(50)
->setValue($today->format("Y-m-d"))
->setAttribs(array('class' => 'post_input_text_with_checkbox', 'id' => 'text_lease_start'))
->addFilter('StripTags')
->addErrorMessage('Start Date is required!');
$this->addElement($lease_start);
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s