从 PHP 回显包含文件在 IE 中不起作用

发布于 2024-10-20 07:10:42 字数 4785 浏览 4 评论 0 原文

我有一个简单的表单,可以将注册信息发布到 mailchimp 帐户。从包含文件返回的表单和消息在 Firefox 中完美运行,但在 IE 中没有任何反应。如果没有输入电子邮件地址,它应该会返回一个错误,就像在 Firefox 中一样。我不知道如何解决此类问题。如果出现错误,它应该将错误回显到表单上的 div 中,这在 Firefox 中再次完美运行,而在 IE 中没有任何反应。这对我来说毫无意义。我需要在今天之前完成这个工作。我尝试将文件移动到与index.php相同的位置,更改权限等,但没有成功。我需要一些重大帮助!我什至无法让这段代码在 IE 中返回: if(!$_GET['email']){ return "No email addressprovided"; 您可以在以下

网址尝试该表单: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 ([email protected])
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(); }
?>

有谁知道为什么这个简单的表单不能像在 Firefox 中那样在 IE 中工作,其他浏览器?

谢谢,

T·布莱恩

I have a simple form that posts signup info to a mailchimp account. The form and messages back from the include file work perfectly in Firefox, but nothing is happening in IE. If no email address is entered, it should come back with an error just like it does in Firefox. I have no idea how to trouble shoot this type of issue. If there is an error, it should echo back the error into a div on the form which again works perfectly in Firefox and nothing happens in IE. It makes no sense to me. I need to have this working by today. I have tried moving the files to the same location as the index.php, changed permissions, etc. with no luck. I need some major help! I can't even get this piece of code to come back in IE: if(!$_GET['email']){ return "No email address provided"; }

You can try the form at: 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>

and here is the include file that the message comes back from:

<?php
/*///////////////////////////////////////////////////////////////////////
Part of the code from the book 
Building Findable Websites: Web Standards, SEO, and Beyond
by Aarron Walter ([email protected])
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(); }
?>

Does anyone have any idea why this simple form would not work in IE like it does in Firefox and other browsers?

Thanks,

T Bryan

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

雨落星ぅ辰 2024-10-27 07:10:42

原因如下:在 IE 中使用图像按钮时,当您单击它时,它不会发送 $_POST['nameofbutton'],而是发送 $_POST['nameofbutton_x']$_POST['nameofbutton_y']。现在,Firefox 会发送 $_POST['nameofbutton_x']$_POST['nameofbutton_y'] 以及 $_POST['nameofbutton'] >。 _x 和 _y 值存储您单击图像按钮的位置的 x 和 y 坐标,因此您可以根据用户单击的位置执行不同的操作,以执行图像映射等操作。

因此,当您测试 if($_GET['submit']){ echo storeAddress(); 时} ?> 你在 IE 上看不到它,因为 IE 没有 $_GET['submit'] 它有 $_GET['submit_x']$_GET['submit_y'],因此您必须测试 $_GET['submit_x'] 或 y。

至少我认为格式是 _x 和 _y,可能略有不同。简单的判断方法是 print_r($_GET);

哦,还有,顺便说一下,在表单中使用 Get 时要小心,特别是如果它们必须传输大量可能很长的信息,IE 地址栏中的字符数限制为 255 个字符,之后的任何内容都会被截断并遗漏$_GET 或格式错误。最好使用 Post 形式。 Get 仅适用于构建 CMS 控制器的链接或注册电子邮件验证链接等。

Here's why: When using an image button in IE, when you click it, instead of sending $_POST['nameofbutton'], it sends $_POST['nameofbutton_x'] and $_POST['nameofbutton_y']. Now, Firefox sends both $_POST['nameofbutton_x'] and $_POST['nameofbutton_y'] as well as $_POST['nameofbutton']. The _x and _y values store the x and y coordinates of where you clicked on the image button, so you can do different things depending on where the user clicked for doing something like an image map.

So, when you test for if($_GET['submit']){ echo storeAddress(); } ?> you don't get it on IE because IE doesn't have $_GET['submit'] it has $_GET['submit_x'] and $_GET['submit_y'], so you must test for $_GET['submit_x'] or y.

Least I think the format was _x and _y, might be slightly different. Easy way to tell is to print_r($_GET);

Oh, also, by the way, be careful using Get for forms, particularly if they have to transfer a lot of potentially long information, IE has like a 255 character limit in the address bar and anything after that will get cut off and left out of $_GET or malformed. Best to use Post for forms. Get is only really good for things like structuring links for a CMS controller or registration email verification links and all that.

治碍 2024-10-27 07:10:42

我建议编辑您的 html 代码以进行提交:

From:

<input type="image" src="i/join.jpg" name="submit" value="Join" class="btn" alt="Join" />

To:

<input type="submit" name="submit" value="Join" class="btn" alt="Join" />

类型提交通常是可靠的,其他类型(包括,遗憾的是,图像提交等)通常在不同的浏览器中实现不同。另一件不要依赖的事情是提交的内容,因为 ie 在某些情况下提交 html 而不是值(通常使用标准提交值以外的东西),或者在页面上提交多个表单,诸如此类的烦人的事情。

因此,一般来说,最好使用简单的 ,并简单检查提交的“存在”,而不是提交内容过于具体。

I suggest editing your html code for submit:

From:

<input type="image" src="i/join.jpg" name="submit" value="Join" class="btn" alt="Join" />

To:

<input type="submit" name="submit" value="Join" class="btn" alt="Join" />

type submit is generally reliable, other types (including, sadly, , image submits, etc) are often implemented differently in different browsers. Another thing not to rely on is the contents of submit, since ie in some cases submits html instead of the value (generally with things other than the standard submit value), or submit multiple forms on the page, annoying things like that.

So in general, it is best to go with a simple <input type='submit' ...etc, and go with a simple check for the -presence- of the submit and don't be too specific about what the submit contains.

熟人话多 2024-10-27 07:10:42

我建议采用一种非常简单的方法,使用 CSS 设计按钮样式,或者执行 我的图像按钮

I would suggest a very simple approach, style your button using CSS, or do <a href="javascript:;" onclick="document.yourformname.submit"><img src="path/to/your/image" alt="my image button" /></a>

满地尘埃落定 2024-10-27 07:10:42

由于 PHP 在服务器上运行,因此它(通常)应该为相同的输入向浏览器提供相同的响应。由于表单使用“get”方法,因此输入完全由 URL 指定(加上标头,包括 cookie,尽管这些似乎不在此考虑)。

无论如何,当您从 Firefox 提交表单时,您应该会看到表单提交的 URL 显示在 Firefox 地址栏中。如果 PHP 脚本发出重定向作为响应,则 URL 可能只会出现非常简短。无论哪种方式,它都应该在您的浏览器历史记录中可用。

如果您可以将该 URL 复制到 IE 的地址栏中,并从 IE 提交相同的请求(再次假设不涉及 cookie),那么您应该从服务器获得几乎相同的响应。如果您在 IE 浏览器窗口中看到的内容与在 Firefox 中看到的内容不同,可能有多种原因。

  1. 查看源代码。 (查看 -> 查看源代码)。如果它完全空白,则脚本可能无法正确执行。

  2. 如果您有权访问服务器错误日志,请检查与您的请求相关的错误消息。健全的 PHP 实现(与健全的服务器合作)将提供错误日志记录。有时,这确实是了解脚本情况的唯一方法。如果您可以通过 FTP 帐户访问 Web 服务器,您可能会在顶级或接近顶级的位置找到日志。

  3. 如果您无权访问服务器,您仍然可以通过使用 Firebug LiteFiddler2

Since PHP runs on the server, it should (generally) provide the same response to the browser for the same input. Since the form uses the "get" method, the input is entirely specified by the URL (plus headers, including cookies, though those don't appear to factor in here).

In any case, when you submit the form from Firefox, you should see that the URL of the form submission appears in the Firefox address bar. If the PHP script issues a redirect as a response, then the URL may only appear very briefly. Either way, it should be available in your browser history.

If you can copy that URL into the address bar of IE and submit the same request from IE (again, assuming cookies aren't involved), then you should get pretty much the same response from the server. If you're not seeing the same thing in the browser window of IE as you do in Firefox, there may be several reasons.

  1. View the source. (View -> View Source). If it's completely blank, the script probably failed to execute properly.

  2. If you have access to the server error logs, check for an error message related to your request. A sane PHP implementation (in cooperation with a sane server) will provide error logging. Sometimes this is really the only way to know what's going on with your script. If you have access to the web server through an FTP account, you will probably find the logs at or near the top level.

  3. If you don't have access to the server, you can still get a low-level view of what's happening with your request through the use of Firebug Lite or Fiddler2.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文