From:             danielcottrell at operamail dot com
Operating system: Web Server is running Windows
PHP version:      5.2.2RC2
PHP Bug Type:     Unknown/Other Function
Bug description:  Arrays in Forms laid out using tables

Description:
------------
If you use javascript to create a textbox in forms which is laid out using
tables, the data from the new elements will not be detected by php. This
does not happen with the same script where tables are not used (I have
before and after to show below).

post_max_size was set to 20M and upload_max_filesize was set to 30M in
php.ini

Reproduce code:
---------------
-------------------Script A - Tableless ------------------

<?

if(isset($_POST['submit']))
{
  foreach($_POST['animals'] as $anim => $a)
  {
    echo $anim.' '.$a.'<br />';
  }
}

?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd";>
<html>
<head>
<script language="javascript">
<!--
var curUser=3;

function add_row()
{
      var af=document.getElementById('anim_tab');

      //First Name
      var inone=document.createElement("input");
      inone.name="animals["+curUser+"]";
          inone.type="text";
          inone.value="";
      //Append the cells to the row
          var myp=document.createElement('p');
          
      af.appendChild(inone);
          af.appendChild(myp);
          curUser++;
}

-->
</script>

<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<form method="post" action="" id="anim_form">

<div style="border:0;" id="anim_tab">
<?
  for($i=0;$i<3;$i++)
  {
    echo "<input type=\"text\" name=\"animals[]\" style=\"width=400px;\"
/><p />\n";
  }
?>
</div>
<input type="button" name="add" value="Add" onClick="add_row();" />
<input type="submit" name="submit" value="submit" />
</form>

</body>
</html>


----------------------Script B - Tables----------------------------


<?

if(isset($_POST['submit']))
{
  foreach($_POST['animals'] as $anim => $a)
  {
    echo $anim.' '.$a.'<br />';
  }
}

?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd";>
<html>
<head>
<script language="javascript">
<!--
var curUser=3;

function add_row()
{
      var af=document.getElementById("anim_tab");

      var lr = af.rows.length;
          
          var row = document.createElement('tr');
          var td1=document.createElement('td');
      
      //First Name
      var inone=document.createElement("input");
          inone.type="text";
      inone.name="animals["+curUser+"]";
      
      td1.appendChild(inone);
          row.appendChild(td1);
          af.appendChild(row);
          
          curUser++;
}
-->
</script>

<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<table id="anim_tab">
<form method="post" action="" id="anim_form">

<?
  for($i=0;$i<3;$i++)
  {
    echo "<tr><td><input type=\"text\" name=\"animals[]\"
style=\"width=400px;\" /></td></tr>";
  }
?>
</table>
<input type="button" name="add" value="Add" onClick="add_row();" />
<input type="submit" name="submit" value="submit" />
</form>

</body>
</html>

Expected result:
----------------
Data from the textboxes created using the add button should be displayed
when submitted.

The table version works when using IE7 but not when using Opera 9.20 and
Firefox 2. The tableless version works in all browsers.

Actual result:
--------------
Only data from the original form elements is displayed not the javascript
created ones.

Could be a browser bug since IE7 delivers the data fine, but why not
standards compliant browers?


Please don't just fob me off by telling me it's already been fixed.

-- 
Edit bug report at http://bugs.php.net/?id=41260&edit=1
-- 
Try a CVS snapshot (PHP 4.4): 
http://bugs.php.net/fix.php?id=41260&r=trysnapshot44
Try a CVS snapshot (PHP 5.2): 
http://bugs.php.net/fix.php?id=41260&r=trysnapshot52
Try a CVS snapshot (PHP 6.0): 
http://bugs.php.net/fix.php?id=41260&r=trysnapshot60
Fixed in CVS:                 http://bugs.php.net/fix.php?id=41260&r=fixedcvs
Fixed in release:             
http://bugs.php.net/fix.php?id=41260&r=alreadyfixed
Need backtrace:               http://bugs.php.net/fix.php?id=41260&r=needtrace
Need Reproduce Script:        http://bugs.php.net/fix.php?id=41260&r=needscript
Try newer version:            http://bugs.php.net/fix.php?id=41260&r=oldversion
Not developer issue:          http://bugs.php.net/fix.php?id=41260&r=support
Expected behavior:            http://bugs.php.net/fix.php?id=41260&r=notwrong
Not enough info:              
http://bugs.php.net/fix.php?id=41260&r=notenoughinfo
Submitted twice:              
http://bugs.php.net/fix.php?id=41260&r=submittedtwice
register_globals:             http://bugs.php.net/fix.php?id=41260&r=globals
PHP 3 support discontinued:   http://bugs.php.net/fix.php?id=41260&r=php3
Daylight Savings:             http://bugs.php.net/fix.php?id=41260&r=dst
IIS Stability:                http://bugs.php.net/fix.php?id=41260&r=isapi
Install GNU Sed:              http://bugs.php.net/fix.php?id=41260&r=gnused
Floating point limitations:   http://bugs.php.net/fix.php?id=41260&r=float
No Zend Extensions:           http://bugs.php.net/fix.php?id=41260&r=nozend
MySQL Configuration Error:    http://bugs.php.net/fix.php?id=41260&r=mysqlcfg

Reply via email to