0
我有一個標籤爲「amenities []」的下拉列表,它是一個數組。當我使用CodeIgniter的form_validation時,我想使用set_value正確地重新填充它,但我無法。任何人對此有任何意見?如何使用CodeIgniter的set_value作爲數組的字段?
我有一個標籤爲「amenities []」的下拉列表,它是一個數組。當我使用CodeIgniter的form_validation時,我想使用set_value正確地重新填充它,但我無法。任何人對此有任何意見?如何使用CodeIgniter的set_value作爲數組的字段?
縱觀源Codeignitor 1.7.2 SET_VALUE實現:
/**
* Get the value from a form
*
* Permits you to repopulate a form field with the value it was submitted
* with, or, if that value doesn't exist, with the default
*
* @access public
* @param string the field name
* @param string
* @return void
*/
function set_value($field = '', $default = '')
{
if (! isset($this->_field_data[$field]))
{
return $default;
}
return $this->_field_data[$field]['postdata'];
}
注意它不支持數組。另一方面,Codeignitor的set_select確實支持陣列:
// --------------------------------------------------------------------
/**
* Set Select
*
* Enables pull-down lists to be set to the value the user
* selected in the event of an error
*
* @access public
* @param string
* @param string
* @return string
*/
function set_select($field = '', $value = '', $default = FALSE)
{
if (! isset($this->_field_data[$field]) OR ! isset($this->_field_data[$field]['postdata']))
{
if ($default === TRUE AND count($this->_field_data) === 0)
{
return ' selected="selected"';
}
return '';
}
$field = $this->_field_data[$field]['postdata'];
if (is_array($field))
{
if (! in_array($value, $field))
{
return '';
}
}
else
{
if (($field == '' OR $value == '') OR ($field != $value))
{
return '';
}
}
return ' selected="selected"';
}
非常感謝!此評論'允許你重新填充表單字段與它提交 值*與,或,如果該值不存在,與default'簡直是我想要的。 – Sobiaholic 2013-10-13 13:38:51