phpdeveloper82 Posted February 27, 2010 Share Posted February 27, 2010 Hello, I need help in building Form elements for the Birthday Input (Label: Birthday and Three select menus - Day, Month & Year). I don't get how can I build three select menus in the same line, as I am new to Zend Framework.. I need Birthday field must work same as of Facebook Sign Up page (http://facebook.com ) Thanks in advance for your help, guidelines & article links. Quote Link to comment https://forums.phpfreaks.com/topic/193549-zend-form-building-help/ Share on other sites More sharing options...
ignace Posted February 27, 2010 Share Posted February 27, 2010 class MyForm extends Zend_Form { const ELEMENT_DAY = 'day'; const ELEMENT_MONTH = 'month'; const ELEMENT_YEAR = 'year'; public function getDay() { return $this->getValue(self::ELEMENT_DAY); } public function getMonth() { return $this->getValue(self::ELEMENT_MONTH); } public function getYear() { return $this->getValue(self::ELEMENT_YEAR); } public function isValid($data) { $isValid = true; $day = $this->getDay(); $month = $this->getMonth(); $year = $this->getYear(); if (!checkdate($day, $month, $year)) { $isValid = false; $this->getElement(self::ELEMENT_DAY)->addError('Invalid date specified'); } return parent::isValid($data) && $isValid; } public function init() { $e = $this->createElement('Select', self::ELEMENT_DAY); $e->setMultiOptions(range(1, 31)); $this->addElement($e); $e = $this->createElement('Select', self::ELEMENT_MONTH); $e->setMultiOptions(array_combine(range(1, 12), range('January', 'December'))); $this->addElement($e); $e = $this->createElement('Select', self::ELEMENT_YEAR); $e->setMultiOptions(range(idate('Y') - 100, idate('Y'))); $this->addElement($e); } } Quote Link to comment https://forums.phpfreaks.com/topic/193549-zend-form-building-help/#findComment-1018959 Share on other sites More sharing options...
phpdeveloper82 Posted March 1, 2010 Author Share Posted March 1, 2010 Thank you for your help. Your code helps me to generate the form elements. I need to display all three "select" menus on the same row. Currently it returns like the format: <dt id="day-label"> <label for="day" class="required">Birthday:</label> </dt> <dd id="day-element"> <select name="day" id="day"> <option value="" label="Day:">Day:</option> <option value="0" label="1">1</option> </select> </dd> <dt id="month-label"> </dt> <dd id="month-element"> <select name="month" id="month"> <option value="" label="Month:">Month:</option> <option value="0" label="January">January</option> <option value="11" label="December">December</option> </select> </dd> <dt id="year-label"> </dt> <dd id="year-element"> <select name="year" id="year"> <option value="" label="Year:">Year:</option> <option value="0" label="1910">1910</option> </select> </dd> Please help me to change to the format: <dt id="day-label"> <label for="day" class="required">Birthday:</label> </dt> <dd id="day-element"> <select name="day" id="day"> <option value="" label="Day:">Day:</option> <option value="0" label="1">1</option> </select> <select name="month" id="month"> <option value="" label="Month:">Month:</option> <option value="0" label="January">January</option> <option value="11" label="December">December</option> </select> <select name="year" id="year"> <option value="" label="Year:">Year:</option> <option value="0" label="1910">1910</option> </select> </dd> Quote Link to comment https://forums.phpfreaks.com/topic/193549-zend-form-building-help/#findComment-1019785 Share on other sites More sharing options...
ignace Posted March 1, 2010 Share Posted March 1, 2010 To do that you first need to disable any and all decorators on the form elements: public function init() { $this->setDisableLoadDefaultDecorators(true); } Then for each element add the appropriate decorators like shown here: http://framework.zend.com/manual/en/zend.form.quickstart.html Quote Link to comment https://forums.phpfreaks.com/topic/193549-zend-form-building-help/#findComment-1019825 Share on other sites More sharing options...
phpdeveloper82 Posted March 1, 2010 Author Share Posted March 1, 2010 Thank you for your reply. I have searched on net the whole day and couldn't find any tutorial which helps me to do as I need. Also gone through the Decorator section in the ZF site also. Quote Link to comment https://forums.phpfreaks.com/topic/193549-zend-form-building-help/#findComment-1019855 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.