Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I set the 'value' in my Zend form checkbox?
    primarykey
    data
    text
    <p>The Zend Form is proving to be a bit tricky for me, even as much as I am working with it lately...</p> <p>I have this form and I am attempting to dynamically create the several checkboxes for it. It is working out alright, except I cannot seem to get the 'value' attribute to change.</p> <p>In my Zend form class I have this snippet...</p> <pre><code>// psychotic symptoms $this-&gt;addElement('checkbox', 'psychoticsymptom', array( 'label' =&gt; 'psychoticsymptom', 'name' =&gt; 'psychoticsymptom', )); </code></pre> <p>In my view (phtml) I am calling it like this...</p> <pre><code>&lt;div class="element"&gt; &lt;?php // Psychotic Symptoms $Criteria = new Criteria(); $Criteria-&gt;add( DictionaryPeer::CATEGORY, 'MAR: Psychotic Symptoms' ); $Criteria-&gt;addAscendingOrderByColumn( 'Ordinal' ); $this-&gt;PsychoticSymptomsList = DictionaryPeer::doSelect( $Criteria ); foreach( $this-&gt;PsychoticSymptomsList as $Symptom ) { $form-&gt;psychoticsymptom-&gt;setValue($Symptom-&gt;getDictionaryId()); $form-&gt;psychoticsymptom-&gt;setAttrib('name', $Symptom-&gt;getWord()); echo $Symptom-&gt;getDictionaryId(); // prove my id is coming through... (it is) $form-&gt;psychoticsymptom-&gt;getDecorator('label')-&gt;setTag(null); echo $form-&gt;psychoticsymptom-&gt;renderViewHelper(); $form-&gt;psychoticsymptom-&gt;setLabel($Symptom-&gt;getWord()); echo $form-&gt;psychoticsymptom-&gt;renderLabel(); echo '&lt;br /&gt;'; } ?&gt; &lt;/div&gt; </code></pre> <p>Everything seems to be working fine, except the value attribute on each checkbox is rendering a value of '1'. I have tried moving the 'setValue' line to several different positions, as to set the value before the form element renders but I am having no luck getting this to work. It's worth any effort to me because I need to do the same type of operation in many areas of my application. I would have done this a bit different too, but I am re-factoring another application and am trying to keep some things unchanged (like the database for instance).</p> <p>Any help is much appriciated Thanks</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload