0

I have a problem getting the value of textbox and transfer it to controller

here's my code

manifest.php(view)

 <form method="POST" action="<?php  echo base_url('PortClient/view_voyage/');?>">  
      <div class=" container">                         
      <div class="row">
      <?php foreach($voyage_info as $voyage) {  ?>
      <input type="hidden" name="voyage_id" value="<?=$voyage->voyage_id?>">
 </form>

      <button type="submit" class="btn btn-primary primary-bg btn-lg  col-md-2 m-3 btn-cus">
          <h3>Voyage - <?=$voyage->voyage_number?></h3> 
          <small>Schedule - <?=$voyage->expected_arrival?> </small>
      </button>

<?php }  ?>

I want to get voyage_id and transfer it to controller

PortClient.php (controller)

public function view_voyage() {
    $this->Auth->authCheck();
    $data = $this->template();
    $voyage_id = $this->input->post('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);
}

The value of voyage_id textbox doesnt transfer

What should I do?

4
  • Possible duplicate of Getting value of a textbox and transfer to controller(Codeigniter)PHP Commented Aug 22, 2018 at 9:23
  • Does $voyage_info only ever have a single entry in the array, if not then check to see if you have multiple hidden inputs with the same name. Commented Aug 22, 2018 at 9:26
  • What you getting output of var_dump($voyage_info) in the view ? Commented Aug 22, 2018 at 9:32
  • first correct your html generated by foreach statement Commented Aug 22, 2018 at 9:56

2 Answers 2

1

First of all, add name in your button.

<button type="submit" name="submit">Submit button</button>

modify your controller

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

    if($_POST["submit"]){
        $voyage_id = $this->input->post('voyage_id');

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

try this...

Sign up to request clarification or add additional context in comments.

Comments

0

Please add your submit button within form.

Currently Button is placed after form, you should add it into form.

And also you have correct for loop.

Comments

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.