Php 如何将数据从窗体发送到控制器

Php 如何将数据从窗体发送到控制器,php,opencart,Php,Opencart,在我的基于OpenCart的web商店中,我为它创建了全新的模板和控制器。路径是template/common/orderForm。在这个模板中有一个非常简单的联系方式 模板代码(不太多,我甚至没有包含标题) 谢谢你的关注。我希望你知道如何解决我的问题。好的,试试这个 您的模板文件应如下所示: <!doctype html> <div style="width: 723px;"> <form action="<?php echo $action; ?>

在我的基于OpenCart的web商店中,我为它创建了全新的模板和控制器。路径是template/common/orderForm。在这个模板中有一个非常简单的联系方式

模板代码(不太多,我甚至没有包含标题)

谢谢你的关注。我希望你知道如何解决我的问题。

好的,试试这个

您的模板文件应如下所示:

<!doctype html>

<div style="width: 723px;">
<form action="<?php echo $action; ?>" method="post">
Your name: <input type="text" name="your_name"><br>
Your e-mail: <input type="text" name="email"><br>
<input type="submit" value="Order">
</form>
</div>

好的,试试这个

您的模板文件应如下所示:

<!doctype html>

<div style="width: 723px;">
<form action="<?php echo $action; ?>" method="post">
Your name: <input type="text" name="your_name"><br>
Your e-mail: <input type="text" name="email"><br>
<input type="submit" value="Order">
</form>
</div>

好的,试试这个

您的模板文件应如下所示:

<!doctype html>

<div style="width: 723px;">
<form action="<?php echo $action; ?>" method="post">
Your name: <input type="text" name="your_name"><br>
Your e-mail: <input type="text" name="email"><br>
<input type="submit" value="Order">
</form>
</div>

好的,试试这个

您的模板文件应如下所示:

<!doctype html>

<div style="width: 723px;">
<form action="<?php echo $action; ?>" method="post">
Your name: <input type="text" name="your_name"><br>
Your e-mail: <input type="text" name="email"><br>
<input type="submit" value="Order">
</form>
</div>


非常感谢。代码工作得很好!顺便说一句,对于像我这样的新手:你应该安装邮件服务器(例如,像我一样安装Sendmail)来获得发送邮件的能力。如果没有Sendmail,代码将无法工作。在上面的代码中发现了一个小错误:出于某些原因,$your_name=$this->config->get('your_name');不起作用。它得到空字符串。但是如果您将这一行替换为$your_name=htmlspecialchars($_POST[“your_name”]);一切都很好@古石器时代的胡言乱语我忘了包括。。。后更新。。。谢谢,请阅读此链接@eolitict谢谢!代码工作得很好!顺便说一句,对于像我这样的新手:你应该安装邮件服务器(例如,像我一样安装Sendmail)来获得发送邮件的能力。如果没有Sendmail,代码将无法工作。在上面的代码中发现了一个小错误:出于某些原因,$your_name=$this->config->get('your_name');不起作用。它得到空字符串。但是如果您将这一行替换为$your_name=htmlspecialchars($_POST[“your_name”]);一切都很好@古石器时代的胡言乱语我忘了包括。。。后更新。。。谢谢,请阅读此链接@eolitict谢谢!代码工作得很好!顺便说一句,对于像我这样的新手:你应该安装邮件服务器(例如,像我一样安装Sendmail)来获得发送邮件的能力。如果没有Sendmail,代码将无法工作。在上面的代码中发现了一个小错误:出于某些原因,$your_name=$this->config->get('your_name');不起作用。它得到空字符串。但是如果您将这一行替换为$your_name=htmlspecialchars($_POST[“your_name”]);一切都很好@古石器时代的胡言乱语我忘了包括。。。后更新。。。谢谢,请阅读此链接@eolitict谢谢!代码工作得很好!顺便说一句,对于像我这样的新手:你应该安装邮件服务器(例如,像我一样安装Sendmail)来获得发送邮件的能力。如果没有Sendmail,代码将无法工作。在上面的代码中发现了一个小错误:出于某些原因,$your_name=$this->config->get('your_name');不起作用。它得到空字符串。但是如果您将这一行替换为$your_name=htmlspecialchars($_POST[“your_name”]);一切都很好@古石器时代的胡言乱语我忘了包括。。。后更新。。。谢谢,请阅读此链接@eoLithic
<?php  
class ControllerCommonOrderForm extends Controller {
    public function index() {
$this->document->setTitle($this->config->get('config_title'));
$this->document->setDescription($this->config->get('config_meta_description'));
$this->data['action'] = $this->url->link('common/orderForm');
$this->data['heading_title'] = $this->config->get('config_title');

if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/common/orderForm.tpl')) {
$this->template = $this->config->get('config_template') . '/template/common/orderForm.tpl';
} else {
$this->template = 'default/template/common/orderForm.tpl';
}

$this->children = array(
'common/column_left',
'common/column_right',
'common/content_top',
'common/content_bottom',
'common/footer',
'common/header'
);

$this->response->setOutput($this->render());

/* Check if form has been submitted */
if( isset($_POST['your_name']) )
{
/* Input data check */
$your_name = htmlspecialchars($_POST["your_name"]);
echo $your_name;
$email = htmlspecialchars($_POST["email"]);
/* Set the e-mail recipient */
$myemail = "the.eolithic@gmail.com";
/* Create a new variable by assigning a value to it */
$message_to_myemail = "Hello!
Your contact form has been sent a message!
Sender's name: $your_name
E-mail: $email
end";
/* Send a message using the mail () function */
$from  = "From: $your_name <$email> \r\n Reply-To: $email \r\n";
mail($myemail, $message_to_myemail, $from);
?>
<p>Your message has been successfully sent!</p>
<p>At <a href="index.php">Home >>></a></p>
<?php
/* If you are filling out the form mistakes were made work
the following code: */
function check_input($data, $problem = "")
{
    $data = trim($data);
    $data = stripslashes($data);
    $data = htmlspecialchars($data);
    if ($problem && strlen($data) == 0)
    {
        show_error($problem);
    }
    return $data;
}
function show_error($myError)
{
    ?>
    <html>
    <body>
    <p>Please correct the following error:</p>
    <?php echo $myError; ?>
    </body>
    </html>
    <?php
    exit();
}
}
}
}
?>