MSIE returns different type than Firefox

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
bbonhomme
Forum Newbie
Posts: 2
Joined: Sat Feb 27, 2010 8:25 pm

MSIE returns different type than Firefox

Post by bbonhomme »

Hi,

If you save the following snippet as testcal.php, and run it in Firefox, $_POST['month'] will return 4, 5 or 6 when you click on one of the three buttons. If you run it in MSIE, $_POST['month'] will return April, May or June. A) Is this standard behavior for MSIE or am I doing something wrong with the buttons? B) When I try a test like if ($_POST['month'] == 'Avril') $month = 4; echo $month; $month isn't set (but $_POST['month'] is set).

Code: Select all

<?php
        echo "<form action='testcal.php' method='post'>";
        
        echo "<button class='button validate' type='submit' name='month' value='4'><font size=4 >4</font>April</button>";
    echo "&nbsp;&nbsp;";
     
        echo "<button class='button validate' type='submit' name='month' value='5'><font size=4 >5</font>May</button>";
    echo "&nbsp;&nbsp;";
 
        echo "<button class='button validate' type='submit' name='month' value='6'><font size=4 >6</font>June</button>";
        echo "&nbsp;&nbsp;";
        
        echo "</form>";
        
        if (isset($_POST['month']))
        {
        echo $_POST['month']
        }
  ?>
Thank you,

Alain

-----
s.dot - Please use [ php ] and [ /php ] tags to post php code.
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Re: MSIE returns different type than Firefox

Post by s.dot »

IE will be different than other browsers.

From: http://www.w3schools.com/tags/tag_button.asp
Browser Support

Internet Explorer Firefox Opera Google Chrome Safari

The <button> tag is supported in all major browsers.

Important: If you use the button element in an HTML form, different browsers will submit different values. Internet Explorer will submit the text between the <button> and </button> tags, while other browsers will submit the content of the value attribute. Use the input element to create buttons in an HTML form.
In other words, use

Code: Select all

<input type="submit" name="month" value="4">
$month = 4; echo $month; $month isn't set (but $_POST['month'] is set)
Show us your code pertaining to this problem.
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
bbonhomme
Forum Newbie
Posts: 2
Joined: Sat Feb 27, 2010 8:25 pm

Re: MSIE returns different type than Firefox

Post by bbonhomme »

Thanks for your reply.

If I do this:

echo "<form method='post'>";

echo "<input type='submit' name='month' value='4'><font size=4 >April</font></input>";
echo "&nbsp;&nbsp;";

echo "<input type='submit' name='month' value='5'><font size=4 >May</font></input>";
echo "&nbsp;&nbsp;";

echo "<input type='submit' name='month' value='6'><font size=4 >June</font></input>";
echo "&nbsp;&nbsp;";

echo "</form>";

Then the buttons have numbers on them (4, 5 and 6), and the text (the month names) is displayed next to them. Is there a way to display the month names on the buttons and retrieve 4, 5 or 6 when a user clicks on one of them?

As for testing on the value of $_POST['month'], this is while in MSIE. Like you said, in MSIE, Internet Explorer will submit the text between the <button> and </button> tags. However, I can't seem to identify or test for that text:

echo "<form method='post'>";

echo "<button type='submit' name='month' value='4'><font size=4 >April</font></button>";
echo "&nbsp;&nbsp;";

echo "<button type='submit' name='month' value='5'><font size=4 >May</font></button>";
echo "&nbsp;&nbsp;";

echo "<button type='submit' name='month' value='6'><font size=4 >June</font></button>";
echo "&nbsp;&nbsp;";

echo "</form>";

if (isset($_POST['month']))
if ($_POST['month'] == "April")
$month = 4;
echo $month;


In this example, $month is not set.

Alain
Post Reply