[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>
<?php foreach($fields as $field => $type): ?>
<?php $field_error = $field."_error"; ?>
<label><?=$this->lang->line($field)?> <span class="error"><?=$this->validation->$field_error?></span></label><br />
<?php switch($type):
default: ?>
<?php break; ?>
<?php case 'text': ?>
<input type="text" name="<?=$field?>" value="<?=$this->validation->$field ?>" /><br />
<?php break; ?>
<?php case 'textarea': ?>
<textarea name="<?=$field?>"><?=$this->validation->$field ?></textarea><br />
<?php endswitch ?>
<?php endforeach ?>
<br />
<input type="submit" class="button" value="<?=$submit_val?>" />
</fieldset>
</form>