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)

View 3 Replies


ADVERTISEMENT

Codeigniter Form Validation Rules?

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

View 2 Replies

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">
<tr>
<td><label>Client</label></td>
[code]....

View 2 Replies

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->load->library('form_validation');
$this->form_validation->set_rules('name', 'Name', 'required');
$this->form_validation->set_rules('email', 'Email', 'required|valid_email');

[code]...

View 3 Replies

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";
[code]...

View 4 Replies

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

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

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

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

Form Validation Using Javascript In Codeigniter

i have a jquery table populate from datebase:

<?php
$attributes = array('name' => 'users');
echo form_open('users/action',$attributes);?>
<table class="data display datatable" id="example">
<thead>
<tr>
<th>Username</th>
[Code]....

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

[Code]....

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

[Code]....

View 1 Replies

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

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

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

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(){
$.ajax({
url: '/projects/cafe/index.php/welcome/save_form',
type: 'post',
data: {'fname' : $('#fname').val(),
'lname' : $('#lname').val(),

[Code]....

View 1 Replies

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: otis.team2648.com/auth/register

View 3 Replies

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

[code]...

View 3 Replies

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.

<?php
class Restaurant extends Controller {
function Restaurant() {
parent::Controller();
}
function index() {
// Load libraries and models
[Code]...

View 4 Replies

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

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

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:

[code]...

The code snippet for text input which successfully repopulated is:

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

View 2 Replies

Codeigniter Form Validation Callback Checking Multiple Fields

I have this controller set up for a login:

<?php
class Login extends Controller {
function __construct() {
parent::Controller();
$this->form_validation->set_error_delimiters('', '');
$this->output->enable_profiler(TRUE);
}

[Code].....

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.

[Code].....

View 3 Replies

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.

http://b.static.ak.fbcdn.net/rsrc.php/v1/Th/qr/B45MCqf3zU.jpg

I want to validate urls only for images.

View 1 Replies

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

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

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:

Array
(
[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

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:

Array
{
'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: -

$this->form_validation->required($user_name);
$this->form_validation->required($password);

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

View 2 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved