![]() |
[Closed] Codeigniter Validation Question - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: [Closed] Codeigniter Validation Question (/showthread.php?tid=60606) Pages:
1
2
|
[Closed] Codeigniter Validation Question - El Forum - 05-07-2014 [eluser]riwakawd[/eluser] I have the general codeigniter validation setup, but I am trying to add bootstrap input has error and has success. I have got the bootstrap has-error working. But trying to get it so i input is filed in correct it will show has-succes so input will turn green Code: <div class="form-group <?php if(validation_errors()) echo 'has-error'; {else} echo 'has-success'; ?> "> has-success not working. [Closed] Codeigniter Validation Question - El Forum - 05-08-2014 [eluser]Tim Brownlaw[/eluser] disclaimer: I'm only answering the question on the code provided. Ok so you are testing that validation_errors() returns a boolean result... So you need to understand what the function you are testing is going to return... In this case It's either a string or empty... - I've NOT looked in the code to make sure... which is something you should do to make 100% sure it's the case! You also need to check your PHP Syntax... ** I've not tested this code - it's a "it might work" suggestion to get you started... Code: <div class="form-group What you have there is an interesting way to do things... I've only broken the php code out to elaborate on the actual code used. The other way to try is... Code: <?php echo (validation_errors() != '')? 'has-error':'has-success'; ?> Cheers Tim [Closed] Codeigniter Validation Question - El Forum - 05-08-2014 [eluser]Tpojka[/eluser] Syntax was not valid regarding your request: Code: <?php if(validation_errors()) echo 'has-error'; {else} echo 'has-success'; ?> Tim already gave you the answer. [Closed] Codeigniter Validation Question - El Forum - 05-08-2014 [eluser]riwakawd[/eluser] [quote author="Tim Brownlaw" date="1399535438"]disclaimer: I'm only answering the question on the code provided. Ok so you are testing that validation_errors() returns a boolean result... So you need to understand what the function you are testing is going to return... In this case It's either a string or empty... - I've NOT looked in the code to make sure... which is something you should do to make 100% sure it's the case! You also need to check your PHP Syntax... ** I've not tested this code - it's a "it might work" suggestion to get you started... Code: <div class="form-group What you have there is an interesting way to do things... I've only broken the php code out to elaborate on the actual code used. The other way to try is... Code: <?php echo (validation_errors() != '')? 'has-error':'has-success'; ?> Cheers Tim[/quote] This works but is there also just away to make has-success show up only when start to type? I am trying to find a suitable javascript to match and work with codeigniter. Can Not seem to get javascript to work with codeigniter Code: <?php echo (validation_errors() != '')? 'has-error':'has-success'; ?> Code: [removed] [Closed] Codeigniter Validation Question - El Forum - 05-08-2014 [eluser]riwakawd[/eluser] I have it working with js now I added http://ajax.aspnetcdn.com/ajax/jquery.validate/1.12.0/jquery.validate.js [Closed] Codeigniter Validation Question - El Forum - 05-08-2014 [eluser]ivantcholakov[/eluser] jquery.validate plugin is nice, I used it as an addition to the server-side validation. But lately I conserve my time and I only implement the PHP-side validation, because it is the secure one. In CodeIgniter I use only the "has-error" class which is triggered when validation fails on a specific field. Code: <div class="form-group<?php if (!empty($validation_errors['username'])) { ?> has-error<?php } ?>"> $validation_errors is an array here. In CodeIgniter 3 it can be taken this way: $validation_errors = $this->form_validation->error_array(); [Closed] Codeigniter Validation Question - El Forum - 05-08-2014 [eluser]riwakawd[/eluser] [quote author="ivantcholakov" date="1399540972"]jquery.validate plugin is nice, I used it as an addition to the server-side validation. But lately I conserve my time and I only implement the PHP-side validation, because it is the secure one. In CodeIgniter I use only the "has-error" class which is triggered when validation fails on a specific field. Code: <div class="form-group<?php if (!empty($validation_errors['username'])) { ?> has-error<?php } ?>"> $validation_errors is an array here. In CodeIgniter 3 it can be taken this way: $validation_errors = $this->form_validation->error_array();[/quote] The reason why I used my javascript I found today is because it has both classes error and success. I had to add change it to work with bootstrap 3 and codeigniter. The way that @Tim Brownlaw was OK but has-success was staying there. The javascript only add class when OK. [Closed] Codeigniter Validation Question - El Forum - 05-08-2014 [eluser]ivantcholakov[/eluser] @riwakawd It is very easy the JavaScript validation to be bypassed (Firefox + Tamper plugin for example). Consider JavaScript validation as visual sugar, user experience improvement only. Validation on server-side always should be implemented. [Closed] Codeigniter Validation Question - El Forum - 05-08-2014 [eluser]riwakawd[/eluser] [quote author="ivantcholakov" date="1399577213"]@riwakawd It is very easy the JavaScript validation to be bypassed (Firefox + Tamper plugin for example). Consider JavaScript validation as visual sugar, user experience improvement only. Validation on server-side always should be implemented.[/quote] I want to be able to do it via server side can do it with input highlighted 'has-error' but the only issue I am having, is if input is filled in correct should be highlighted 'has-success'. Currently when use this <?php echo (validation_errors() != '')? 'has-error':'has-success'; ?> makes the input always highlighted 'has-success' when no error. if there was away to addClass and removeClass using that would be good. Working like the javascript but using codeigniter validation. [Closed] Codeigniter Validation Question - El Forum - 05-08-2014 [eluser]ivantcholakov[/eluser] I imagine that 'has-success' may be triggered on two conditions, when: 1. on the specific field there is no error; 2. the request method is 'POST', i.e. $this->input->method() == 'post' . When the validation fails, the fields will be repopulated, and the wrong field will get the attribute 'has-error' (red), the correct fields will get attribute 'has-success' (green). |