Set Form Validation Rules For CodeIgniter Dynamically ?

Feb 27, 2009

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?

Aug 21, 2010

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

View 2 Replies View Related

Form Validation With Rules?

Mar 9, 2011

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?

Apr 13, 2011

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()?

Aug 31, 2010

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?

May 10, 2010

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?

May 27, 2011

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?

Feb 3, 2011

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?

Jun 18, 2010

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

May 26, 2011

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)?

May 30, 2011

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?

Jun 23, 2011

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

Feb 5, 2011

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?

Jun 23, 2011

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?

Jan 23, 2011

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?

Sep 1, 2009

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

Dec 29, 2009

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?

Aug 11, 2009

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?

Jun 16, 2011

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

Jun 14, 2011

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

Aug 20, 2010

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?

Mar 14, 2011

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

Mar 5, 2007

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?

Apr 1, 2010

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

Sep 5, 2010

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"

Jan 22, 2009

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

Feb 17, 2006

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

Dec 14, 2004

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?

Feb 5, 2009

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?

Feb 10, 2011

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?

Nov 8, 2010

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

Jquery Validation In CodeIgniter?

Nov 11, 2009

i need to add client side validation to my fiels which are selected in a forloop.the fields are auto incremented according to count.i need to add validation for a selected fields code is

 <? $i=0;?>
<? foreach ($info as $link): ?>

<DIV><INPUT type="checkbox" name="check<?=$i?>"  onclick="show(this,<?=$i;?>);" id="check" ><a href="<? echo[code].....

View 1 Replies View Related

Codeigniter Return Validation Error?

Jun 10, 2011

I'm making a URL validation helper which I set as a rule in my form validation.

$this->form_validation->set_rules('link_url', 'Link URL', 'trim|required|xss_clean|max_length[255]|validate_url');

If the validate_url returns FALSE how can I return a custom validation error from the helper?

if ( ! function_exists('validate_url'))
function validate_url($str)
$pattern = "/^(http|https)://([A-Z0-9][A-Z0-9_-]*(?:.[A-Z0-9][A-Z0-9_-]*)+):?(d+)?/?/i";
if (!preg_match($pattern, $str))
$this->form_validation->set_message('validate_url', 'URL is not valid');
return FALSE;


When I submit the form I get Fatal error: Using $this when not in object context

View 2 Replies View Related

Codeigniter 2.x.x Validation Error Highlighting

Jul 14, 2011

where/what file to tweak in order to alter the background color of the form_validation error ? , like e.g I want to change the color to red, so that it stands out on my registration form, when it detects an error when user enters inappropriate data

View 2 Replies View Related

CodeIgniter Validation In Library Does Not Accept Callback?

Jun 12, 2010

This library has a function _validation() and this uses the validation library to validate the data.With using normal validation methods it works just fine, but using a callback function just does not work. It is not called.I call it like this.

$this->CI->form_validation->set_rules('user', 'Username', 'required|callback__check_user');

The functions name is _check_user and it uses the username _check_user($user).The function itself works fine and I can also call it in the class ($this->_check_user('username')) with a working result. I am guessing, there might be a problem because I am not workin in a controller so I have a CI instance $this->CI instead of just the original instance $this->

View 2 Replies View Related

Codeigniter Simple Validation Callback Not Working

May 29, 2011

I'm creating a codeigniter callback for validating an input where users enter programming tags for example php, js, jquery. Values are separated by commas. I want to show a message if you enter duplicate tags for example php, jquery, php, js where php would be the duplicate. First in my controller I set the validation rules for the 'user_tags` input

$this->form_validation->set_rules('user_tags', 'User Tags', 'callback_user_tags_dublicates', 'trim|xss_clean|max_length[100]|regex_match[/^[a-z,0-9+# ]+$/i]');

Then the callback

<?php function user_tags_dublicates($str)
$val = $str; //the input value (all the CSV)
$tags = str_getcsv($val); //creates an array of the CSV
if(count($tags) != count(array_unique($tags))) //if array not equal to unique array it contains duplicates

and finally in the view I show my error.

<?php echo form_error('user_tags'); ?>

When I enter duplicate tags I get Unable to access an error message corresponding to your field name. I'm not sure what I'm doing wrong. I tested the function in a static page without validation rules and it works.

View 2 Replies View Related

Recaptcha Validation Not Being Thrown With Codeigniter - However Only When Uploaded To Webhost

Feb 1, 2010

Using the following guide online (and the 1.7x fix at the bottom) [URL] Recaptcha validation works well when working locally (tested on both my windows machine and a friends OSX machine) however when uploaded too both my server and his web host the validation routine for the recaptch appears not get checked even though the other validation on the pages do. However no errors are thrown and I have looked through the code and unable to find out what is going wrong. here are the classes that deal with this

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class MY_Form_Validation extends CI_Form_Validation
function MY_Form_Validation()
function recaptcha_matches() {
$CI = & get_instance();

View 1 Replies View Related

Validating That At Least One Checkbox Is Selected Using Codeigniter Validation Class?

May 3, 2011

I have a codeigniter form that contains two checkboxes:

<input type="checkbox" checked="checked" id="box1" name="box1" /> <label for="box1">Box One</label>
<input type="checkbox" checked="checked" id="box2" name="box2" /> <label for="box2">Box Two</label>

I want to use CI form validation to check that at least one checkbox is select (more than one can be selected). I'm having problems working out how to do it with the form validation libaray. I tried a callback but this only passes the value of one checkbox. Whats the best way to validate?

There are also other fields on the form, so I need to maintain the state of the checkboxes on validation.

View 1 Replies View Related

Loading 'modules' Data Into Views On A Per User Basis Dynamically From One Controller (codeigniter)?

Jun 15, 2009

I am trying to load the views for a set of 'modules' for a user who has selected any number of available 'modules'. I can get the name of the module (or any column) from the database and load->view($name . '_view'); but can't seem to figure a way to load the data for the view based on the 'module' name.

//Loads the rows (selected modules) I need for this user into an array
$modules['modulearr'] = $this->module_model->getModuleUser();
for($i = 0; $i < count($modules['modulearr']); $i++){


There is also an issue with loading the models in the controller based on the fact I can't change $this->load->THIS_PART dynamically. I am new to everything so there may be a basic concept I am not grasping, If you could point me in the right direction that would be awesome. I could do a whole bunch of if statements but that seems messy, surely there is a better way.

View 3 Replies View Related

Prevent A Form From Proceeding To The Post-validation If An Error Occurred In The "normal" Validation?

Jun 26, 2011

Is there a way to prevent a form from proceeding to the post-validation if an error occured in the "normal" validation?

View 1 Replies View Related

Access Array Form Position Dynamically In Html Form?

Jun 10, 2011

I am doing a little learning on php and and html using smarty to aid it.
I am trying to build a very simple shop-alike list with a cart image that when it is clicked, it is supposed to return via form the info I want from that item, but I am failing to get the index of the items right....

This is the code relative to the loop inside the tlp (it is a HTML internally used by smarty):

{section name=i loop=$homeList}
<div class="homemenu" align="right">
<table class="menhome" border="0">


The thing is: how do I tell the form that a single button has a singular index to the array and gain access to the correct info inside the array?

View 1 Replies View Related

Get Ajax Form To Inject Captcha Verification Into The Browser After Successful Form Validation?

Sep 21, 2010

Currently after my form has passed validation it forwards to an html page.I would like to have one last step that pulls reCaptcha and when reCaptcha has been passed only then is the registration details of the user sent to my database and user forwarded to what ever page I choose. Here is my javascript and ajax. The submit.php is a file that holds all my validation rules. I think I now have to have a file that holds my captcha and use ajax to get that file or maybe there is some better way. I'm still learning.

$('#fhjoinForm').submit(function(e) {


View 1 Replies View Related

Use ExpressionEngine Form Validation Class In Module To Repopulate Form In Template?

Mar 15, 2011

Is it possible to display errors and repopulate fields on a form that is hard coded into a template? So far Ive only figured out how to display the errors in a modules view, but not a template. Based on the logic of ExpressionEngine, Im guessing I need to somehow make the validation errors visible through a tag in my module, or even generate the whole form from the module, but Im not sure how to best approach this.

Here is what I have right now.

function submit_form()


And for testing, the view simply contains:

echo validation_errors();

View 1 Replies View Related

Dreamweaver Form Validation And Redirect Them Back To The Form Page Without Comment Input To The Database

Nov 28, 2007

I post this solution to a form validation and redirect as an addition to a comment page written with dreamweaver. Unfortunately Dreamweaver does not provide server-side validation for php. You're expected to purchase an extension. My problem I have a comments page with a comment form. I wanted the comment input to a database if ok but if a user tried to input code or a link, I wanted to redirect them back to the form page without their comment input to the database. I also needed to work out where in the Dreamweaver written code to place my validation and redirect.

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "comments"))
$comment = htmlentities($_POST['comment']);
function check_field1($comment)
if (preg_match("/</", $comment))

View 9 Replies View Related

Set Up Validation On A Simple Contact Form That Is Created Using The Form?

Jun 13, 2010

I am trying to set up validation on a simple contact form that is created using the form helper. No validation at all occurs. What is wrong? In the code below, the good keyword always shows, regardless of what is entered into the form, and the saved values set via set_value are never shown.

// Contact
function contact() {
$data['pageTitle'] = "Contact";
$data['bodyId'] = "contact";

View 1 Replies View Related