I make linked lists in opencart

view

<script> $(document). ready(function () { $("#country").change(function () { var countryval = parseInt( $("#country").val() ); //console.log(countryval); selectRegion(countryval); }) }) function selectRegion(countryval) { var region = $("#region"); if (countryval > 0){ $("#divregion").fadeIn("slow"); region.attr("disabled", false); region.load( "/catalog/controller/account/order.php", {countryval : countryval} ); } } </script> <form action="/catalog/controller/account/order.php" method="post"> <legend>Адрес доставки</legend> <!-- Text input--> <div class="form-group"> <label class="col-sm-2 control-label" for="textinput">Область</label> <div class="col-sm-10"> <select name="country" id="country"> <option value="0">- Выберите область -</option> <?php foreach ($regions as $region){ ?> <option value="<?php echo $region['id']?>"><?php echo $region['name']?></option> <?php } ?> </select> </div> </div> <div class="form-group"> <label class="col-sm-2 control-label" for="textinput">Город</label> <div class="col-sm-10" id="divregion"> <select disabled id="region" name="region" > <option value="">- Выберите город -</option> <?php foreach ($oll_city as $city){ ?> <option value="<?php echo $city['id']?>"> <?php echo $city['name']?></option> <?php } ?> </select> </div> </div> </form> 

controller

 $sq = $this->request->post['countryval']; print_r($sq); 

Trying to get the values ​​that came to the server, gives an error Notice: Undefined index: countryval

Tell me, maybe I have incorrectly specified the paths for data transfer.

How to do? transfer data immediately to the model and there to make a request to the database or to the controller.

model

 public function getRegion(){ $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "region"); return $query->rows; } 

    1 answer 1

    1. Your form does not post the countryval field, it is not there. It passes the key country with the value $ region ['id'].
    2. You don’t need to pull the model directly, you’ll break the MVC model. The code will start to smell. And in the future it will be difficult to make edits + dependencies that you would not expect. Touch the model through the controller of the view where you need to display all this.

    • Confused completely, can you tell me how to accept the data in the controller? - Roman Yushko
    • If I understand correctly, you want to accept the id of the country. He comes, but in the post array his name is country. View the entire post: print_r ($ this-> request-> post). $ data ['selected_counrty'] = $ this-> request-> post; - Kirill Korushkin
    • Tell me in the controller I am trying to print the post, but I have it empty, I pass in the form name = 'country', that is, I must get print_r in the controller ($ this-> request-> post ['country']) - country id but instead I get the error Notice: Undefined index: country? - Roman Yushko
    • See where the post flies out of the form via the dev-tools of any browser. If this is a non-standard pattern, it can fly anywhere and by any method. I described to you standard and the standard output agent. But first check where and how the form sends the data. - Kirill Korushkin