Issues with IE and form handling

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
paul_m
Forum Newbie
Posts: 5
Joined: Fri May 30, 2008 9:15 pm

Issues with IE and form handling

Post by paul_m »

Hi, I am creating a tool that registers a user for newsletter purposes. The general process is they submit their email address [any form], get sent a confirmation email with a link[from signup.php], click the link and are then required to fill out a form with general information[in register.php].

My problem, however, is I have coded it and it works flawlessly in Firefox. In checking in IE now, when the user submits an email address [to signup.php], it never gets into the loop.

Code: Select all

if(isset($_POST['submit']) && isset($_POST['email'])){...}
never returns true. In testing, I have echo'd stuff before the conditional, inside, and after, and only the before and after appear. Does IE handle the $_POST superglobal any differently than FF?.

It was supposed to go live yesterday, and so this is really irritating me when I thought I successfully completed the project and then some error that had never happened before pops up.

here's the full code for signup.php, with the sensitive stuff edited out.

Code: Select all

 
 
session_start();
echo("first");
if(isset($_POST['submit']) && isset($_POST['email'])){
echo("second");
  $_SESSION['email'] = $_POST['email'];
  $_SESSION['referer'] = $_POST['link'];
  $referer = $_SESSION['referer'];
  $email = $_SESSION['email'];
    
  if(!check_email_address($email)){ //Bad email address, redirect back to original page
    header("Location: redirect.php");
  }  
 
  // Check to make sure the email does not match any current records in the DB.  
  //connect to the db
  $con = mysql_connect($ip,$user,$password);
  if (!$con)
    {
    die('Could not connect: ' . mysql_error());
    }
  mysql_select_db($database,$con);
  
 
    //query each row
    $q="SELECT email, ksu_id FROM members";
    $result = mysql_query($q) or die(mysql_error());
    while($row = mysql_fetch_array($result)) {
      if($row['email'] == $email) {     
        include("define_top.php");
        ?>
              Already exists message
        <?
        include("define_bot.php");
        return;
      }
    }
    
    //query unconfirmed email addresses
    $q="SELECT * FROM unconfirmed";
    $result = mysql_query($q) or die(mysql_error());
    while($row = mysql_fetch_array($result)) {
      if($row['email'] == $email) {
          //Send the new user an email
          $m = new MAIL;
          $m->From(...);
          $m->AddTo($email);
          $m->Subject('...');
      
          $message = "..."
          $m->HTML($message);
          $m->Send();  
          
        include("define_top.php"); ?>
              Needs to be confirmed message output
      <? include("define_bot.php"); 
      return;
      }
    }
   
    
    //Insert the new email into the database
    $salt = "...";
    $hash = md5($email.$salt);
    $q ="INSERT INTO unconfirmed (email,hash) VALUES('$email','$hash')";
    mysql_query($q)or die(mysql_error());
    mysql_close($con);  
 
 
    //Send the new user an email
    $m = new MAIL;
    $m->From('...);
    $m->AddTo($email);
    $m->Subject('...');
 
    $message = "...";
    $m->HTML($message);
    $m->Send();  
    
  include("define_top.php"); ?>
        Thank you message
<? include("define_bot.php"); 
      
}
echo("third");
 
And right now it's just outputting "firstthird" without my damned "second" in there. Thanks for the help!
paul_m
Forum Newbie
Posts: 5
Joined: Fri May 30, 2008 9:15 pm

Re: Issues with IE and form handling

Post by paul_m »

Oh, and I obviously left out check_email_address() from the signup.php code I posted.
nowaydown1
Forum Contributor
Posts: 169
Joined: Sun Apr 27, 2008 1:22 am

Re: Issues with IE and form handling

Post by nowaydown1 »

Hi Paul. Not exactly sure what could be causing this issue for you. Is there any way you could provide the form that you use to post to this page also? Might help us track down the issue. Some other general debugging type stuff you might try is just do a print_r($_POST); where you currently have your 'first' echo. Then you can at least see what's being passed to you and maybe something will stand out to there.
paul_m
Forum Newbie
Posts: 5
Joined: Fri May 30, 2008 9:15 pm

Re: Issues with IE and form handling

Post by paul_m »

The generic form that doesn't work [which i use for testing]

Code: Select all

 
<form action="signup.php" method="POST">
<input type="text" length="40" name="email">
<input type="hidden" name="link" value=" <? echo($_SERVER['PHP_SELF']); ?> ">
<input type="submit" name="submit" value="submit">
</form>
and the one on the actual site with javascript [doesn't work either]

Code: Select all

 
<form action="signup.php" method="POST">
<input type="text" class="src_field" name="email" value="E-mail Address" onClick="this.value=''">
<input type="hidden" name="link" value="<? echo($_SERVER['PHP_SELF']); ?> ">
<input type="submit" name="submit" value="Join Striped Crew!">
</form>
 
And thanks for reminding me about print_r. I'd been using it a ton with the form. For some reason, it's not recognizing the submit button [not included in the array].

It outputs : firstArray ( [email] => email [link] => /index.php ) third
now
nowaydown1
Forum Contributor
Posts: 169
Joined: Sun Apr 27, 2008 1:22 am

Re: Issues with IE and form handling

Post by nowaydown1 »

So, I've actually never noticed this before. I was just doing some testing and was able to replicate the issue. It seems to be that when you just press enter to do your form submission, the value of your submit button isn't passed. If I actually click the submit button it is.

I'm sure one of the other guys here have probably come up against this issue before and may have a recommendation on the correct way to implement a solution for this. I was able to get the form working by just shoving a hidden form element with the same key on the form.

Code: Select all

 
<input type="hidden" name="submit" value="" />
 
Hope that helps.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Re: Issues with IE and form handling

Post by RobertGonzalez »

I have posted this "issue" before :wink:

It gets even better when using an image for a button. Try that one day.

Never check for a form submission by using a button. Check the request method.

Code: Select all

<?php
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
// this is a post
}
?>
Then you are not bound by how a browser handles the form.
paul_m
Forum Newbie
Posts: 5
Joined: Fri May 30, 2008 9:15 pm

Re: Issues with IE and form handling

Post by paul_m »

You my friends, are genii [would that be the correct plural?]. When you've been staring at something for the past 2 days, your brain becomes a little fried. The littlest things that you overlook are the ones that screw ya.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Re: Issues with IE and form handling

Post by RobertGonzalez »

Experience is priceless. :) This came up for me about two years ago. Once I saw how IE handled forms, I never again used a form element to check if a form was sent.
Post Reply