我是php的新手。我想在按钮提交上保存一个表单。但它在页面渲染时保存表单。我试过这个。
Php代码
<?php
if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) {
$this->model_catalog_contactus->saveContact($this->request->post);
}
?>
Html代码
<form action="/common/contactus" method="post" class="smart-green">
<h2>Contact Us</h2>
<p><label><span>Name :
</span><input id="name" type="text" name="contactname" placeholder="Your Name">
</label><label><span>Email :</span>
<input id="email" type="text" name="email" placeholder="Your Email">
</label>
<label><span>Mobile :</span>
<input id="email" type="text" name="mobile" placeholder="Your Mobile Number">
</label>
<label><span>Message :</span>
<textarea rows="" cols="" placeholder="Your message here" name="message"></textarea>
</label>
<label><span> </span>
<input type="submit" class="btn btn-primary" value="save" style="margin-top:15px;" name="submit-btn"/>
</label></p>
</form>
答案 0 :(得分:1)
请确保提交表单,如下所示:
if (!empty($_POST)) {
if ($this->validate()) {
$this->model_catalog_contactus->saveContact($this->request->post);
}
}