Changeset 1461

Show
Ignore:
Timestamp:
12/07/07 21:17:50 (9 months ago)
Author:
Shadowhand
Message:

Changes to Forge:

  • Resurrected and fixed up Form_Hidden
  • Changed Form_Hidden handling in Forge::call
  • Updated /forge_demo with hidden and Form_Dateselect demos
Location:
trunk/modules/forge
Files:
3 modified
1 copied

Legend:

Unmodified
Added
Removed
  • trunk/modules/forge/controllers/forge_demo.php

    r1460 r1461  
    1919        //   type($name)->attr(..)->attr(..); 
    2020        // 
     21        $form->hidden('hideme')->value('hiddenz!'); 
    2122        $form->input('email')->label(TRUE)->rules('required|valid_email'); 
    2223        $form->input('username')->label(TRUE)->rules('required|length[5,32]'); 
  • trunk/modules/forge/i18n/en_US/forge.php

    r1450 r1461  
    33$lang = array 
    44( 
     5    'invalid_input' => 'Invalid input type requested: %s', 
    56    'address_unit' => 'Unit #', 
    67    'address_city' => 'City', 
  • trunk/modules/forge/libraries/Forge.php

    r1459 r1461  
    2828            return $this->inputs[$key]; 
    2929        } 
     30        elseif (isset($this->hidden[$key])) 
     31        { 
     32            return $this->hidden[$key]; 
     33        } 
    3034    } 
    3135 
    3236    public function __call($method, $args) 
    3337    { 
    34         if ($method == 'hidden') 
    35         { 
    36             $this->hidden[$args[0]] = $args[1]; 
    37             return; 
    38         } 
    3938        // Class name 
    4039        $input = 'Form_'.ucfirst($method); 
    4140 
    4241        // Create the input 
    43         $input = new $input(empty($args) ? NULL : current($args)); 
     42        switch(count($args)) 
     43        { 
     44            case 1: 
     45                $input = new $input($args[0]); 
     46            break; 
     47            case 2: 
     48                $input = new $input($args[0], $args[1]); 
     49            break; 
     50        } 
    4451 
    4552        if ( ! ($input instanceof Form_Input)) 
    46             throw new Kohana_Exception('forge.invalid_input'); 
     53            throw new Kohana_Exception('forge.invalid_input', get_class($input)); 
    4754 
    4855        if ($name = $input->name) 
    4956        { 
    50             // Assign by name 
    51             $this->inputs[$name] = $input; 
     57            if ($method == 'hidden') 
     58            { 
     59                $this->hidden[$name] = $input; 
     60            } 
     61            else 
     62            { 
     63                // Assign by name 
     64                $this->inputs[$name] = $input; 
     65            } 
    5266        } 
    5367        else 
     
    7993 
    8094        $data = array(); 
    81         foreach($this->inputs as $input) 
     95        foreach(array_merge($this->hidden, $this->inputs) as $input) 
    8296        { 
    8397            if ($name = $input->name) 
     
    95109        $form = new View($template, $this->template); 
    96110 
     111        $hidden = array(); 
     112        if ( ! empty($this->hidden)) 
     113        { 
     114            foreach($this->hidden as $input) 
     115            { 
     116                $hidden[$input->name] = $input->value; 
     117            } 
     118        } 
     119 
    97120        // Set the form open and close 
    98         $form->open  = form::open($form->action, array('method' => 'post'), $this->hidden); 
     121        $form->open  = form::open($form->action, array('method' => 'post'), $hidden); 
    99122        $form->close = form::close(); 
    100123 
  • trunk/modules/forge/libraries/Form_Hidden.php

    r1452 r1461  
    99    ); 
    1010 
    11     protected $protect = array('type'); 
     11    protected $protect = array('type', 'label'); 
    1212 
    13     protected function html_element() 
     13    public function html() 
    1414    { 
    1515        $data = $this->data; 
    16  
    17         unset($data['label']); 
    1816 
    1917        return form::hidden($data);