提交PHP联系表单后打开模态窗口(AJAX?jQuery?)

时间:2013-03-05 03:19:43

标签: php jquery ajax forms contact

我已经重新阐述了我的第一个问题,因为我认为它太含糊了!

案例:santz.net/index.contacto.html (如果你想尝试发送一些好的话......我收到它就没问题了)

这是我的代码......

联系表格:

    <form id="contact-form" name="contact-form" class="p25" action="contact.php" method="post">
        <fieldset>
            <label class="name">
                <input class="input" type="text" value="Nombre" onfocus="if(this.value == 'Nombre'){this.value = '';}" onblur="if(this.value == ''){this.value='Nombre';}" name="php_name" />
            </label>
            <label class="email">
                <input class="input" type="email" value="Email" onfocus="if(this.value == 'Email'){this.value = '';}" onblur="if(this.value == ''){this.value='Email';}" name="php_email" />
            </label>
            <label class="phone">
                <input class="input" type="tel" value="Teléfono" onfocus="if(this.value == 'Teléfono'){this.value = '';}" onblur="if(this.value == ''){this.value='Teléfono';}" name="php_phone" />
            </label>
            <label class="message">
                <textarea class="textarea" onfocus="if(this.value == 'Mensaje'){this.value = '';}" onblur="if(this.value == ''){this.value='Mensaje';}" name="php_message">Mensaje</textarea>
            </label>

            <div class="buttons-wrapper ml20">
                <div class="submit-comment">
                    <span></span>
                    <input type="reset" value="Cancelar">
                </div>
                <div class="submit-comment ml25">
                    <span></span>
                    <input type="submit" value="Enviar">
                    <div id="clicker"></div>
                </div>
            </div>
        </fieldset>
    </form>

这是我的PHP代码:

<?php
$field_name = $_POST['php_name'];
$field_email = $_POST['php_email'];
$field_phone = $_POST['php_phone'];
$field_message = $_POST['php_message'];

$field_sender = 's2@hotmail.com';

$mail_to = 's@hotmail.com';
$subject = 'Mensaje via Santz.net de '.$field_name;

$body_message = 'From: '.$field_name."\n";
$body_message .= 'E-mail: '.$field_email."\n";
$body_message .= 'Phone: '.$field_phone."\n";
$body_message .= 'Message: '.$field_message;

$headers = 'From: '.$field_sender."\r\n";
$headers .= 'Reply-To: '.$field_email."\r\n";

$mail_status = mail($mail_to, $subject, $body_message, $headers);

if ($mail_status) { ?>
    <script language="javascript" type="text/javascript">
        alert('Gracias por contactarse, en breve, me pondre en contacto.\n\nSantz Design | www.santz.net');
        window.location = 'index.contacto.html';
    </script>
<?php
}
else { ?>
    <script language="javascript" type="text/javascript">
        alert('El envio fallo. Por favor, envie un mail directamente a info@santz.net');
        window.location = 'index.contacto.html';
    </script>
<?php
}
?>

我想要做的是以下......

现在联系表格有效,我收到了电子邮件......那很好......所以:

1-我需要在提交表单时消除页面刷新/重定向 2-要替换刷新/重载/重定向,我需要在表单被提交时,我希望它打开一个模态窗口(我会把任何内容放在那里......)(例如: pixeden。 com / media-icons / soft-media-icons-set-vol-2 ...点击“下载”时打开的对话框

这是其他用户推荐我用于模态框的内容(非常好): mywebdeveloperblog.com/my-jquery-plugins/modalpoplite

问题是我不明白如何在提交后删除重新加载/刷新/重定向问题,我不明白如何在表单提交后连接模式框打开事件...

注意:

我对这一切都很陌生(我年仅17岁),所以我不是程序员......只是一个了解小编程的设计师......但我正在学习如何编程网络我需要帮助。

如果PHP不是要走的路,我需要改编编程技术,请告诉我。我对任何可以完全解决我问题的编程语言持开放态度!

非常感谢!!!

2 个答案:

答案 0 :(得分:1)

将此脚本放在联系表单的<head>中:

<link href="http://code.jquery.com/ui/1.10.1/themes/base/jquery-ui.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"></script>
<script type="text/javascript" src="http://code.jquery.com/ui/1.10.1/jquery-ui.js"></script>
<script type="text/javascript">
$(function() {
    $("#dialog-modal").dialog({
        height: 140,
        modal: true,
        autoOpen: false
    });
    $('#contact-form').submit(function() {
        $("#dialog-modal").dialog("open");
        $.ajax({
            type: "POST",
            url: $(this).attr('action'),
            data: $(this).serialize(),
            success: function() {
                $("#dialog-modal").dialog("close");
            }
        });
        return false;
    });
});
</script>

将其粘贴在身体的任何位置:

<div id="dialog-modal">Form submitted</div>

答案 1 :(得分:1)

Santz,他们很可能使用ajax和jquery UI对话框来显示javascripts ajax响应何时返回。这是一个很好的小教程,解释他们如何实现这一目标。祝你好运。

http://net.tutsplus.com/tutorials/javascript-ajax/submit-a-form-without-page-refresh-using-jquery/

相关问题