获取文本框的价值并转移到控制器(Codeigniter)PHP [英] Getting value of a textbox and transfer to controller(Codeigniter)PHP

查看:55
本文介绍了获取文本框的价值并转移到控制器(Codeigniter)PHP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

将值从视图转移到控制器时遇到问题。我没有得到值
这是我的方法

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

Manifest.php

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 }  ?>

我想在manifest.php(查看页面)中获取voyage_id(上面的代码)的值,并转移到控制器。
这是我的控制器

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

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);
}

我将使用$ this-> session-> userdata()来调用它

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

我该怎么办?

推荐答案

您正在使用会话获取值。相反,在提交表单后(必须使用表单),必须使用POST或GET方法-

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->会话-> userdata('voyage_id');

在此上面是错误的。提交表单/使用ajax并使用-

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

$ voyage_id = $ this-> input-> post('voyage_id'); 获取值c $ c>

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

其他选项是-
(如果要存储 voyage_id 在一个函数中并将相同的值发送到表单,则无需在隐藏元素中进行设置(请确保这与 voyage_id 提交表单后需要),然后删除html元素,就可以实现您要执行的操作。

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.

这篇关于获取文本框的价值并转移到控制器(Codeigniter)PHP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆