Ejemplo n.º 1
0
 /**
  * Create a new form, with the given fields an action buttons.
  * @param controller The parent controller, necessary to create the appropriate form action tag.
  * @param name The method on the controller that will return this form object.
  * @param fields All of the fields in the form - a {@link FieldSet} of {@link FormField} objects.
  * @param actions All of the action buttons in the form - a {@link FieldSet} of {@link FormAction} objects
  */
 function __construct($controller, $name, FieldSet $fields, FieldSet $actions, $validator = null)
 {
     parent::__construct();
     foreach ($fields as $field) {
         $field->setForm($this);
     }
     foreach ($actions as $action) {
         $actions->setForm($this);
     }
     $this->fields = $fields;
     $this->actions = $actions;
     $this->controller = $controller;
     $this->name = $name;
     // Form validation
     if ($validator) {
         $this->validator = $validator;
         $this->validator->setForm($this);
     }
     // Form error controls
     $errorInfo = Session::get("FormInfo.{$this->FormName()}");
     if (isset($errorInfo['errors']) && is_array($errorInfo['errors'])) {
         foreach ($errorInfo['errors'] as $error) {
             $field = $this->fields->dataFieldByName($error['fieldName']);
             if (!$field) {
                 $errorInfo['message'] = $error['message'];
                 $errorInfo['type'] = $error['messageType'];
             } else {
                 $field->setError($error['message'], $error['messageType']);
             }
         }
         // load data in from previous submission upon error
         if (isset($errorInfo['data'])) {
             $this->loadDataFrom($errorInfo['data']);
         }
     }
     if (isset($errorInfo['message']) && isset($errorInfo['type'])) {
         $this->setMessage($errorInfo['message'], $errorInfo['type']);
     }
 }
Ejemplo n.º 2
0
	/**
	 * Create a new form, with the given fields an action buttons.
	 * 
	 * @param Controller $controller The parent controller, necessary to create the appropriate form action tag.
	 * @param String $name The method on the controller that will return this form object.
	 * @param FieldSet $fields All of the fields in the form - a {@link FieldSet} of {@link FormField} objects.
	 * @param FieldSet $actions All of the action buttons in the form - a {@link FieldSet} of {@link FormAction} objects
	 * @param Validator $validator Override the default validator instance (Default: {@link RequiredFields})
	 */
	function __construct($controller, $name, FieldSet $fields, FieldSet $actions, $validator = null) {
		parent::__construct();

		foreach($fields as $field) $field->setForm($this);
		foreach($actions as $action) $actions->setForm($this);

		$this->fields = $fields;
		$this->actions = $actions;
		$this->controller = $controller;
		$this->name = $name;
		
		if(!$this->controller) user_error("$this->class form created without a controller", E_USER_ERROR);

		// Form validation
		$this->validator = ($validator) ? $validator : new RequiredFields();
		$this->validator->setForm($this);

		// Form error controls
		$this->setupFormErrors();
		
		$this->security = self::$default_security;
	}
Ejemplo n.º 3
0
 /**
  * Create a new form, with the given fields an action buttons.
  * 
  * @param Controller $controller The parent controller, necessary to create the appropriate form action tag.
  * @param String $name The method on the controller that will return this form object.
  * @param FieldSet $fields All of the fields in the form - a {@link FieldSet} of {@link FormField} objects.
  * @param FieldSet $actions All of the action buttons in the form - a {@link FieldSet} of {@link FormAction} objects
  * @param Validator $validator Override the default validator instance (Default: {@link RequiredFields})
  */
 function __construct($controller, $name, FieldSet $fields, FieldSet $actions, $validator = null)
 {
     parent::__construct();
     if (!$fields instanceof FieldSet) {
         throw new InvalidArgumentException('$fields must be a valid FieldSet instance');
     }
     if (!$actions instanceof FieldSet) {
         throw new InvalidArgumentException('$fields must be a valid FieldSet instance');
     }
     if ($validator && !$validator instanceof Validator) {
         throw new InvalidArgumentException('$validator must be a Valdidator instance');
     }
     $fields->setForm($this);
     $actions->setForm($this);
     $this->fields = $fields;
     $this->actions = $actions;
     $this->controller = $controller;
     $this->name = $name;
     if (!$this->controller) {
         user_error("{$this->class} form created without a controller", E_USER_ERROR);
     }
     // Form validation
     $this->validator = $validator ? $validator : new RequiredFields();
     $this->validator->setForm($this);
     // Form error controls
     $this->setupFormErrors();
     // Check if CSRF protection is enabled, either on the parent controller or from the default setting. Note that
     // method_exists() is used as some controllers (e.g. GroupTest) do not always extend from Object.
     if (method_exists($controller, 'securityTokenEnabled')) {
         $this->security = $controller->securityTokenEnabled();
     } else {
         $this->security = self::$default_security;
     }
 }