【发布时间】:2011-03-06 16:01:31
【问题描述】:
我有一个简单的表单,可以将注册信息发布到 mailchimp 帐户。从包含文件返回的表单和消息在 Firefox 中完美运行,但在 IE 中没有发生任何事情。如果没有输入电子邮件地址,它应该会返回一个错误,就像在 Firefox 中一样。我不知道如何解决此类问题。如果出现错误,它应该将错误回显到表单上的 div 中,该表单在 Firefox 中再次完美运行,在 IE 中没有任何反应。对我来说完全是无稽之谈。我需要在今天之前完成这项工作。我尝试将文件移动到与 index.php 相同的位置,更改权限等,但没有成功。我需要一些重要的帮助!我什至无法让这段代码在 IE 中返回: if(!$_GET['email']){ return "No email address provided"; }
您可以尝试以下网址:www.terrybryan.com/index.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<title>Ajax Mailing List Sign Up System</title>
<link type="text/css" rel="stylesheet" href="css/default.css" />
</head>
<body>
<form id="signup" action="<?=$_SERVER['PHP_SELF']; ?>" method="get" style="width:250px;">
<fieldset>
<label for="email" id="email-label">Email Address</label>
<input type="text" name="email" id="email" />
<label for="zipcode" id="zipcode-label">Zip Code</label>
<input type="text" name="zipcode" id="zip" />
<label for="events" id="events-label">Receive future info from us?</label>
Yes<input type="radio" name="events" value="Yes" checked="checked" />
No<input type="radio" name="events" value="No" />
<label for="hearabout" id="hearabout-label">How did you hear about us?</label>
<select name="hearabout" id="hearabout">
<option value="Ice">Ice</option>
<option value="Radio">Radio</option>
<option value="Friend">Friend</option>
<option value="Door Hanger">Door Hanger</option>
</select>
<br /><br />
<input type="image" src="i/join.jpg" name="submit" value="Join" class="btn" alt="Join" />
<br /><br />
<div id="response">
<? require_once 'store-address.php'; if($_GET['submit']){ echo storeAddress(); } ?>
</div>
</fieldset>
</form>
<!-- Some fancy Ajax stuff to store the sign up info. If you don't want to use it, just delete it and the form will still work -->
</body>
</html>
这是返回消息的包含文件:
<?php
/*///////////////////////////////////////////////////////////////////////
Part of the code from the book
Building Findable Websites: Web Standards, SEO, and Beyond
by Aarron Walter (aarron@buildingfindablewebsites.com)
http://buildingfindablewebsites.com
Distrbuted under Creative Commons license
http://creativecommons.org/licenses/by-sa/3.0/us/
///////////////////////////////////////////////////////////////////////*/
require_once('MCAPI.class.php');
function storeAddress(){
// Validation
if(!$_GET['email']){ return "No email address provided"; }
if(!preg_match("/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*$/i", $_GET['email'])) {
return "Email address is invalid";
}
// grab an API Key from http://admin.mailchimp.com/account/api/
$api = new MCAPI('********');
// grab your List's Unique Id by going to http://admin.mailchimp.com/lists/
// Click the "settings" link for the list - the Unique Id is at the bottom of that page.
$list_id = "********";
// Merge variables are the names of all of the fields your mailing list accepts
// Ex: first name is by default FNAME
// You can define the names of each merge variable in Lists > click the desired list > list settings > Merge tags for personalization
// Pass merge values to the API in an array as follows
$mergeVars = array('ZIPCODE'=>$_GET['zipcode'],
'EVENTS'=>$_GET['events'],
'HEARABOUT'=>$_GET['hearabout']);
if($api->listSubscribe($list_id, $_GET['email'], $mergeVars) === true) {
// It worked!
return 'Success! Check your email to confirm sign up.';
}else{
// An error ocurred, return error message
return 'Error: ' . $api->errorMessage;
}
}
// If being called via ajax, autorun the function
//if($_GET['ajax']){ echo storeAddress(); }
?>
有人知道为什么这个简单的表单在 IE 中不能像在 Firefox 和其他浏览器中那样工作吗?
谢谢,
T 布莱恩
【问题讨论】:
-
我建议尝试的一件事是不要使用简短的 php 标签。 IE。总是使用
-
除此之外,化繁为简。浏览器的差异意味着 html 的问题,而不是 php 的问题(除非有短标签问题)。在 ie 中尝试一个简单的测试用例,例如在ie中检查回显,然后if得到回显。在其他一切正常之前,尽量不要涉及那些庞大而复杂的表单 html 代码。
-
我不知道如何解决 PHP 的问题。如何在 IE 中测试回声?任何帮助将不胜感激。谢谢,
-
@Tchalvak,使用您的信息,我将其缩小到 IE 无法识别:
if($_GET['submit']){ echo storeAddress(); } ?>它没有触发回声,因为它无法识别:if($_GET['submit']) 有没有更好的方法来做到这一点? -
哦,您可能还需要澄清您对 $_GET 与 $_POST 的理解。如果它没有显示在 url 中,那么它不是 $_GET。所以这可能是你的问题。我建议通常只使用 $_REQUEST。这样做的另一个好处是消除了 $_POST 是比 $_GET 更安全的用户输入的错觉,因为当您将它们放入 sql 时,两者都应该同样不受信任。
标签: php internet-explorer echo