I've got this code:
Code:
$in = $this->getInput();
$clean = array('txtTitle' => $this->_escape($in->getRaw('txtTitle')) or '',
'selClient' => $in->getInt('selClient') or 0,
'selSubclient' => $in->getInt('selSubclient') or 0,
'fsVideo' => $in->getInt('fsVideo') or true,
'txtUrlStream' => $this->_escape($in->getRaw('txtUrlStream')) or '',
'txtUrlDownload' => $this->_escape($in->getRaw('txtUrlDownload')) or '',
'txtWidth' => $this->getInt('txtWidth') or 0,
'txtHeight' => $this->getInt('txtHeight') or 0,
'txtMsgFeedback' => $this->_escape($in->getRaw('txtMsgFeedback')) or '',
'txtMsgStream' => $this->_escape($in->getRaw('txtMsgStream')) or '',
'txtMsgDownload' => $this->_escape($in->getRaw('txtMsgDownload')) or '',
'fsQuestionnaire' => $this->getInt('fsQuestionnaire') or true,
'txtMsgOnStart' => $this->_escape($in->getRaw('txtMsgOnStart')) or '',
'txtMsgOnceFinished' => $this->_escape($in->getRaw('txtMsgOnceFinished')) or '');
$clean = (object)$clean;
It's getting posted values from a form or if they aren't present assigning them with a default.
However there are a couple of problems:- The first line ($in = $this->getInput();) can fail, as in return NULL, if the form hasn't been posted in which case $in->getRaw('txtTitle') generates an E_FATAL because $in isn't an object.
- I can't make the assignment of $clean conditional based on $in because then my defaults wouldn't be assigned.
So basically I'm looking for a nice solution for managing default values where form isn't posted or any single field isn't posted.
Bookmarks