views:

159

answers:

1

This is a very specific instance where I'm having difficulty getting Zend Form to produce the correct output and supply the correct validation. I may have to go create a composite element but thought I'd ask here first. Here is the HTML I'm trying to get Zend Form to produce. I'd like this to be able to work where if the validation doesn't pass that the error messages still show up inline with the field that produced the error.

<tr>
    <td>Budget</td>
    <td>
        <input type="radio" name="budget" value="unlimited" /> unlimited
        <br />
        <input type="radio" name="budget" value="limited" /> $ <input type="text" name="budget_amount" /> every <select name="budget_period">
            <option value="day">day</option>
            <option value="week">week</option>
            <option value="month">month</option>
            <option value="year">year</option>
        </select>
    </td>
</tr>
<tr>
    <td></td>
    <td><input type="checkbox" name="include_weekends" value="yes" /> include weekends?</td>
</tr>

The user can choose either unlimited or limited for the budget value, however, if they choose limited, then they are required to enter a value for the budget amount field and choose a value from the select for the budget period field.

A: 

Figured it out after lots of tweaking, but hopefully the answer will help someone else out. Just going to post the decorator stuff since I'm still working on the validation for the budget value (got it to work by overriding form's isValid() function but now trying to get it into a custom validator).

    $this->setElementDecorators(array(
        'ViewHelper',
        array(array('data' => 'HtmlTag'), array('tag' => 'td')),
        array('Label', array('tag' => 'td')),
        array(array('row' => 'HtmlTag'), array('tag' => 'tr'))
    ));

    $budget->setDecorators(array(
        'ViewHelper',
        array(array('openData' => 'HtmlTag'), array('tag' => 'td', 'openOnly' => true)),
        array('Label', array('tag' => 'td')),
        array(array('openRow' => 'HtmlTag'), array('tag' => 'tr', 'openOnly' => true))
    ));

    $budgetAmount->setDecorators(array(
        'ViewHelper'
    ));

    $budgetPeriod->setDecorators(array(
        'ViewHelper',
        array('AnyMarkup', array('markup' => 'every', 'placement' => 'PREPEND')),
        array(array('closeData' => 'HtmlTag'), array('tag' => 'td', 'closeOnly' => true)),
        array(array('closeRow' => 'HtmlTag'), array('tag' => 'tr', 'closeOnly' => true))
    ));

    $includeWeekends->setDecorators(array(  
        'ViewHelper',
        array('Label', array('placement' => 'APPEND')),
        array(array('data' => 'HtmlTag'), array('tag' => 'td')),
        array(array('emptyRow' => 'HtmlTag'), array('tag' => 'td', 'placement' => 'PREPEND')),
        array(array('row' => 'HtmlTag'), array('tag' => 'tr'))
    ));

    $this->setDecorators(array(
        'FormElements',
        array('HtmlTag', array('tag' => 'table')),
        'Form',
        array('FormErrors', array('placement' => 'PREPEND', 'class' => 'error')),
        array('Description', array('placement' => 'PREPEND'))
    ));
Jeremy Hicks