DanielHardy Posted August 11, 2009 Share Posted August 11, 2009 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); ?> Quote Link to comment Share on other sites More sharing options...
taquitosensei Posted August 11, 2009 Share Posted August 11, 2009 where's the html for your form? It could be that the html isn't validating and firefox is a little more forgiving than IE. Quote Link to comment Share on other sites More sharing options...
DanielHardy Posted August 11, 2009 Author Share Posted August 11, 2009 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> Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted August 11, 2009 Share Posted August 11, 2009 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. Quote Link to comment Share on other sites More sharing options...
DanielHardy Posted August 11, 2009 Author Share Posted August 11, 2009 Lovely As always an easy fix. Thankyou Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.