0

I have a from which lists several items that can be selected by check box and a dropdown permitter added. In a separate part of the form is have another check box. This is submitted as two arrays.

The arrays look like this

Array
(
[1] => Array
    (
        [num_copy] => 1
        [dwg_rev] => B
        [dwg_id] => 1
    )

[2] => Array
    (
        [num_copy] => 1
        [dwg_rev] => B
        [dwg_id] => 2
    )

)
Array
(
[1] => Array
    (
        [client_id] => 1
    )

)

I need to pass these two arrays to a form_validation that can check is dwg_rev has already been added to the database for the selected client_id.

I tried to use is_unique, but it can only check in one table to see if this already exists in it.

This is what my form validation currently looks like

$rows = array();

    if(!empty($_POST['result']))
    {
        $rows = $_POST['result'];
        $temp_dwg_array = array_column($rows, 'temp_dwg_id');
        foreach($temp_dwg_array as $key => $temp_dwg_id)
        {
            $this->form_validation->set_rules('result['.$temp_dwg_id.'][dwg_rev]', 'Revision' , 'required|callback_check_issued_rev');
        }
    } else $this->form_validation->set_rules('result[][temp_dwg_rev]', 'Revision' , 'required');

    if(!empty($_POST['client']))
    {
        $temp_client_array = array_column($_POST['client'],'client_id');
        foreach($temp_client_array as $key => $client_id)
        {
            $this->form_validation->set_rules('client['.$client_id.'][client_id]', 'Please make a selection from the distribution list' , 'required|callback_check_issued_rev');
        }
    }
    else $this->form_validation->set_rules('client[][client_id]', 'Distribution' , 'required');

I want to create a callback function, but I can't figure out how to pass two variables to the callback function to compare to the db.

9
  • Couldn't you use is_unique as few times rule for different tables is_unique[table1.col4]|is_unique[table2.col3]? Commented Apr 2, 2016 at 9:17
  • I think I'm going to need to pass the two arrays to a callback function and then check if I can find the values in the db tables with a join and then return true or false... the passing of the post arrays to the callback function what I'm struggling with. Commented Apr 2, 2016 at 15:30
  • Do you want to check two values in one table or two values in two tables? Commented Apr 2, 2016 at 15:42
  • I want to check two values in two tables. Commented Apr 2, 2016 at 16:02
  • Than you can use proposed solution for both values separately. Commented Apr 2, 2016 at 21:05

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.