Set Form Validation Rules For CodeIgniter Dynamically ?

With the new version of CodeIgniter you can only set rules in a static form_validation.php file. I need to analyze the posted info, i.e, only if they select a checkbox, only then do I want certain fields to be validated.What's the best way to do that? Or do I must use the old form validation class (which is deprecated now)


Codeigniter Form Validation Rules?

What does the trim form validation rule actually do and when should I use it?

View 2 Replies View Related

Form Validation With Rules?

I'm writing and app in PHP. I want to use jquery form validation but the situation I have are 'from' and 'to' fields. If one of these used and the other is blank I want to stop the form submit. So user can only submit the form if to and from are either both empty or both contain dates.Here are the fields:

<table class="search-form">

View 2 Replies View Related

Put Form Validation Rules In The Controller Or Model?

On one hand form validation could be seen as part of the application logic and therefore belonging in the model.On the other hand, it deals directly with the input coming from view and handles displaying errors, etc. From that angle it makes more sense to put it into controllers.Which one is the right approach from the MVC point of view?P.S my form validation actually consists only of writing a list of fields, their rules, and passing it on to a form validation library, which returns true/false on whether it passed validation or not.Example:

$this->form_validation->set_rules('name', 'Name', 'required');
$this->form_validation->set_rules('email', 'Email', 'required|valid_email');


View 3 Replies View Related

Setting Form Validation Rules For Form_radio()?

I want to have a form_radio() set as obligatory field in codeigniter any ideas on how can I do that?this is my form:

echo form_radio('radio','earing',FALSE)."earings";
echo form_radio('radio','bag',FALSE)."bag";

View 4 Replies View Related

Codeigniter Form Validation -unset Form Values After Success?

I realise this request goes against the example provided in the CI documentation (which advises a separate 'success' page view), but I would like to reutilise a given form view after a form has been successfully submitted - displaying a success message then displaying a blank form. I've tried a few ways unsuccessfully to clear the validation set values (unsetting $_POST, setting rules / fields to an empty array and rerunning validation). I could redirect to the same page, but then I'd have to set a session variable to display a success message - which is a messy approach.

View 3 Replies View Related

Form Validation With JQuery And Codeigniter?

Is there any tutorial or other helpful resource to create form validation with jQuery using Codeigniter 2.0.2I have been searching but didnt find any. As I've just started learning Codeigniter, I'd prefer to have some helpful tutorial or any resource instead of already built-in liberary.

View 2 Replies View Related

Codeigniter Realtime Form Validation?

I wanting to validate my forms via ajax (jquery library). Basically I have a form, that takes a password, this needs to be a minimum of 6 letters longs. Currently I have the validation rule set as this,

$this->form_validation->set_rule('password', 'passswprd', 'required|min_length[6]|trim')

This works fine when submitted using traditional submition through PHP and POST. However is there a way I can run my validation each time the users changes that field they are focused on?

View 1 Replies View Related

Re - Populatin Form With Codeigniter Validation?

Im using Codeigniter Form Validation class to validate some forms. The forms are used to store info on a db. Im using the following code, to load all the values into the fields:

PHP Code:

<?php echo ($ae == 'edit') ? form_input('name',$records[0]->name) : form_input('name', set_value('name')); ?>

So, if we are Editing the form, we load it with the value from the db. If we are Adding, we use the set_value() function to set the value in case that an error msg appeared.

This works ok. But I want to see if there's a better way of writting that line or doing this. For example, one of the problems of this approach is that, if im editing a form and after submitting it I get an error, I lose all the info I just modified, and the db info is restored. Not a big deal though.

View 3 Replies View Related

Form Validation Using Javascript In Codeigniter

i have a jquery table populate from datebase:

$attributes = array('name' => 'users');
echo form_open('users/action',$attributes);?>
<table class="data display datatable" id="example">

as you can see below,, i use checkID[] so that i can get every id of each user. i did make a onlick on edit button so that it will check if the id is empty or not. heres my js function


the problem now is that it will still alert even i check one user in the table.. even i use this:


View 1 Replies View Related

Codeigniter Form Validation (mysql Check)?

I'm learning CI as we speak, and I've got a quick question for you guys. I'm currently using the form_validation function to help me with some quick validations. This works fine, but! If i wanted to validate a username or email that is already in use, how can i do this?

I'm guessing that i need a model and a method that check's if the username or email is already in use. But how can i combine the false/true result given with the form_validation error messages?

View 2 Replies View Related

Codeigniter Form Validation To Model Logic?

I'm working on my first codeigniter application and have encountered some confusion around handling post data.

More specifically, I understand the role of $this->form_validation->set_rules(), and how set_value() works to repopulate input values when the validation failed, but what I can't figure out is if $this->input->post is the same value as the set_value equivalent.

I understand that the majority of validation rules would have a boolean result, however what about ones like trim|htmlspecialchars - these also have the benefit of preparing the data for db queries.

So in my model, can I access the inputs after being processed by the form_validation library, or should I do the additional preparation inside the model directly onto $this->input->post('variable')?

My gut tells me that I should add final processing like htmlspecialchars right before the sql in the model, as it is really a db specific operation (I would not want & instead of & in my form inputs, but I would want & in the database).

Incidentally in my reading I did come across $this->validation->variable which would appear to have been the answer to my question in previous CI versions.

View 2 Replies View Related

Codeigniter - Form Validation Callback Order

I have the following form validation rules:

$this->form_validation->set_rules('timeStart', 'Day Start Time', 'trim|required|xss_clean|callback_validtime');
$this->form_validation->set_rules('timeEnd', 'Day End Time', 'trim|required|xss_clean|callback_validtime|callback_validtimeorder');
$this->form_validation->set_rules('interval', 'Interval', 'trim|required|xss_clean|is_natural|callback_valid_interval');

The problem I have is that callback_valid_interval requires that $this->input->post('timeStart') and $this->input->post('timeEnd') are set. Currently my callback_valid_interval function errors if the user has not completed the timeStart or timeEnd. Is there any way I can set a dependency between the rules i.e. dont run the callback_valid_interval if the other rules have not passed? Alternatively I can put in a manual check for these fields but was wondering if there is a better way to do this?

View 3 Replies View Related

Codeigniter Form Validation With Ajax Failing?

I am trying to validate a form and save it in my database. I am using codeigniter's validation library and it fails.

this is the ajax function inside the view

function save_form(){
url: '/projects/cafe/index.php/welcome/save_form',
type: 'post',
data: {'fname' : $('#fname').val(),
'lname' : $('#lname').val(),


View 1 Replies View Related

Way To Disallow Word In Codeigniter's Built In Form Validation?

O have a form that the fields are prefilled by jQuery. When a user clicks in the field, the field empties itself, and they type their information. However if they don enter information in each filed the default value is submitted. I would like to use Codeigniter's built in validation to disallow users creating an account with a first name of "First Name".See here:

View 3 Replies View Related

Codeigniter Form Validation Callback Function Not Working?

I've written a simple callback function which isn't working. My other callbacks (which are in the same library file) work fine so I guess the problem has to do with my code.The parameter passed in the callback function takes the form of a chunk of PHP which is eval()'ed to form part of an 'if()' statement in the function itself.Here's what's in the controller:

$this->form_validation->set_rules('rating', 'Rating','required');
$condition = $this->input->post('rating') . " != 'Excellent'";
$this->form_validation->set_rules('details', 'Details', 'required_conditional[' . htmlentities


View 3 Replies View Related

Codeigniter - Repopulating Form On Failed Validation After Submitting

I have a form that requires the user to enter some information. If they fail to complete the required fields they are re-presented with the form; the top of the page notifying them what fields are required and I've enabled sticky forms (set_value()) so their input is not lost. I'm using flashdata to display messages to the user (i.e., if what they've entered already exists in the database).

My form is in the index method of my controller. When submit is clicked from my view it calls the add() method in my controller. The add() method performs the validation and depending on the results either submits to the database or kicks back out to the user to get more data. I have several issues with the way that i've done this.

1. If validation fails I'm using $this->index() to get back to my form and display the validation errors. If I try using redirect, I lose my validation errors and my $_POST[] data so my sticky forms end up blank.
2. Using $this->index() appends the 'add' to the end of my url
3. Using $this->index() causes issues with the flashdata. Random results.

class Restaurant extends Controller {
function Restaurant() {
function index() {
// Load libraries and models

View 4 Replies View Related

Codeigniter's Form Validation Library Handle Xss Filtering?

The codeigniter form validation library provides the option to 'prep' data from a form that is being validated. The following is a snippet from the documentation:

$this->form_validation->set_rules('username', 'Username', 'trim|required|min_length[5]|max_length[12]|xss_clean');

The xss_clean parameter at the end supposedly passes the post data through the xss_clean function.I am wondering how then do I use the POST data 'username'? Did the xss_clean function act directly on the POST variable so that I may then do: $username = $this->input->post('username'); and actually get the filtered data? What if I place that last statement before the validation line: will $username contain unfiltered data in this case?

View 3 Replies View Related

Manipulating Input Before Using It With CodeIgniter's Form Validation Class?

Since you can't do this: $this->form_validation->set_rules($VARIABLE, 'Some text', 'required');, is it possible to do something similar to:

$variable = $this->input->post('some_input');
$variable = some_function_which_manipulates_the_input($variable);
$this->form_validation->set_rules($i_want_the_variable_here, '', '');

to manipulate the input before validation check? Adding a custom callback seems a little clumsy to me since one method could do several things (not necessarily targeted at X validation field).

View 2 Replies View Related

Repopulating Checkboxes In Codeigniter After Unsuccessful Form Validation

I have a problem repopulating a set of checkboxes after an unsuccessful form validation returns the user back to the same form. Dropdown menus and text inputs could be repopulated, but not checkboxes. Here's a snippet of the code for the checkboxes:


The code snippet for text input which successfully repopulated is:

<?php echo form_dropdown('price_range', $options, set_value('price_range')); ?>

View 2 Replies View Related

Codeigniter Form Validation Callback Checking Multiple Fields

I have this controller set up for a login:

class Login extends Controller {
function __construct() {
$this->form_validation->set_error_delimiters('', '');


What I am looking at is the line that does the form validation callback >> $this->form_validation->set_rules(array('username','password'), 'Username', 'callback_terminal_login_check[$username,$password]'); I know this is not right. Basically what I want to do is check the username and password against the Authentication->DoTerminalAuthentication model to process the user's login. I want to pass the $username and $password form fields.


View 3 Replies View Related

Setting Validation Rules For Image Links?

I want to users to share their photos. I am using cakephp.I set the validation rule as url. Save fails.URL of the photo looks similar to this.

I want to validate urls only for images.

View 1 Replies View Related

Mailer Script With Common Validation Rules

Can anyone recommend a comprehensive php form mailer script that includes common validation rules such as checks for valid email addresses, phone numbers etc?

View 2 Replies View Related

Add Custom Call Back Method To Validation Rules?

What is the best method to strip html tags from the input? How can i remove the HTML tags while validating the input

$this->form_validation->set_rules('description', 'Description', 'trim|xss_clean');

Do I need to add custom call back method to validation rules?

View 3 Replies View Related

Codeigniter - Form Validation Converting Post Variables From Array To "Array" String

I am building an HTML form with a set of checkboxes for selecting multiple categories using this format:

<input type="checkbox" name="category[]" />

So, when I post and print_r($_POST) to view the variable and values I get:

[27] => on
[28] => on
[29] => on

Once I run $this->form_validation->run(); the categories array becomes "Array" as a string. I believe I have narrowed it down to "prep_for_form" function in the system/libraries/Form_validation.php file, but it seems like the recursive function is working correctly.

View 2 Replies View Related

CodeIgniter Form Validation - Get The Result As "array" Instead Of "string"

I am writing my form validation class using CodeIgniter. Is there any way so that I can get error messages in name value pair? Say, in an example form there are four fields: user_name, password, password_conf, timezone. Among them user_name, password validation has failed. So after executing: -

$result = $this->form_validation->run();

If the above function returns false, I want to get the errors in name value pairs like:

'user_name' => 'user name is required',
'password' => 'passord is required'

Actually, I want to form a JSON, which I can pass back to the AJAX call. I have a solution (a dirty one):- I can call validation methods one by one like: -


Is there any other way, to get all the error messages at once in name value pair?....

View 2 Replies View Related

Creating Rules Based Data In Form

On my form that I created that the data is being sent into a database, I also want to create rules to send outgoing email 1 of 5 people depending on something that was entered in the form.

View 1 Replies View Related

Form Validation :: Combine Validation For Different / Multiple Fields

Now I have the error messages going where i want them to but I cant figure out how to combine validation for different fields. The form due to how I now have it set up as error_msg, error_msg1 and error_msg2 will only reject the form if one field is not filled in. I tried to use the pipe to combine them but had no luck. Will i have to set a different complete validation for each field. Or can i use an array (error_msg = 'error messager here' error_msg1 = 'error message one here') somthing like that. Can you use multiple words in an array? Everything i see on line and in my books show one word one=two sort of This is the code I now have ...

View 1 Replies View Related

Regex - Simple Form Validation And The Validation Symbols?

I want to use some basic php validation (regular expressions) on, how do you go about doing it? I have just general text input, usernames, passwords and date to validate. I would also like to know how to check for empty input boxes. I have looked on the interenet for this stuff but I haven't found any good tutorials.

View 6 Replies View Related

Dynamically Extend A Model In Codeigniter?

my models in CI are set up so that they load "sub"-models whenever they need certain functions. In order to keep my code as accessible and clean as possible, I want those submodels to extend the model they are called to. So if I have two models:

class Mymodel extends Model


class Submodel extends Model
function test() { do something.. }

Then I need to, somehow, be able get the submodel to extend mymodel, so that I can do something like $this->mymodel->test(). It doesn't have to be mymodel that submodel extends, it could be any model.

View 2 Replies View Related

JQuery Validation With Codeigniter?

I have an input field which I would like to dynamically validate while user is typing... I am using Codeigniter and I believe that I have some URI problem...


<input type="text" id="username"> <span id="validateUsername"></span>


$(document).ready(function() {
var validateUsername = $('#validateUsername');
$('#username').keyup(function () {
var t = this;


In there I'm just trying to var_dump different stuff (like $_SERVER, $_REQUEST, $username), but I think that my script doesn't even reach that controller...

I was trying to change url: '<?php echo base_url(); ?>register/check_user/' + t.value, line in my jQuery script but it seems that no combination works. For example:

url: '<?php echo site_url('register/check_user/'); ?>' + t.value,
url: 'index.php/register/check_user/' + t.value,
url: 'register/check_user/' + t.value,

whatever I try my validateUsername span shows only "checking availability" message. I was trying my script in Chrome, Safari and IE8. PHP version is 5.3.0 and jQuery is 1.4.2...

View 1 Replies View Related

Copyrights 2005-15, All rights reserved