mercredi 25 mai 2016

Trying to load checkbox results into iFrame in CodeIgniter

I am attempting to learn CodeIgniter. I want to send checkbox values from my view (index.php), via my controller (also called index.php confusingly, but that is what it is called at my company i work at, is this a good idea?), to an iFrame (which has a file called results.php) within my view. So far I get an array on view but only keys being shown - no values from checkboxes - like this:

Array ( [resultsAreaCode] => [resultsNumberType] => [resultsOrder] => [fred] => DAVE [sheep] => cow ) TEST

Here is my view with checkboxes and target iframe, note that one checkbox is populated by PHP/SQL:

  <form id="numberOrderForm" action="index/localNumberResults" method="post" enctype='multipart/form-data'>
    <div class="wrappers" id="multi-select1Wrapper">
        <h2>Area Code</h2>
        <select class="dropDownMenus" id="multi-select1" name="multi_select1[]" multiple="multiple">
            <?php
                //The query asking from our database
                $areaCodeSQL = "SELECT ac.Number AS `AreaCode`, ac.Name AS `AreaName`
                                FROM `AreaCodes` ac";                                                               //SQL query: From the table 'AreaCodes' select 'Number' and put into 'AreaCode', select Name and put into 'AreaName'

                $areaCodeResults = $conn->query($areaCodeSQL);                                                      // put results of SQL query into this variable

                if ($areaCodeResults->num_rows > 0) {                                                               // if num_rows(from $results) is greater than 0, then do this:
                    // output data of each row
                                foreach($areaCodeResults as $areaCodeResult)                                        //for each item in $areCodeResults do this:
                                    {
                                        $areaNameAndCode =  $areaCodeResult['AreaCode'] ." ". $areaCodeResult['AreaName'];  //get AreaCode and AreaName from query result and concat them
                                        $areaName = $areaCodeResult['AreaName'];                                    // get AreaName
                                        $areaCode = $areaCodeResult['AreaCode'];                                    //get AreaCode

                                        ?><option class="menuoption1" name="menuAreaCode" value="<?php echo $areaCode ?>"  ><?php echo $areaNameAndCode; ?></option><?php  //Create this option element populated with query result variables
                                    }
                } 

            ?>
        </select>
    </div>       




    <div class="wrappers" id="multi-select2Wrapper">
        <h2>Number Type</h2>
        <select class="dropDownMenus" id="multi-select2" name="multi_select2[]" multiple="multiple">
            <option class="menuoption2" name="package" value="gold">Gold</option>
            <option class="menuoption2" name="package" value="silver">Silver</option>
            <option class="menuoption2" name="package" value="bronze">Bronze</option>
        </select>
    </div>

    <div class="wrappers" id="multi-select3Wrapper">
        <h2>Order</h2>
        <select class="dropDownMenus" id="multi-select3" name="multi_select3[]" >
            <option class="menuoption3" name="order" value="sequential">Sequential</option>
            <option class="menuoption3" name="order" value="random">Random</option>
        </select>
    </div>  
    <input type="submit" value="Submit">
</form>

<div id="resultsTableWrapper">
    <iframe id="resultsTable" src="http://ift.tt/20AiYKR" width="100%"></iframe> 
</div>

This is within my controller (this I have been told by my tutor is correct though):

class Index extends CI_Controller { // this is my controller!


public function localNumberResults()
    {
    $data['formdata']= array(
                        'resultsAreaCode' => $this->input->post("menuAreaCode"), 
                        'resultsNumberType' => $this->input->post("package"), 
                        'resultsOrder' => $this->input->post("order"),
                        'fred' => 'DAVE', 
                        'sheep' => 'cow'
                        );



    $data['contentlocation'] = 'system/results';
    $this->load->view('system/template', $data);

    }
}

Can anyone point me in the right direction where i am going wrong? :-)




Aucun commentaire:

Enregistrer un commentaire