0

我相信我发现我的表单使用 Firebug 存在问题。经过仔细检查,当有人在主页上时,我的表单操作被设置为 index.php。我把它改成了一个简单的/在萤火虫中,它起作用了。我的问题是该表单可以在某些页面上工作,而在其他页面上却不行。动作被设置为

<?php echo htmlentities($_SERVER['PHP_SELF']); ?>

在我的代码中。如何让它显示为 / 仅在主页上而不是 index.php 上。如果需要,我所指的站点和页面是“链接”处的主页。有问题的表格是通讯表格。导航到“链接”时会显示正确的地址。代码是:

</div>
<div class="footer">
<div class="wideNewsletter">
<div class="wrapNewsletter">
<div class="newsletterIntro"><b>NEWSLETTER SIGN UP</b></div>
<div class="newsletterForm">
<?php/* var_dump($_SERVER) */?>
<?php
$name = "";
$email = "";
$msg_to_user = "";
if ($_POST['name'] != "") {

    include_once "connect_to_mysql.php";

    // Be sure to filter this data to deter SQL injection, filter before querying database
    $name = mysql_real_escape_string(strip_tags(trim($_POST['name'])));
    $email = mysql_real_escape_string(strip_tags(trim($_POST['email'])));

    $sql = mysql_query("SELECT * FROM newsletter WHERE email='$email'");
    $numRows = mysql_num_rows($sql);

function curPageURL() {
 $pageURL = 'http';
 if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
 $pageURL .= "://";
 if ($_SERVER["SERVER_PORT"] != "80") {
  $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
 } else {
  $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
 }
 return $pageURL;
}


    if (!$email) {

        $msg_to_user = '<div class="warning"><ul><li>Please type an email address ' . $name . '.</li></ul></div><br /><br />';

    } else if ($numRows > 0) {

        $msg_to_user = '<div class="warning"><ul><li>' . $email . ' is already in the system.</li></ul></div><br /><br />';

    } else {

        $sql_insert = mysql_query("INSERT INTO newsletter (name, email, dateTime) 
                                                    VALUES('$name','$email',now() )")  or die (mysql_error());

        $msg_to_user = '<div class="success"><ul><li>Thanks ' . $name . ', hope you find what you want!</li></ul></div><br /><br />';
        $name = "";
        $email = "";
    }
    $message = 'Name: ' . $_POST['name'] . 'Page:'.$curPageURL.', Email: ' . $_POST['email']; 
mail('newproducts@moniquetrinidadjewelry.com', 'New Newsletter Sign Up at Monique Trinidad Jewelry',  $message);
}
?>
<form style="width:430px;" action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>" method="post">
<fieldset style="text-align:left;padding:0px;border:0px;"> 
Name:
<input name="name" type="text" maxlength="36" value="<?php echo $name; ?>" />
Email:
<input name="email" type="text" maxlength="36" value="<?php echo $email; ?>" />
<input type="image" src="https://www.moniquetrinidadjewelry.com/images/new-images/green-bullet.png" border="0" name="mySubmitBtn" type="submit" value="Submit">

</fieldset> 
</form></div>
<div style="position:absolute;top:120px;"><?php echo $msg_to_user; ?></div>
<div class="newsletterExplain">Receive product updates. Remember only one of each!</div>
</div>
</div><!--wide newletter end-->
<div class="wrapFooter">


<div class="tearOneFooter">
    <div class="footerColumnList">
        <div class="footerTitles">Connect With Us</div>
        <div class="footerLists">
            <ul>
                <li><a href="https://www.moniquetrinidadjewelry.com/contact/contact-pop.php">Connect With Monique!</a></li>
            </ul>
        </div>

    </div>
<!--Seperate Connect With us Column from Information Column-->
    <div class="footerColumnList">
        <div class="footerTitles">Information</div>
        <div class="footerLists">
            <ul>
                <li><a href="https://www.moniquetrinidadjewelry.com/about-us.php">About Us</a></li>
                <li><a href="https://www.moniquetrinidadjewelry.com/packaging.php">Packaging</a></li>
                <li><a href="https://www.moniquetrinidadjewelry.com/terms-and-conditions.php">Terms & Conditions</a></li>
            </ul>
        </div>
    </div>
<!--Seperate Information Column from Shipping and Returns Column-->
    <div class="footerColumnList">
        <div class="footerTitles">Shipping and Returns</div>
        <div class="footerLists">
            <ul>
                <li><a href="https://www.moniquetrinidadjewelry.com/return-policy.php">Orders and Returns<a/></li>
                <li><a href="https://www.moniquetrinidadjewelry.com/secure-shopping.php">Secure Shopping</a></li>
                <li></li>
            </ul>
        </div>
    </div>
<!--Seperate Shipping and Returns Column from Services & Support Column-->
    <div class="footerColumnList">
        <div class="footerTitles">Hours Of Operation</div>
        <div class="footerLists">
            <ul>
                <li>We are a 24/7 <br />Online Establishment!<br />(US Based)</li>
            </ul>
        </div>
    </div>
<!--Seperate Connect With us Column from Information Column-->
</div>
<!--Beging SecondTearFooterArea-->
<div class="tearTwoFooter">

    <!--<div class="signUpNewsLetter"><img src="https://www.moniquetrinidadjewelry.com/images/news_letter_temp_IMG.png" alt="newsletter" /></div>-->
    <div class="paymentOptions"><img src="https://www.moniquetrinidadjewelry.com/images/payment_options_temp.png" alt="payment options" /></div>
    <div class="twitter"><a href="https://twitter.com/MoniqueJewelry"><img src="https://www.moniquetrinidadjewelry.com/images/twitter_temp.png" alt="twitterLink" /></a></div>


</div>
</div>
</div>
</div>

==================================================== ======================== 问题扩展:

不再需要的链接已删除。不使用 php_self 时是否可以清理 action=""?

4

1 回答 1

0

如果您希望表单提交到您当前所在的页面,请使用空操作属性,这将导致表单提交到当前 url。

<form style="width:430px;" action="" method="post">
于 2013-06-05T03:16:56.423 回答