i've a situation where i've to show forms just like excel sheet and then against each row there is a submit button ,Once submit button is clicked data is saved against that row , row is disabled and focus is set to next line automatically
see my screenshot what i've
i'm creating form using this code
<table border="1" cellspacing="5">
<?php
for ($index = 0; $index <4; $index++) {
echo "<form method='post' action='' id='myform'>";
echo"<tr>";
echo"<td><input type='text' name='name$index'></td>";
echo"<td><input type='text' name='email$index'></td>";
echo"<td><input type='submit' name='submit$index'></td>";
echo"</tr>";
echo "</form>";
}
?>
</table>
when i enter data in first form i'm able to get it and save in database but i really not getting how can i go to second line and then process it , please help me about it as i am new and not sure if i am using right approach to do it
I think you should assign to your submit button for each row the same name and a value related to the id eg: the index
<table border="1" cellspacing="5">
<?php
for ($index = 0; $index <4; $index++) {
echo "<form method='post' action='' id='myform'>";
echo"<tr>";
echo"<td><input type='text' name='name$index'></td>";
echo"<td><input type='text' name='email$index'></td>";
echo"<td><input type='submit' name='my_action' value="$index"></td>";
echo"</tr>";
echo "</form>";
}
?>
</table>
In your Server myRelatedAction.php you can easily obtain the index submitted
$my_index = $_POST['my_action'] ;
Related
i have some problem in here. I have textbox value inside table, and when i clicked link "Valid", i can pass the textbox value to another page.
This is my textbox code in table
echo "<form name='nomor' role='form' method='get'>";
echo "<input type='text' name='nomortempat' class='form-control input-sm'></input>";
echo "</form>";
This is my button
echo "<td class='center'>";
echo "<a class='btn btn-primary btn-sm' href='validasi.php?idorder=" . $row['id_order'] . "&pilih=" . $_GET['pilih'] . "'>
<i class='fa fa-check-square-o'>Valid</i></a>
echo "</td>";
Maybe someone can give me a solution, Thank you and have a nice day!!
In the page validasi.php add this:
$IDorder = $_GET['idorder'];
$Pilih = $_GET['pilih'];
Now you have two variables on validasi.php called IDorder and Pilih from your form
Or is it the nomortempat you want?
I think you can just add
$nomortempat = $_GET['nomortempat'];
to the validasi page and it should work. If I understand your code it should be sent
EDIT I was wrong, you need to add a sumbmit button to your form.
Add session start at the top of your pages: session_start();.
Then add this to your first page:
$_SESSION["idorder"] = $idorder;
$_SESSION["pilih"] = $pilih;
Then this code to your form:
echo "<form name='nomor' role='form' method='get'>";
echo "<input type='text' name='nomortempat' class='form-control input-sm'></input>";
echo "<input type='submit' name='submit' value='Submit'></input>";
echo "</form>";
Then on validasi page add this:
$nomortempat = $_GET['nomortempat']; // and:
$IDorder = $_SESSION["idorder"];
$Pilih = $_SESSION["pilih"];
Now you have all three values on validasi.php
with GET form, you could try this:
echo "<form name='nomor' action='action.php' role='form' method='get'>";
echo "<input type='text' name='nomortempat' class='form-control input-sm'></input>";
echo "<input type='submit' value='valid'>";
echo "</form>";
and in action.php page, to catch value in textbox name='nomortempat', code is below:
if (isset($_GET['nomortempat'])){
echo $_GET['nomortempat'];
}
Of course, you could add more input fields whenever you want to inside form with different names.
I need a help to make the submit button inside the while loop work. I design a code that fetch the value from DB and user has to approve or reject the pulled value. So when user click OK, then the DB should be updated with a OK value. I dont know where is the problem is that my OK button doesnt work,
When user click OK, then it should go to approval.php page
<?php
if ($_POST['action'] == 'show'){
$requestCompSql = "SELECT REQUEST_COMPONENT_CUTTING.PROJECT_NAME,
REQUEST_COMPONENT_CUTTING.BASE_PLATE,
REQUEST_COMPONENT_CUTTING.THICKNESS,
REQUEST_COMPONENT_CUTTING.QTY_REQUESTED,
REQUEST_COMPONENT_CUTTING.REQUESTER,
REQUEST_COMPONENT_CUTTING.REQUEST_DATE
FROM REQUEST_COMPONENT_CUTTING
WHERE REQUEST_COMPONENT_CUTTING.BASE_PLATE = '{$_POST["bp"]}'";
$requestCompParse = oci_parse($conn, $requestCompSql);
oci_execute($requestCompParse);
while($row = oci_fetch_assoc($requestCompParse)){
echo "<form action='approval.php'>";
echo "<div class='table-responsive'>";
echo "<table class='table table-bordered'>";
echo '<table cellspacing = "0"';
echo '<thead>';
echo '<tr>
<th>PROJECT</th>
<th>BASEPLATE</th>
<th>THICKNESS</th>
<th>QTY REQUESTED</th>
<th>REQUESTER</th>
<th>REQ. DATE</th>
<th align="center">ACTION</th>
</tr>
</thead>';
echo "<tbody>";
echo "<tr class='warning'><td>$row[PROJECT_NAME]</td>";
echo "<td>$row[BASE_PLATE]</td>";
echo "<td>$row[THICKNESS]</td>";
echo "<td>$row[QTY_REQUESTED]</td>";
echo "<td>$row[REQUESTER]</td>";
echo "<td>$row[REQUEST_DATE]</td>";
echo "<td><input type='button' value='OK' class='btn btn-success'>
<input type='button' value='REJECT' class='btn btn-danger'></td>";
echo "</tr>";
echo "</tbody>";
echo "<table cellspacing = '0'";
echo "</form>";
echo "</div>";
}
}
?>
For a submit button you need to use
<input type="submit" value="OK">
You used
<input type="button" value="OK">
which can be used for javascript execution. Same for the reject button. You could however send the form with javascript (which is not recommended, as some choose to turn of javascript) by using something like this:
<input type="button" value="OK" onClick="document.forms[0].submit()">
The button needs to be of type="submit" and not only of type="button"
echo "<td><input type='submit' value='OK' class='btn btn-success'>
You have some problems in your code. Firstly if you are posting data through form, then there should be method property for the form like:
echo "<form action='approval.php' method='post'>";
Secondly, if you are submitting the form on clicking the button, then the type of button should be submit instead of button.
<input type='submit' value='OK' class='btn btn-success'>
Since you are using type='button' you should add Javascript to submit the form such as onclick='submit();'
I need to display a list of elements and after each and every element a delete button is added dynamically. Whenever the user presses a delete button the corresponding element should be deleted and rest of the list should be shown.
I have written the following php code to accomplish this:
for($i=0;$i<count($b);$i++)
{
$a=$b[$i];
echo "<li>$b[$i]</li> ";
$p="remove"."$j";
echo "<form action='' method='post'> <input class='z' type='submit' name='$p' value='delete'> </form>";
$j++;
}
if($_POST['$p'])
{
//code for deleting
}
The problem is whenever the user presses the delete button only the last element added is getting deleted and rest of the buttons are not working.Please tell me how to detect which button has been pressed dynamically and delete the corresponding element using php.
Thank you
You need to associate each button with its respective element. You'll wanna do this dynamically with an id or hidden input or something.
for($i=0;$i<count($b);$i++)
{
$a=$b[$i];
echo "<li>" . $b[$i] . "</li> ";
$p="remove" . $i;
echo "<form action='' method='post'>";
echo "<input type='hidden' name='item' value='" . $i . "' />";
echo "<input class='z' type='submit' name='delete' value='delete'> </form>";
$i++;
}
if($_POST['delete'])
{
$item = $_POST['item'];
//code for deleting $item
}
You're putting each delete button in its own form - you could also add in a hidden input with the ID to remove?
echo "<form action='' method='post'>\n";
echo "<input type='hidden' name='toDelete' value='" .$i ."'>\n";
echo "<input class='z' type='submit' name='$p' value='delete'>\n";
echo "</form>\n";
You'd then look for the element to delete with:
if(isset($_POST['toDelete'])) {
// $_POST['toDelete'] has the index number of the element to remove
}
hi i want to store value of each input text in different arrays how to do that
for example store value of input text 1 in array 1 and value of input text 2 in array 2 and so on how to achieve that
here is the code for print input text
for($r=1;$r<=10;$r++)
{
echo"<form id='ponts'>
<table>
<tr>
<td>Enter point number$r</td><td> <input type='text' id='pt$r' name='pt$r' pattern='[0-9.]+'/></td>
</tr>
</table>
</form>";
}
I guess I didn't understand well, but the following script may be what you want.
<?php
$g=$_GET;
if( isset($g['pt']) ){
// the form has been submitted.
$ptValues=$g['pt'];
print_r($ptValues);
}
echo "<form id='ponts'><table>";
for($r=1;$r<=10;$r++)
{
echo "<tr><td> Enter point number$r</td><td> <input type='text' id='pt$r' name='pt[]' pattern='[0-9.]+'/> </td></tr>";
}
echo "</table></form>";
?>
Maybe this:
<?php
$g=$_GET;
if( isset($g['pt0']) ){
// the form has been submitted.
$ptValues=array();
for($i=0; isset($g['pt'.$i]); $i++ )
$ptValues[]=$g['pt'.$i];
print_r($ptValues);
}
echo "<form id='ponts'><table>'";
for($r=1;$r<=10;$r++)
{
echo "<tr><td> Enter point number$r</td><td> <input type='text' id='pt$r' name='pt$r' pattern='[0-9.]+'/> </td></tr>";
}
echo "</table></form>";
?>
maybe this is what u are looking for
echo"<table id='points'>";
for($r=1;$r<=10;$r++)
{
echo"
<tr>
<td>Enter point number".$r."</td><td> <input type='text' id='pt".$r."' name='pt".$r."' pattern='[0-9.]+'/></td>
</tr>
";
}
echo "</table>";
i dont know why you are using the form tags here .
Im am trying to add a check box that will enable/disable the edit button. Im retrieving a price list and displaying it inside a table. When i add the javascript into the php code it doesn't work. Below is my code
<table border="1">
<tr>
<td width="100">Fee % </td>
<td width="100">Price</td>
<td width="100">Total</td>
<td width="102"> </td>
</tr>
<tr>
<?php
$sql1="select * from pricelist";
$result1=mysql_query($sql1) or die(mysql_error());
while ($row=mysql_fetch_array($result1)) {
$id=$row['id'];
$price=$row['h_price'];
$a=0;
print "<form id='form1' name='$a+' method='post' action=''>";
print "<td><input name='fees' value ='$fees' type='text' size='4' /></td>";
print "<td><input name='price' value ='$price' type='text' size='15' /></td>";
echo "<td><input type='checkbox' onclick='this.$a+.disabled = !this.checked;'><td>";
print"<td><input type='submit' name='$a+' value='Submit' disabled='disabled' /></td>";
print "</tr>";
print "</form>";
}
?>
</table>
Can someone please tell me what am i doing wrong?
Thanks
take out the following code out of loop... it creates multiple form tag...
print "<form id='form1' name='$a+' method='post' action=''>";
Place "<tr></tr>" inside the loop...
final code looks like:
<form id='form1' name='fm1' method='post' action=''> <tr>
<?php
$sql1="select * from pricelist";
$result1=mysql_query($sql1) or die(mysql_error());
while ($row=mysql_fetch_array($result1)) {
$id=$row['id'];
$price=$row['h_price'];
$a=0;
print "<tr>";
print "<td><input name='fees' value ='$fees' type='text' size='4' /></td>";
print "<td><input name='price' value ='$price' type='text' size='15' /></td>";
echo "<td><input type='checkbox' onclick='this.$a+.disabled = !this.checked;'><td>";
print"<td><input type='submit' name='$a+' value='Submit' disabled='disabled' /></td>";
print "</tr>";
}
print "</form>";
?>
Next if u want to control the button only then
<input type='checkbox' onclick='document.$a.submit.disabled = !this.checked;' />
and make sure of the following things:
1.) form name should be $a
i.e <form name='$a' ...>
2.) submit buttons name should be submit
i.e <input type='submit' name='submit'...>
3.) increase the $a variable only at the end of loop
i.e
$a++;
}
i think $a+ will cause syntax error. you need to increment $a at the end of loop like $a++. Also see page source and see what is coming from server.
I would recommend using following format for html + php output
<form id='form1' name='<?=$a++?>' method='post' action=''>
<tr>
<td><input name='fees' value ='<?=$fees?>' type='text' size='4' /></td>
<td><input name='price' value ='<?=$price?>' type='text' size='15' /></td>
<td><input type='checkbox' onclick='this.disabled = !this.checked;'><td>
<td><input type='submit' name='<?=$a++?>' value='Submit' disabled='disabled' /></td>
</tr>
</form>
<?
you also need to have < tr > to be in the while loop.
In your html part where you set up the formular you have to use " " to escape the php code. example:
print "<form id='form1' name='".$a+."' method='post' action=''>";
But as Adeel said already, what is $a+ ?
And you have to edit all prints and echoes in the way, that php expressions are excaped from the HTML source.