Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9257717
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T12:12:14+00:00 2026-06-18T12:12:14+00:00

Array values in form are always a problem for form validation in CI. Now

  • 0

Array values in form are always a problem for form validation in CI. Now I’ve to input multiple values and those array values are to be stored in DB. Now the user can keep some fields blanks by mistake as shown below in the links:

Input values.

Values in the array on submission.

I used this tutorial to add input boxes on + button click. On submission the blank values will be truncated and then not null array values will added to database. I tried this using a sample program in native PHP but could not implement it in CI.

I used the following code in native PHP to insert values in DB truncating null values:

<?php
    include 'sql_connect.php';
    $str = array();
    for($i=0;$i<count($_POST["txtSiteName"]);$i++)
    {
        $str[] = $_POST["txtSiteName"][$i];
    }
    $str = array_filter($str, function($item) {if(!is_null($item)) return $item;});
    foreach($str as $loop_str)
    {
        $arr_str[] = $loop_str;
    }
    for($k = 0; $k<count($arr_str);$k++)
    {
        mysql_query("INSERT INTO sitename (name) VALUES ('".$arr_str[$k]."')") or die(mysql_error());
    }
    print_r($arr_str);
?>

How can I achieve this in CI ?
I tried to use callback function but the array value is not being passed to the callback function.

EDIT:

The below code shows my callback function :

On entering 3 urls it is called 3 times. Is that normal ?
Also my array_walk’s callback function is not working. Calling a callback function inside another callback function is not possible ?

public function null_check()
{
    $urls = $this->input->post('link_name');
    array_walk($urls, 'prepurl');
    var_dump($urls);
}

prepurl function:

public function prepurl($item, $key)
{
    $item = "http://".$item;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T12:12:15+00:00Added an answer on June 18, 2026 at 12:12 pm

    Your question is not clear to me but since you mentioned to validate multiple text boxes. So if your text boxes are something like this

    <input type="text" name="txtSiteName[]" />
    <input type="text" name="txtSiteName[]" />
    

    then simply you can use

    $this->form_validation->set_rules('txtSiteName[]', 'Site Name', 'required|xss_clean');
    

    to validate all the text boxes against null or empty.

    Update (TO pass an argument in to the callback)

    $this->form_validation->set_rules('txtSiteName[]', 'Site Name', 'callback_sitename_check[' . $this->input->post('txtSiteName') . ']');
    
    function sitename_check($str, $sitenames) {
        // $sitenames will be your textboxe's array
    }
    

    The first argument is used by CodeIgniter by default so second argument is your parameter. Also take a look at insert_batch() to insert multiple records.

    Also you can do this like

    $this->form_validation->set_rules('txtSiteName[]', 'Site Name', 'callback_sitename_check');
    
    function sitename_check() {
        $sitenames =  $this->input->post('txtSiteName');
    }
    

    Update: (For array_walk)

    array_walk($urls, array($this, 'prepurl'));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got a php array (obtained through checkbox values in a form - as
foreach($apps as $app){ echo $this->Form->input('Application', array('type'=>'checkbox', 'id'=>$app['Application']['description'], 'div'=>false,'type'=>'checkbox','value' => $app['Application']['description'],'label'=>$app['Application']['description'])); } <div class=checkboxes> <input
How can I add all of my array values together in PHP? Is there
Can anybody please tell me how to put array values into a string or
I want to show some children of div#options based on multiple values of the
I've been stuck on this problem for a while now and seeking some help.
I want to submit a zend form but with lowercase values. Whatever user use
I am retrieving an array values from database which save multi dimensional array..i want
When I compare two array values I see two strings that look the same.
I'm working with two-dimensional array-values that should be inserted into a ArrayList. But this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.