如何在 php 中保存按钮提交表单


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);
    }
?>

网页代码

<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>&nbsp;</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);
    }
}