form_validation, styling question |
[eluser]questionmark[/eluser]
Hello@all, how could I add a class value to an input-field if an error occurs? view: Code: <? echo form_label('Firstname*','firstname'); ?> <br /> controller: Code: $this->form_validation->set_rules('firstname', 'Firstname', 'required'); i'd like to have this output, if no input for firstname is given ... Code: <label for="vorname">Vorname*</label> <br /> so a class value => form-error Thanks for your help.
[eluser]Dam1an[/eluser]
FIrst of all, I'm not sure if you really need to, is it not sufficient to just show an individual form error? If you need to (eg if you want a red border on the field) you could maybe try something like Code: <input type="text" name="vorname" <?=(form_error('firstname') != '') ? 'class="form-error"' : ''?> /> You could probably do the same sort of thing with the input helper, but I don't use it, and not going to embarass myself trying
[eluser]questionmark[/eluser]
Hi! Thanks ok in this way ... Code: $data = array('name' => 'firstname', 'id' => 'firstname', 'maxlength' => '50', 'size' => '50'); but my form_error('firstname') ... is always '' ... here is my controller code ... Code: $this->load->library(array('form_validation')); thanks for your help.
[eluser]TheFuzzy0ne[/eluser]
Code: $data = array('name' => 'vorname', 'id' => 'vorname', 'maxlength' => '50', 'size' => '50');
[eluser]questionmark[/eluser]
but my form_error(‘firstname’) ... is always false ... why?
[eluser]questionmark[/eluser]
Ok because of this two lines of code ... Code: $this->session->set_flashdata('message', 'wrong'); is this no good way to display an errormessage in combination with form_validation?
[eluser]TheFuzzy0ne[/eluser]
OK, I'm confused. I don't understand where flashdata comes into this, for starters, but I'm more confused about what the input name attributes are in your view, and what you're using in your validation. I see vorname and firstname, which one are you using?
[eluser]questionmark[/eluser]
I use vorname ... but I wanted to post it in english ... firstname, I mixed it up a little bit ;-) sorry! i use now the german version -> vorname Nevertheless I've fix my problem in this way ... maybe it will be give an better one? instead of setting flashdata I use a model var $message ... controller: Code: $this->load->library(array('form_validation')); view: Code: ...
[eluser]TheFuzzy0ne[/eluser]
If you want to change the message, you can override it via ./system/application/language/german/form_validation.php. You'll need to create the directory and the structure and then just make a copy of the english file into the german subdirectory, and then edit it. You'll then need to set your default language in the config.php file. Ideally, it should have been set up like this to begin with. Another alternative, might be to us a callback method. Code: function valid_vorname($str="") You can also add any further validation you want. Then you can just set your rule like this: Code: $this->form_validation->set_rules('vorname', 'Vorname', 'callback_valid_vorname'); Hope this helps.
|
Welcome Guest, Not a member yet? Register Sign In |