We help IT Professionals succeed at work.

Populating a form from another from...

aej1973
aej1973 asked
on
Hello:

I have a PHP form that picks up data from the data base based on query. This form has 8 fields that are populated. There are two other fields ( comment , status ) that needs to be filled in once this form is updated. What I need is that once an updated button is clicked and a radio button selected a new form needs to pop up with pre populated fields corresponding to the row selected, and this form will have two empty fields ( comment and status ) that will be updated. How can I do this? Thanks for the help.

A report to be updated
Comment
Watch Question

Keith BrownAWS System Administrator
CERTIFIED EXPERT

Commented:
The HTML text boxes have a "value" property that you set to what you want to appear in the box when the page loads.

so, an example of this is
<?php
$textval="This is what will load in the box";
echo "<input type='text' size='25' value='".$textval."' />"
?>

Open in new window

First of all, if you want to select multiple rows use "checkbox" not radio buttons. Radio button will let you select one row at a time. What you need to do is get the id of the row which is selected and populate the results for just that row once the radio button is clicked or checkbox is checked.

Author

Commented:
I did not get you. How do I populate my text box with the data from the row I have selected?  The unique value in the row is the wo_code, I need to pass this wo_code and run the query with reference with this wo_code that was selected,I am having difficulty passing this code. I have attached the php script that outputs the data show in the image file I uploaded. Thanks for the help.
<?php
//session_start();
//if (isset($_SESSION['user'])) 
include "connect.php";
$tempdate1 = $_POST['date1'];
$tempdate2 = $_POST['date2'];


//$yesterdate = date('Y-m-d', strtotime($tempdate) - 86400);
$sql = "select w.wo_code, w.account_num, w.order_date, w.schedule_date,  w.wo_notes, w.type, w.city, w.state from work_order w
where w.order_date between '$tempdate1' and '$tempdate2'"; 
$result = mysql_query($sql);
?>

::::::::::some HTML code followed by the PHP code shown below::::

<?php
if (!mysql_num_rows($result)){
?>
<tr>
  <td colspan="11"><div align="center"><span class="style3">No work orders for this period</span></div></td>
</tr>
<?php
}
while ($row=mysql_fetch_assoc($result)){
?>
<tr bordercolor="#660066"   class="tableData">
  <td><input type="radio" name="radio" id="woSelect" value="woSelect">
    <label for="woSelect"></label></td>
<td> <?=$row['wo_code']?></td>
<td><?=$row['account_num']?></td>
<td><?=$row['order_date']?></td>
<td><?=$row['schedule_date']?></td>
<td><?=$row['wo_notes']?></td>
<td><?=$row['type']?></td>
<td><?=$row['city']?></td>
<td><?=$row['state']?></td>
<td>&nbsp;</td>
<td><form name="form1" method="post" action="updates.php">
  <input type="submit" name="update" id="update" value="Update">
</form></td>
</tr>  
 
<?php
}
?>
</table>

Open in new window

report.jpg

Author

Commented:
Hello Pranjal: I am using the radio button since I need to select only one row. Actually the radio button can be dropped if I am going to use a select button on each row.
Change you from method from post to get

<form name="form1" method="get" action="updates.php">

Change the value of the radio button to the id of the row

<input type="radio" name="radio" id="woSelect" value="<?=$row['wo_code']?>">

After doing this, if you select the wo_code=2 row, when you click the update button, your URL will look something like,

updates.php?radio=2

in your updates.php do

$wo_code = $_GET['radio'] // this will be your unique wo_code from which you can get the rest of the info
Top Expert 2011

Commented:
To open a new row when an item is clicked, you can use JavaScript to open a new window at a specified URL with whatever parameters you want to pass along.

<html>
<head>
</head>
<body>
<form>
  <input type="radio" name="ID" value="1" onclick="newWin(this.form,'200','600');">&nbsp;1<br/>
  <input type="radio" name="ID" value="2" onclick="newWin(this.form,'200','600');">&nbsp;2
</form>

<script language="javascript" type="text/javascript">
function newWin(form,Height,Width){
    var url = "somepage.html";
    for (var i = 0; i < form.ID.length; i++) {
        if (form.ID[i].checked) {
            break
        }
    }

    //alert("You chose " + form.ID[i].value + ".")
    url += "?ID=" + form.ID[i].value;

    newwindow=window.open(url,'name','height='+Height+',width='+Width);
    if (window.focus) {newwindow.focus()}
}
</script>
</body>
</html>

Open in new window


This scenario only passes along the specified ID of the row you selected, presuming that you would populate the pop-up with values from the database, rather than passing each and every value into the URL... You could, of course, expand this to pass along additional field values as parameters to the popup page, just add those values to the URL list so that you end up with:

somepage.html?ID=1&param2=something&param3=else ...

In the pop-up, the user is going to update the comments and status of the issue(?) and when they submit the update and close the pop-up, you want to re-query the main page?  If so, you can add something this to the pop-up.  This will force a refresh of the main page... of course, this presumes that you want to refresh the entire page...:
<body onunload="window.opener.location.reload(true);">

Open in new window

Commented:
aej1973:

When the page is submitted, the variables are available in the $_POST array if the form was submitted by the POST method or will be in the $_GET array if the form was submitted by the GET method.

If you had a form field named 'quantity' it would be accessed in one of the two methods shown below.

$_POST['quantity'];
$_GET['quantity'];

You can use the associative array variable names just like any other variable.

Regards,

AielloJ

Author

Commented:
Pranjal, I am not sure why it is not working. Attached is my code...
<?php
if (!mysql_num_rows($result)){
?>
          <tr>
            <td colspan="11"><div align="center"><span class="style3">No work orders for this period</span></div></td>
          </tr>
          <?php
}
while ($row=mysql_fetch_assoc($result)){
?>
         
          <tr bordercolor="#660066"   class="tableData">
            
            <td> <?=$row['wo_code']?></td>
            <td><?=$row['account_num']?></td>
            <td><?=$row['order_date']?></td>
            <td><?=$row['schedule_date']?></td>
            <td><?=$row['wo_notes']?></td>
            <td><?=$row['type']?></td>
            <td><?=$row['city']?></td>
            <td><?=$row['state']?></td>
            <td>&nbsp;</td>
            <td><input name="radio" type="radio" id="WoSelect" value="<?=$row['wo_code']?>"></td>
          </tr>
          
          <?php
}

?>
 <tr bordercolor="#660066"   class="tableData">
            <td colspan="10"><form name="form1" method="get" action="updates.php">
              <div align="center">
                <input type="submit" name="Submit" id="Submit" value="Submit">
              </div>
            </form></td>
          </tr>

        </table>

Open in new window

report.jpg
Your radio element should be under the form tag. You can start your form tag before you started the table.

Author

Commented:
Pranjal, I did not get you. Can you please show me what you mean. Thanks for the help.

A

<form name="form1" method="get" action="updates.php">
<table>
<?php
if (!mysql_num_rows($result)){
?>
          <tr>
            <td colspan="11"><div align="center"><span class="style3">No work orders for this period</span></div></td>
          </tr>
          <?php
}
while ($row=mysql_fetch_assoc($result)){
?>
         
          <tr bordercolor="#660066"   class="tableData">
            
            <td> <?=$row['wo_code']?></td>
            <td><?=$row['account_num']?></td>
            <td><?=$row['order_date']?></td>
            <td><?=$row['schedule_date']?></td>
            <td><?=$row['wo_notes']?></td>
            <td><?=$row['type']?></td>
            <td><?=$row['city']?></td>
            <td><?=$row['state']?></td>
            <td>&nbsp;</td>
            <td><input name="radio" type="radio" id="WoSelect" value="<?=$row['wo_code']?>"></td>
          </tr>
          
          <?php
}

?>
 <tr bordercolor="#660066"   class="tableData">
            <td colspan="10">
              <div align="center">
                <input type="submit" name="Submit" id="Submit" value="Submit">
              </div>
            </td>
          </tr>

        </table>
</form>

Open in new window

Author

Commented:
Thank you so much, that works.

Explore More ContentExplore courses, solutions, and other research materials related to this topic.