Jump to content

[SOLVED] Code works in Firefox but not in I.E?


DanielHardy

Recommended Posts

Hi,

 

You can view the application associated with the code at www.chcsc.org

 

The guestbook at the bottom right hand page is what I am having issues with.

 

In both I.E and firefox it will succesfully read a txt file and echo the output.

 

However it will only add a new entry to the file in Firefox, in I.E i use the submit button and nothing seems to happen.

 

I find this very weird.

 

Any help is greatly appreciated.

 

<?php


// Save filename to variable.
$guestbook = "messages.txt";

// This will run if someone sends user input.
if (isset($_POST['button']))
{
	// Check whether any fields are empty or not.
	if (!empty($_POST['name'])  && !empty($_POST['message']))
	{
		// Bad characters in E-Mail string.
		$badSearch = array("@", ".");
		// Goods characters in E-Mail string.
		$goodSearch = array(" @ ", " . ");
		// Grab name from the form and add a newline afterwards.
		$string .= "<b>" . $_POST['name'] . "  ";
		// Grab email and replace the @ and . in the string.
		$string .= str_replace($badSearch, $goodSearch, $_POST['email']) . "</b>\n";
		// Grab the message and save it in $string.
		$string .= "<font color=#2766c5>" . $_POST['message'] . "</font>\n<hr>";

		// Open messages.txt and append more posts to it.
		$file = fopen($guestbook, "a");
		// Write $string to the text file and replace bad characters to avoid XSS attacks.
		fwrite($file, nl2br(strip_tags($string, "<b><hr><font>")));
		// Close the file we opened.
		fclose($file);
		echo '<script>alert("Your comment has been added ")</script>';
	} else {
		// Of the form fields are empty will there popup a message.
		echo '<script>alert("Please fill out the whole form")</script>';
	}
}

$readfile = fopen($guestbook, "r");
   echo @fread($readfile, filesize($guestbook));
   fclose($readfile);

?>

Link to comment
Share on other sites

here is the html :

 

<form id="form1" name="form1" method="post" action="<?= $PHP_SELF ?>">
  <label>
  
  <div align="center">
    <table width="100" border="0">
      <tr>
        <td height="20"><p>
          <font size="2px"  ><strong><center>Name</strong><br /></font>
          <input type="text" name="name" id="name" style="border: 1px solid #2766c5;"/>
          <br />
          <br />
          
          <p><font size="2px"  ><strong>Message</strong><br /></font>
            <textarea wrap="hard" name="message" id="message" cols="16" rows="6"  style="border:1px solid #2766c5;"></textarea>
          </p>
          <p>
          <input type="image" src="http://www.chcsc.org/images/submit.jpg" name="button" id="button" value="Submit" STYLE="background-color:#2766c5;" />
          <input type="image" src="http://www.chcsc.org/images/reset.jpg" name="button2" id="button2" value="Reset" />
        </p></td>
      </tr>
    </table>
  </div></label>

</form>

 

Link to comment
Share on other sites

You are going to find that your form does not work in Opera as well because both IE and Opera are following the w3.org specification (exactly) of sending the x,y coordinates where the type="image" button was clicked. They won't send $_POST['button'] or $_POST['button2']. They will send the _x and _y versions of those as described at this link in the php documentation - http://us3.php.net/manual/en/faq.html.php#faq.html.form-image

 

All the browsers send the x,y coordinates, so once you change your code to use either the _x or _y variable name, it will work in all browsers.

 

If you only have one submit button in your form that you need to test, you could also use a hidden field or append a get variable on the end of the URL in the action="..." attribute, or test if the 'REQUEST_METHOD' is POST (assuming you are using post for your form), but these things won't work if you need to test for more than one submit button in a form.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.