如何在模板中获取表单值

时间:2014-03-17 17:49:19

标签: php html forms cakephp-1.3

我想在表单模板文件中呈现$ _POST值。表单重定向到同一页面,但我不确定如何将我的值呈现给模板文件。

表格:

<form method="POST" name="requestform" action="" id="tour_request_form">
       <h4>Number of Passengers:</h4>
        <input type="hidden" name="tour_name" value="{{ tourData.title }}"/>
         <div id="request_form_row">
          <label> Adults:
          <select id="adult_passengers" name="adult_passengers" required> 
            <option value="1">1</option>
            <option value="2" selected="selected">2</option>
            <option value="3">3</option>
            <option value="4">4</option>
            <option value="5">5</option>
            <option value="6">6</option>
          </select>
          </label>
         </div>
        <div id="request_form_row">
         <button type="submit">Send Request</button> 
        </div>
       </form>

我的控制器:

 public function form_controller()
{
    $this->Messenger->sent_mail(array(
                    "to"           => "myemail@here.com",
                    "from"          => "company@email.com",
                    "subject"       => "Subject",
                    "body"         => "TESTING  BODY",
                    "status"       => "statusest",
                    "orderId"      => "111"
  }

在Messenger组件中我有:

public function sent_mail($data = array()) {
    if(empty($data)) {
        return false;
    }

    $this->Email->to = $data["to"];

    if(!empty($data["cc"])) {
        $this->Email->cc = explode(",", $data["cc"]);
    }

    $this->Email->from = $data["from"];
    $this->Email->subject = $data["subject"];
    $this->Email->template = "request_form";
    $this->Email->layout = "request_form";
    $this->Email->sendAs = "html";

    $this->controller->set("message", $data["body"]);

    return $this->Email->send();
}

我只想知道如何将表单数据呈现给模板?

1 个答案:

答案 0 :(得分:1)

http://articles.classoutfit.com/cakephp-sending-email-using-the-email-component/

观看线吼声

$ this-&gt; set(&#39; first_name&#39;,$ first_name);

您可以通过如上设置值来传递值,并可以将它们称为变量。