Getting value of a textbox and transfer to control

2019-09-21 14:21发布

问题:

I have problem when i transfer value from view to controller. I don't get the value Here's my method

Manifest.php

<?php foreach($voyage_info as $voyage) {  ?>

  <input type="hidden" name="voyage_id" value="<?=$voyage->voyage_id?>">
  <a class="btn btn-primary primary-bg btn-lg  col-md-2 m-3 btn-cus" href="<?php  echo base_url('PortClient/view_voyage/');?>">
  <h3>Voyage - <?=$voyage->voyage_number?></h3> 
  <small>Schedule - <?=$voyage->expected_arrival?> </small>
  </a>
<?php }  ?>

I want to get the value of voyage_id(Code above) in manifest.php(view page) and transfer it to controller. Here's my controller

PortClient.php

public function view_voyage() {
    $this->Auth->authCheck();
    $data = $this->template();
    $voyage_id = $this->session->userdata('voyage_id');

    $data['view_cargo'] = $this->PortManifestModel->view_voyage($voyage_id)->result();
    // your code here
    $this->load->view("port/client/sub_manifest/sub_manifest_1", $data);
}

and i will call it using $this->session->userdata() but it doesnt transfer.

What should I do?

回答1:

You need to either use a form and access the value on form submit. OR you can use AJAX to post the value and access it like: $this->input->post("voyage_id") instead of using the session



回答2:

You are using session to get the value.Rather you must use POST Or GET method after form is submitted (use form either) -

$voyage_id = $this->session->userdata('voyage_id');

Here above this is wrong.Submit the form/use ajax and get the value using -

$voyage_id = $this->input->post('voyage_id');

OR

Other Option is- if you are storing voyage_id in one function and also sending same value to the form then you do not need to set it in the hidden element (make sure that this is the exact voyage_id you need after form submission) then remove html element and you can achieve what you are trying to do.