我相信我已经使用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 =“”?
答案 0 :(得分:0)
如果您希望表单提交到您当前使用的页面,请使用空操作属性,该属性将使表单提交到当前网址。
<form style="width:430px;" action="" method="post">