Example #1
0
 /**
  * Exports the value.
  *
  * If the other value is set, this will be exported if in singular mode
  * and the other radio button is selected.  Otherwise if in multiple mode
  * the other value is added to the array of values.
  *
  * @param   array   $submitValues submitValues values submitted
  * @param   bool    $assoc        propagate on to 
  *                                HTML_QuickForm_select::exportValue()
  * @access  public
  * @return  mixed   Single value or array of values
  */
 function exportValue(&$submitValues, $assoc = false)
 {
     if (!$this->includeOther) {
         return parent::exportValue($submitValues, $assoc);
     }
     if ($this->getMultiple()) {
         // kinda defeats the purpose of using exportValue to return only
         // allowed options
         $value = $this->_findValue($submitValues);
         // if nothing was posted, then grab the defaults
         if (is_null($value)) {
             $value = $this->getValue();
         }
         // _findValue may return a scalar if that's what was posted
         if (is_array($value)) {
             // remove the empty string from the other option
             foreach ($value as $key => $item) {
                 if ($item === '') {
                     unset($value[$key]);
                 }
             }
         } else {
             // if a scalar, force an array to be exported
             $value = array($value);
         }
         return $this->_prepareValue($value, $assoc);
     } else {
         // NB: If an array was submitted with an other value, then it will
         // not be exported, as we're expecting '_qf_other' to be submitted
         // in singular mode.
         $myName = $this->getName();
         // XXX
         $this->addOption(null, '_qf_other');
         $value = parent::exportValue($submitValues, $assoc);
         // XXX
         array_pop($this->_options);
         if (is_array($value) && $value[$myName] == '_qf_other' || $value == '_qf_other') {
             if (isset($submitValues[$myName . '_qf_other'])) {
                 $value = $submitValues[$myName . '_qf_other'];
             } else {
                 $value = $this->_otherValue;
             }
         }
         return $this->_prepareValue($value, $assoc);
     }
 }