Back to Form class

Method setValue

public bool
setValue
(mixed $name, mixed $group = null, mixed $value = null)
Method to set the value of a field. If the field does not exist in the form then the method will return false.
Parameters
  • string $name The name of the field for which to set the value.
  • string $group The optional dot-separated form group path on which to find the field.
  • mixed $value The value to set for the field.
Returns
  • bool True on success.
Since
  • 1.7.0
Class: Form
Project: Joomla

Method setValue - Source code

/**
 * Method to set the value of a field. If the field does not exist in the form then the method
 * will return false.
 *
 * @param   string  $name   The name of the field for which to set the value.
 * @param   string  $group  The optional dot-separated form group path on which to find the field.
 * @param   mixed   $value  The value to set for the field.
 *
 * @return  boolean  True on success.
 *
 * @since   1.7.0
 */
public function setValue($name, $group = null, $value = null)
{
    // If the field does not exist return false.
    if (!$this->findField($name, $group)) {
        return false;
    }
    // If a group is set use it.
    if ($group) {
        $this->data->set($group . '.' . $name, $value);
    } else {
        $this->data->set($name, $value);
    }
    return true;
}