0

我有一个联系表格,我正在使用 Jquery .load 将一个 php 文件导入到导航所在的任何页面中。下面的例子。

http://madaxedesign.co.uk/dev/index.html

我知道需要更改操作表单,以便将其连接到正确的位置。但是,如果它在不同的页面上并导入到一个页面中,我该怎么做。因为目前它设置为contact.php,但在提交后它会转到该页面并且不会将消息导入弹出窗口。所以我真的需要它作为文件名,具体取决于它所在的页面。

所以我想问题是如何在提交后让消息出现在弹出窗口中而不是在不同的页面上?

代码:

        <?php
        $your_email = "maxlynn@madaxedesign.co.uk";
        $subject = "Email From Madaxe";
        $empty_fields_message = "<p>Please go back and complete all the fields in the form.</p>";
        $thankyou_message = "<p>Thank you. Your message has been sent. We Will reply as soon as possible.</p>";

        $name = stripslashes($_POST['txtName']);
        $email = stripslashes($_POST['txtEmail']);
        $message = stripslashes($_POST['txtMessage']);

        if (!isset($_POST['txtName'])) {

        ?>
        <form method="post" action="contact.php">
            <div id="NameEmail"> 
                <div>
                    <label for="txtName">Name*</label> 
                    <input type="text" title="Enter your name" name="txtName" />
                </div> 
                <div>
                    <label for="txtEmail">Email*</label> 
                    <input  type="text" title="Enter your email address" name="txtEmail" />
                </div> 
            </div>
            <div id="MessageSubmit">
                <div> 
                    <textarea maxlength="1200" title="Enter your message" name="txtMessage"></textarea> 
                    <label for="txtMessage">Message</label>
                </div>
                <div> 
                    <input type="submit" value="Submit" /></label>
                </div>
            </div> 
        </form> 
        <?php

        }

        elseif (empty($name) || empty($email) || empty($message)) {

        echo $empty_fields_message;

        }

        else {

            $referer = $_SERVER['HTTP_REFERER'];
            $this_url = "http://".$_SERVER['HTTP_HOST'].$_SERVER["REQUEST_URI"];
    if ($referer != $this_url) {
    echo "You do not have permission to use this script from another URL, nice hacking     attempt ;p.";
    exit;
            }

        mail($your_email, $subject, $message, "From: $name <$email>");

        echo $thankyou_message;

            }

?>
4

2 回答 2

0

你想做的只有在 javascript 中才有可能,这是一种由浏览器执行的语言。Javascript self 是一种讨厌的语言,但有许多扩展/插件可以让这变得非常简单,就像 jQuery。我建议你学习这门语言,你会发现 Web 开发的新世界打开了 ;-)。例如:http ://learn.jquery.com/

给你的表单一个id: <form method="post" id="test-form" action="contact.php"> 这样你就可以用jquery引用它

现在您可以使用 jQuery 捕获表单提交操作:

$('#test-form').submit(function() {
//send your data to your server and get the html data
  $.post('contact.php', $(this).serialize(), function (data){
 //here you can add the (html)data returned by the action to your page.
   $('body').append(data); //append data to body of html page
 })
 return false; //stop form from going to the next page
});

此代码基于 javascript 插件:jQuery,如果您想在页面上执行任何动态操作而不重新加载页面,则需要使用 javascript。

于 2013-04-14T16:46:37.590 回答
0

You should use ajax, send the email without refreshing page.

于 2013-04-14T16:43:15.457 回答