开发者

Echo back from PHP include file not working in IE

开发者 https://www.devze.com 2023-02-15 07:14 出处:网络
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 happeni开发者_如何学运维ng in IE. If no e

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 happeni开发者_如何学运维ng 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 (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(); }
?>

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


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.


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.


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>


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号