Welcome Guest, Not a member yet? Register   Sign In
XHTML Presentation of froms
#8

[eluser]breaddes[/eluser]
ok, this is the way i am doing my form now. What do you think about it?

Controller
Code:
$data['headline'] = $this->lang->line('centers_add');
$data['action_url'] = 'centers/add';
$data['reset_url'] = 'centers';
$data['fields'] =& $fields;
$data['submit_val'] = $this->lang->line('add');
        
$fields['place'] = 'text';
$fields['address'] = 'text';
$fields['postcode'] = 'text';
$fields['city'] = 'text';
$fields['phone'] = 'text';
$fields['web'] = 'text';
        
$basic_rule = "htmlspecialchars|trim|required|min_length[2]";
        
$rules['name'] = "max_length[1]";
$rules['place'] = $rules['address'] = $rules['city'] = $basic_rule;
$rules['county'] = $rules['phone'] = $basic_rule;
$rules['postcode'] = $basic_rule."|numeric|max_length[5]";
$rules['web'] = "htmlspecialchars|trim|min_length[2]";
        
$this->validation->set_fields($fields);
$this->validation->set_rules($rules);
        
$this->validation->set_message('required', $this->lang->line('short'));
$this->validation->set_message('min_length', $this->lang->line('short'));
$this->validation->set_message('max_length', $this->lang->line('long'));
$this->validation->set_message('numeric', $this->lang->line('numeric'));

View
Code:
<form action="<?=base_url().$action_url?>" id="form" method="post">
        <fieldset>
            &lt;?php foreach($fields as $field => $type): ?&gt;
                &lt;?php $field_error = $field."_error"; ?&gt;
                
                <label>&lt;?=$this->lang->line($field)?&gt; <span class="error">&lt;?=$this->validation->$field_error?&gt;</span></label><br />
                
                &lt;?php switch($type):
                    default: ?&gt;
                    &lt;?php break; ?&gt;
                    &lt;?php case 'text': ?&gt;
                        &lt;input type="text" name="&lt;?=$field?&gt;" value="&lt;?=$this-&gt;validation->$field ?&gt;" /><br />
                    &lt;?php break; ?&gt;
                    &lt;?php case 'textarea': ?&gt;
                        &lt;textarea name="&lt;?=$field?&gt;"&gt;&lt;?=$this->validation->$field ?&gt;&lt;/textarea&gt;<br />
                &lt;?php endswitch ?&gt;
            &lt;?php endforeach ?&gt;

            <br />
            &lt;input type="submit" class="button" value="&lt;?=$submit_val?&gt;" /&gt;
        </fieldset>
    &lt;/form&gt;


Messages In This Thread
XHTML Presentation of froms - by El Forum - 02-08-2008, 05:29 AM
XHTML Presentation of froms - by El Forum - 02-08-2008, 06:22 AM
XHTML Presentation of froms - by El Forum - 02-08-2008, 06:27 AM
XHTML Presentation of froms - by El Forum - 02-08-2008, 06:44 AM
XHTML Presentation of froms - by El Forum - 02-08-2008, 06:48 AM
XHTML Presentation of froms - by El Forum - 02-08-2008, 06:52 AM
XHTML Presentation of froms - by El Forum - 02-08-2008, 07:02 AM
XHTML Presentation of froms - by El Forum - 02-11-2008, 12:24 PM



Theme © iAndrew 2016 - Forum software by © MyBB