联系表格加载

时间:2013-07-25 15:42:15

标签: php forms contact

                <form id="contact" action="contact.php" method="get" />
                <div class="row-fluid">
                    <p class="span12">
                        <label for="name" class="second-color">
                            Nome</label>
                        <input type="text" id="name" name="name" class="required second-color span12" maxlength="25" />
                    </p>
                </div>
                <div class="row-fluid">
                    <p class="span12">
                        <label for="email" class="second-color">
                            E-mail</label>
                        <input type="text" id="email" name="email" class="required second-color email span12" maxlength="25" />
                    </p>
                </div>
                <div class="row-fluid">
                    <p class="span12 multi">
                        <label for="comment" class="second-color">
                            Mensagem</label>
                        <textarea id="comment" name="comment" class="required second-color span12"></textarea>
                    </p>
                </div>
                <a href="javascript:;" class="btn medium color1 hidden-tablet hidden-phone">ENVIAR MENSAGEM</a>
                <a href="javascript:;" class="btn small color1 visible-tablet visible-phone">ENVIAR MENSAGEM</a>
                <div id="loadingForm">
                    <img src="assets/images/loading.gif" alt="loading" />
                </div>
                </form>

所以我收到了这份联系表格。我有两个按钮,一个用于电脑,另一个用于平板电脑和手机。我使用GET,我应该使用POST方法吗?

任何人都可以帮我构建contact.php吗?在发送消息时,我不确切知道如何使用loading.gif ..

1 个答案:

答案 0 :(得分:0)

你想使用$_POST,除非你做一些ajax的东西或者提交长网址给一个单独的处理表单而不是下面的post方法使用$_GET并将表单contact.php命名为您指定并通过ajax进行一些调用以获取加载微调器,并集成所有内容。但是,从这个问题来看,我认为最好的选择,在学习更多关于php和ajax之前,只需要通过$_POST来完成。

您可以使用php self将其提交到同一页面,然后在顶部有:

if ($_POST['email']) {
    $emailFrom = trim(stripslashes($_POST['email']));
    $emailTo = "youremail@domain.com";
    $subject = "Website contact form submission";
    $name = trim(stripslashes($_POST['name']));
    $message = trim(stripslashes($_POST['comment'])); 
    // prepare email body text
    $body = "";
    $body .= "Name: ";
    $body .= $name;
    $body .= "\n";
    $body .= "Email: ";
    $body .= $emailFrom;
    $body .= "\n";
    $body .= "Message: ";
    $body .= $message;
    $body .= "\n";
    // send email 
    $success = mail($emailTo, $subject, $body, "From: <$emailFrom>");
}