• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1205
  • Last Modified:

Button in first row of html table does not work

Hi all.

I have a php page (see below). Each row of data has a button, if the status is Open then the button is showed otherwise the button is not shown. When the button is clicked it goes to another file (ProcessToDoAction.php). Something weird is happening, the button on the first row of data does not work, meaning it does not go to the file ProcessToDoAction.php but rather it goes to the form's action (LookupResultsConvertJobType.php). And again this only happens on the first row of data, if I click the button on the second row it goes to the correct file (ProcessToDoAction.php).

Any idea why this is happening?

Thank you in advance.

  <head>
  <title>MyPage</title>
  <meta http-equiv="content-type" content="text/html; charset=utf-8" />
  <link rel="stylesheet" href="style.css" type="text/css" />
  <link href="iphone-icon1.png" rel="apple-touch-icon">
  </head>
<body>
      				
<div class="wrapper">
    <div id="logo"></div>
    <form class="form4" action="LookupResultsConvertJobType.php" method="post">
<div class="formtitle4">Lookup Form</div>
  </head>
<body>
  <div class="input3">
                       <div class="inputtext">Job Type:</div>
               <div class="inputcontent" >
                    <?php  foreach($data as $row){ echo '<input type="text" name="jobtype" id="jobtype" value="' . html_escape($row['jobtypedescription']) . '">'; } ?>           
               </div>
               <?php if ($row['Type'] == 1 AND	$row['Status'] <> 'Completed') {
               echo '<input class="button5"  type="submit" value="Convert to D"/><p></p>'; }
               		 
               		 elseif ($row['Type'] == 2 AND	$row['Status'] <> 'Completed') {  // Job type is 2
	               		 echo '<input class="button5"  type="submit" value="Convert Back To S"/><p></p>';
               		 }  ?>              
           
          </div>
           
		  <div class="input3">
            
                <table cellpadding="0" cellspacing="0"  class="db-table" align = "center">
                <tr>
                <th>To Do</th>
                <th>Status</th>
                <th>Date</th>
                <th>Action</th>
                </tr>
                               
                <?php  foreach($data1 as $row){ 
                    echo '<tr>';
                    echo '<td>' . html_escape($row['ToDo']) . '</td>';
                    echo '<td>' . html_escape($row['Status']) . '</td>';
                    echo '<td>' . html_escape($row['ToDoStatusDate']) . '</td>';
                     if ($row['Status'] == 'Open') 
					{
						echo "<td>
						<form action='ProcessToDoAction.php' method='post'>        					
						<input type='text' id='DataEntryID' name='DataEntryID' value='" . html_escape($row['DataEntryID']) . "'/>
						<input type='text' id='todoid' name='todoid' value='" . html_escape($row['ToDoID']) . "'/>
						<input class='button8'  type='submit'  value='Complete'/>
						</form>				
						</td>";
					}

				   else
				   {
					   echo "<td>                 
					   	<input type='hidden' name='todoid' value='" . html_escape($row['ToDoID']) . "'/>      
					   	</td>";   
				  }
                    echo '</tr>';
                   
                } ?>                 
               </table>

			<div class="buttons" align = center>

				<input class="button1"  type="submit" formaction="BacktoLookup.php" value="Search" /> 
				<input class="button1"  type="submit" formaction="Menu.php" value="Menu" /> 
				<input class="button1"  type="submit" formaction="Shortage.php" formmethod="post" value="Shortage" /> 		
			</div>   
</form>
</div>
</body>
</html>

Open in new window

0
Sim1980
Asked:
Sim1980
2 Solutions
 
RobOwner (Aidellio)Commented:
This is to do with nested forms, forms within forms.  You can't do that, which is why you're getting it working once and not after that because the browser has submitted that form but even this could give you unexpected results across browsers (and versions thereof).  

You'll need to rethink your design.

Having said that, I don't think it's going to be too hard but I would need to know more info on both ProcessToDoAction and LookupResultsConvertJobType but I suspect you may be able to call the ProcessToDoAction using ajax (and hence removing those form tags in the rows).  Then you can submit the main form LookupResultsConvertJobType once all rows have been "modified"
0
 
Slick812Commented:
Hello Sim1980, You may have better HTML if you take OUT all of the -
<form action='ProcessToDoAction.php' method='post'>

from the -
<form class="form4" action="LookupResultsConvertJobType.php" method="post">

so the browser can work with a single form at a time, ,

also your HTML is very messed up you have TWO -
</head>
<body>

which can get the browser to be inconsistent.

Also you have this DIV - <div class="input3">  start INSIDE a <form> , BUT it ends with </div>  OUTSIDE that form as -
</form>
</div>

making the browser display inconsistent, , you might try something like -
  <head>
  <title>MyPage</title>
  <meta http-equiv="content-type" content="text/html; charset=utf-8" />
  <link rel="stylesheet" href="style.css" type="text/css" />
  <link href="iphone-icon1.png" rel="apple-touch-icon">
  </head>
<body>
      				
<div class="wrapper">
    <div id="logo"></div>
    <form class="form4" action="LookupResultsConvertJobType.php" method="post">
<div class="formtitle4">Lookup Form</div>
  <div class="input3">
   <div class="inputtext">Job Type:</div>
    <div class="inputcontent" >
<?php  foreach($data as $row){ echo '<input type="text" name="jobtype" id="jobtype" value="' . html_escape($row['jobtypedescription']) . '">'; } ?>           
    </div>
<?php if ($row['Type'] == 1 AND	$row['Status'] <> 'Completed') {
  echo '<input class="button5"  type="submit" value="Convert to D"/><p></p>'; }
  elseif ($row['Type'] == 2 AND	$row['Status'] <> 'Completed') {  // Job type is 2
    echo '<input class="button5"  type="submit" value="Convert Back To S"/><p></p>';
    }  ?>              
  </div>
   
  <div class="buttons" align = center>
  <input class="button1"  type="submit" formaction="BacktoLookup.php" value="Search" /> 
  <input class="button1"  type="submit" formaction="Menu.php" value="Menu" /> 
  <input class="button1"  type="submit" formaction="Shortage.php" formmethod="post" value="Shortage" /> 		
  </div>   
</form>


<div class="input3">
     <table cellpadding="0" cellspacing="0"  class="db-table" align = "center">
<tr>
<th>To Do</th><th>Status</th><th>Date</th><th>Action</th>
</tr>
<?php  foreach($data1 as $row){ 
  echo '<tr>';
  echo '<td>' . html_escape($row['ToDo']) . '</td>';
  echo '<td>' . html_escape($row['Status']) . '</td>';
  echo '<td>' . html_escape($row['ToDoStatusDate']) . '</td>';
  if ($row['Status'] == 'Open') {
    echo "<td>
    <form action='ProcessToDoAction.php' method='post'>        					
    <input type='text' id='DataEntryID' name='DataEntryID' value='" . html_escape($row['DataEntryID']) . "'/>
    <input type='text' id='todoid' name='todoid' value='" . html_escape($row['ToDoID']) . "'/>
    <input class='button8'  type='submit'  value='Complete'/>
    </form>				
    </td>";
  } else {
  echo "<td>                 
  <input type='hidden' name='todoid' value='" . html_escape($row['ToDoID']) . "'/>      
  </td>";   
  }
  echo '</tr>';
} ?>                 
    </table>
</div>

Open in new window

notice that I removed ALL of the <div class="input3"> OUTSIDE of the -
<form class="form4" action="LookupResultsConvertJobType.php" method="post">
    <form> code
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now