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


ADVERTISEMENT

Validating Only Selected Characters In String Php (phone Number Validation)?

i have a string containing alpha numeric characters.The script should return (echo) "true" if the string contains only 0-9, - , + , or the word NA (NA should be validated only if it contain no other characters and should echo false if the string contain any other character along with "NA"), The script should echo "false" if the string contains any other characters other than the specified characters.. How can i make this possible??

View 3 Replies

Validation - Validating Setter When Overloading Class Properties?

I have a class that uses the __set magic method. One of the properties for the class can only be set with a certain range of string values, the best example I can think of is the mysql datatype ENUM('value_one','value_two','value_three').

Would I place conditional statements within the __set method to distinguish between which property is being set and whether the value is valid for that property?

Are large switch statements inside a __set method considered sloppy practice, is their a better way of producing the desired results?

View 2 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

Select Only One Checkbox And Show Input Field If Checkbox Selected

I have a form with "Yes" and "No" as two checkboxes. These come in unselected at first. I'd like the user to only select one of these with the option to deselect their choice if they don't want to make a decision (which is why I didn't use radio buttons). Selecting Yes should deselect No and vice versa. I'm not sure how to do this. I'm using PHP (codeigniter), Javascript and JQuery. Secondly, after either Yes or No is selected, an input field needs to be displayed. I've got this setup but it toggles on the "onclick" action, which means selecting Yes twice shows and hides the input field! I want the input field to show if Yes or No are selected and disappear if the both Yes and No are unselected.

[code]...

View 3 Replies

Make Checkbox 2 Unavailable If Checkbox 1 Selected

I have a page with 10 checkbox-selected items to be used in determining what to display on the subsequent page. The two checkboxes, Continents & Countries, can be chosen, but you can have one or the other. How do I make it such that if one is selected, the other is not and vice-versa? HTML Code:

<td column width=426><h4><input type="checkbox" name="Continents" value="1">Continents</h4></td><tr>
<td column width=426><h4><input type="checkbox" name="Countries" value="2">Countries</h4></td><tr>

View 4 Replies

Validating Checkbox Array In A Form?

Im creating a simple quiz where some of the questions are checkbox because there is more than one correct answer. What I would like to be able to do, is run an if statement to check if, say for example, options 1 and 5 out of 6 have been selected, then award the point. However the point is only awarded is both options are selected.

View 5 Replies

In Symfony - Add A 'selected' Class To The Currently Selected Page In Navigation?

My navigation is written in the layout.php template It looks like this:

<ul id="nav">
<li><a href="item1">Item 1</a></li>
<li><a href="item1">Item 2</a></li>
<li><a href="item1">Item 3</a></li>
<li><a href="item1">Item 4</a></li>
</ul>

What is the best way to get a class="current" on the currently selected page?

View 4 Replies

Use Only Certain Validation Set For Validating Data In CakePHP?

I was trying to validate my User model data and I came upon this problem.

Say i have the following validation rules, stored in $validate variable:

var $validate=array(
"username" => array(
"usernameCheckForRegister" => array(
"rule" => ...,

[Code]....

In the UsersController controller, I have two actions: register() and login().The problem is, how do I validate the username field in the register() action using ONLY the usernameCheckForRegister rule, and how do I validate the username field in the login() action, using the other rule, usernameCheckForLogin? Is there any behaviour or method in CakePHP which allows me to choose which set of rules to apply to a form field when validating?

View 3 Replies

Validation - Simplify The Checking/validating Logic?

Here is a sample code of how to write something based on email, session key, and message. I use most of the code in error handling, like this:First, I need check null, then, the length, session, connection with db, lastly, the actually result.... ....It is very ignoring, and the code become very long, how can I simify this?

if(checkNullExisit($aEmail, $aSessionKey, $aMessage)){
//Null params detect
return;

[code]...

View 2 Replies

Validation - Validating Date Range Search?

Im going to implement a search function in mySQL for an application Im building,
the user types [for now, later will be a calendar picker] start date and end date,and click searchif (start day > end day), THEN errorif (start month > end month), THEN errorOk so far, but when having into account thatif (start day > end day) && (start month < end month), THEN searchif (start Month > end Month) && (start year < end year), THEN searchI dont worry about leap years, I will loop all months to 31 days, because if the day is in the db, it will fetch it, other wise, it will go to 31 and return nothing as there is no day,Im using varchar for my dates (no timestamp), as they are imported from json [iOSOk, hope to make sense,here the code,

<?PHP
$start = $_POST['start_date'];
$end = $_POST['end_date'];

[code]...

View 1 Replies

Validating Arrays With Callbacks In Codeigniter?

I'm running an array of user input through form validation utilizing a custom callback as a rule. Each of the submitted data values needs to pass this custom callback. If they don't pass, I want to set a unique error message for whichever values are invalid.

It seems, however, that I can only assign one error message to each rule. What is the best way to assign an error to any value being run through a callback that fails so that each value can maintain its own error?

View 2 Replies

Validating If String Is A FQDN ( Codeigniter )?

I'm trying to use form_validation to validate a domain name using a custom run:

function fqdn($str)
{
$CI =& get_instance();
$CI->form_validation->set_message('fqdn','The %s is not a valid domain name.');
$re1='((?:[a-z][a-z\.\d\-]+)\.(?:[a-z][a-z\-]+))(?![\w\.])';
if ($c=preg_match_all ("/".$re1."/is", $str, $matches)){
return TRUE;

[Code]...

This works relatively well apart from I dont want it to return true if there are @ anywhere in the address and also where there are leading or trailing How would I go about changing the code to match. Also am I going about this all wrong should there be something else I should be doing so I can make sure that the ext are correct and not some made up garbage.

View 1 Replies

Making Validation Class - Normal Class - Abstract Class - Interface - Polymorphism

im am making a php validation class with sub classes that extend it, eg, mobile, suburb, credit_card, ect so, the idea is you can call

$validation = new Validation('mobile');
$valid = $validation->validate($number);
$validation->type('suburb');
$valid2 = $validation->validate($suburb);

now my idea for doing this is having

[Code].......

View 1 Replies

Form Validation - Validating Select Drop Down Array?

I have the following to generate a state drop down on a form:

$states = array('State', 'Alabama', 'Alaska', 'Arizona', 'Arkansas');
echo "<select name='choose_state'>
[code]...

edit: validate in php, this is for a form collecting user information before posting to a db I tried using in_array and got stuck trying to exclude the default value

View 3 Replies

Validating Single Form Field With CodeIgniter?

Is there a quick way to validate a single form field with CodeIgniter to see whether or not that field matches a set of rules? There's the $this->form_validation->run();, but that will return either TRUE or FALSE for the whole form, and that's just not what I'm looking for. For example, if I only wanted to check if the email was valid, checking the whole form is not going to get me the result I'm looking for.

I looked through the documentation but couldn't find anything like $this->form_validation->run(); that accepts one parameter and returns TRUE or FALSE if it's valid.

View 1 Replies

How To Give A Value To Non Selected Checkbox

I would like to get a value for a non selected checkbox in a form.

Imagine my form contains :

<input type='checkbox' name='t[0]' value=&#391;'>
<input type='checkbox' name='t[1]' value=&#391;'>

When I analyse $t, if first checkbox is not selected and second is, I have :
$t[0] has no value. $t[1] equals 1
and count($t) equals 1

I would like to find a way to get :
$t[0] equals 0. $t[1] equals 1
and count($t) equals 2

View 4 Replies

Display The Selected Checkbox Id

I created a list of check box,if i select a indvidual check box,then it must go to the indvidual pages on the basis of selection. how to code for this.

View 1 Replies

Number Of Checkbox Selected

i have a code that should trap that only 1 checkbox should be selected but i don't know how?

View 4 Replies

Get Selected Index Of Checkbox?

I managed to add dynamic checkboxes(ie., if i add data in database checkbox will automatically generated in another form Coding Create table trole(id,role,isadmin)

<?php
$sql="select id,role from trole where isadmin='0'";
$result=mysql_query($sql);
$count=mysql_num_rows($result);
$role='';
$ID='';
$role1='';
$i = 0;
[Code]....

Example outputs 2(id)student(role), 3(id)faculty(role), 4(id)others Now my problem is if i select id 2 and 4 it should add 2&4 in database but i',m getting default value 4 for every data (ex: if i select 2&3 it should add 2&3 but i'm getting as 4 for every one.)

View 4 Replies

Check If Checkbox Are Selected Or Not?

i was making a form and wondering. when u have a check box. how to check if its checked or not before sending it value to database.? and in database its type will be a tiny int.right?

View 14 Replies

Checkbox Selected After Submit?

how I can show to the user what checkboxes he selected, after he clicks the submit button.

View 7 Replies

Delete Values Selected Using Checkbox?

I want to delete values that has been selected using checkbox. I am using this script though its not giving any error but its not working

for checkbox
<input name="checkbox[]" type="checkbox" value="<?=$row['s_id']?>">
for delete button
<input type="submit" name="delete" value="Delete">
for query
if(isset($_POST['delete']))
{.............

View 2 Replies

Deleting Records Selected By Checkbox?

Delete values selected using checkbox

I want to delete records that has been selected using Checkbox

Checkbox code

<input name="checkbox[]" type="checkbox" value="<?=$row[s_id]?>" id="checkbox[]">
ON delete button
if($_POST['delete'])
{
$cnt=array();

[Code]....

View 3 Replies

Checkbox Selected In Edit Section?

I want to show checkbox selected in edit section if there have value in DB. i m using cakephp 1.3 version .in edit section how i will show valued checkbox true.

View 2 Replies

Disable Submit Until Checkbox Is Selected

I have done a search but maybe I'm not putting the right terms in - I can't find what I'm looking for. I have attached my files. The index file contains a form. The form consists of just 6 checkboxes and the submit button. If someone makes a selection the submit button calls my process.php file and sends the browser to the vacancies.html page. If someone tries to click the button without selecting any of the checkboxes, I want it to say: "Please make a selection before continuing".

I've had a go (I'm a bit of a noob so don't laugh!). This is what I put in:

PHP Code:

if($THEPRINT=="" and $GUARDIANPRINT=="" and $THEONLINE=="" and $GUARDIANONLINE=="" and $JOBSACUK=="" and $OTHER=="")
echo ('Please make a selection before continuing');

This kind of works but it throws up a horrible warning message underneath which I think is something to do with my redirect to the vacancies.html page.

View 17 Replies







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