如何呈现一些不在表单中,而是与表单数据一起呈现的数据


How to render some data which are not in the form, but together with the form data?

>我需要使用 CodeIgniter 实现事件注册功能,以显示事件详细信息并提供注册条目。

用户需要登录才能注册,

因此我将在会话中保存用户信息,一旦他登录,然后单击注册按钮,将显示名称和手机的形式。

我想做的是从表单中检索信息,加上用户信息(在会话中)+event_id,然后我将所有信息呈现给CI控制器以继续该过程。

我的问题是,我们可以在表单中设置一个操作,该操作仅与表单数据一起直接转到控制器,我想添加的数据呢,例如user_id,event_id(这将存储在某个html标签下的页面中)? 是否可以呈现一些不在表单中的数据, 但与表单数据一起?

这是我的注册表:

<body style="height: auto; overflow: auto;">
<form method="post" action="<?php echo BASE_URI.'registration_manager/add_registration'; ?>">
    <div>
      <input type="text" name="user" id="registration_name" placeholder="name">
      <input type="text" name="mobile" id="registration_mobile" placeholder="mobile">
      <input type="submit" data-inline="true" value="Register">
    </div>
</form>
...
<div event_id="1337"></div>     // I am not sure if this is proper way to store the event_id here?
</body>

我想发送姓名,手机,user_id,event_id registration_manager/add_registration操作,我该怎么办?

在控制器中,您可能具有如下所示的内容: $this->load->view('path/to/form', array('form_data' => $form_data));将加载视图,并允许您在该视图中使用$form_data中的值。

要使其与会话数据一起使用,您可以将会话信息加载到变量中并将其传递:

$this->load->library('session'); // loads the session library
$session_data = $this->session->userdata(); // loads everything from the session into a variable $session_data
$this->load->view('path/to/form', array(
    'form_data' => $form_data,
    'session_data' => $session_data
    )); // lets you access $form_data and $session_data in the view

在您看来,您可以拥有类似于以下内容的行:

<div event_id="<?php echo $session_data['event_id'];?>"></div>

请查看 CodeIgniter 会话文档,了解您可以使用会话执行的操作。