55 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
			
		
		
	
	
			55 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
<?php
 | 
						|
 | 
						|
namespace Artmark\Forms\Fields;
 | 
						|
 | 
						|
use Artmark\Forms\AbstractField;
 | 
						|
 | 
						|
/**
 | 
						|
 * Description of HiddenField
 | 
						|
 *
 | 
						|
 * @author Andrey Pokidov <pokidov@e-traffic.ru>
 | 
						|
 */
 | 
						|
class HiddenField extends AbstractField
 | 
						|
{
 | 
						|
    private $value;
 | 
						|
    
 | 
						|
    public function __construct($form, $name, $value = '')
 | 
						|
    {
 | 
						|
        parent::__construct($form, 'hidden', $name);
 | 
						|
        
 | 
						|
        $this->setValue($value);
 | 
						|
    }
 | 
						|
    
 | 
						|
    /**
 | 
						|
     * Возвращает значение поля
 | 
						|
     * @return string
 | 
						|
     */
 | 
						|
    public function value()
 | 
						|
    {
 | 
						|
        return $this->value;
 | 
						|
    }
 | 
						|
    
 | 
						|
    /**
 | 
						|
     * Задаёт новое значение для поля типа hidden
 | 
						|
     * @param string|int|float $newValue
 | 
						|
     * @return $this
 | 
						|
     */
 | 
						|
    public function setValue($newValue)
 | 
						|
    {
 | 
						|
        if (is_string($newValue) || is_numeric($newValue)) {
 | 
						|
            $this->value = strval($newValue);
 | 
						|
        }
 | 
						|
        
 | 
						|
        return $this;
 | 
						|
    }
 | 
						|
    
 | 
						|
    public function getAssociativeAttributes()
 | 
						|
    {
 | 
						|
        $attributes = parent::getAssociativeAttributes();
 | 
						|
        
 | 
						|
        $attributes['value'] = $this->value;
 | 
						|
        
 | 
						|
        return $attributes;
 | 
						|
    }
 | 
						|
}
 |