[英]How to save a form on button submit in 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>
只需確保提交表單,如下所示:
if (!empty($_POST)) {
if ($this->validate()) {
$this->model_catalog_contactus->saveContact($this->request->post);
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.