jQuery对话框,php表单

时间:2010-03-11 19:31:31

标签: jquery dialog

我有一个对话框,可以在网站的页面加载时打开。

script type="text/javascript">
$(function() {
    $('#dialog-message').dialog({
        modal: 'true',
        width: '400'
    });
});

</script>

这会产生一个包括:

<div id="dialog-message" title="Free Jiu Jitsu Session at Alliance">
          <!--#include virtual="/includes/guest.php" -->

guest.php有一个非常小的表单,由页面本身处理:

    <?php
$dbh=mysql_connect //login stuff here       
                if (isset($_POST['submit'])) { 

                if (!$_POST['name'] | !$_POST['email']) 
                {
                echo"<div class='error'>Error<br />Please provide your Name and Email Address so we may properly contact you.</div>";
                }
                else
                {
                $age = $_POST['age'];   
                $name = $_POST['name'];
                $gender = $_POST['gender'];
                $email = $_POST['email'];
                $phone = $_POST['phone'];
                $comments = $_POST['comments'];

                $query = "INSERT INTO table here (age,name,gender,email,phone,comments)
                VALUES ('$age','$name','$gender','$email','$phone','$comments')";

                mysql_query($query);

                mysql_close();

                $yoursite = "my site here";
                $youremail = $email;

                $subject = "Website Guest Contact Us Form";
                $message = "message here";

                $email2 = "send to email address";

                mail($email2, $subject, $message, "From: $email");

                echo"<div class='thankyou'>Thank you for contacting us,<br /> we will respond as soon as we can.</div>";

                }
                }
                ?>

                <form id="contact_us" class="guest" method="post" action="/guest.php" >
                    <fieldset>
                        <legend>Personal Info</legend>
                            <label for="name" class="guest">Name:</label>
                            <input type="text" name="name" id="name" value="" /><br>

                            <label for="phone" class="guest">Phone:</label>
                            <input type="text" name="phone" id="phone" value="" /><br>

                            <label for="email" class="guest">Email Address:</label>
                            <input type="text" name="email" id="email" value="" /><br>

                            <label for="age" class="guest">Age:</label>
                            <input type="text" name="age" id="age" value="" size="2" /><br>

                            <label for="gender" class="guest">Sex:</label>
                            <input type="radio" name="gender" value="male" /> Male
                            <input type="radio" name="gender" value="female" /> Female<br />
                    </fieldset>

                    <fieldset>
                       <legend>Comments</legend>     

                            <label for="comments" class="guest">Comments / Questions:</label>
                            <textarea id="comments" name="comments" rows="4" cols="22"></textarea><br>

                            <input type="submit" value="Submit" name="submit" /> <input type="Reset" value="Reset" />

                    </fieldset> 
                </form>

问题是,表单操作的路径不起作用,因为此对话框位于站点的index.html页面上,如果我放置绝对路径,它就不会处理......

我在另一个联系我们页面上有这个功能,所以我知道它有效,但是在对话框中,它似乎让我感到难过......

我该怎么办?

2 个答案:

答案 0 :(得分:0)

尝试分离代码或在操作属性中使用#

答案 1 :(得分:0)

我认为你最好的(最简单的)赌注实际上是将表单发布到包装页面(thanks.php或者你有什么),而后者又包含了guest.php代码。

你现在的方式,你会将你的结果发布到include / guest.php文件,它没有明显的HTML敷料。听起来你可能期望以某种AJAX-y方式将结果加载到对话框中?