Jump to content

Recommended Posts

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.

 

 

Link to comment
https://forums.phpfreaks.com/topic/193549-zend-form-building-help/
Share on other sites

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);
    }
}

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>




 

 

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.