I need help with form
Moderator: General Moderators
I need help with form
I need a dynamically built form that have several rows that looks the same.
1 - Each of the rows should have a buy button that takes me to another php document.
2 - Each row should have a textfield with quantity.
When I click on the buy botton I want to read the value in the textfield for the row I'm clicking on.
I have no problems building the form, but I can't read anything from the textfield so I think I'm doing this completely wrong.
Can someone please post some code for me and explain how to do this?
1 - Each of the rows should have a buy button that takes me to another php document.
2 - Each row should have a textfield with quantity.
When I click on the buy botton I want to read the value in the textfield for the row I'm clicking on.
I have no problems building the form, but I can't read anything from the textfield so I think I'm doing this completely wrong.
Can someone please post some code for me and explain how to do this?
Code: Select all
$result = mysql_query("SELECT * FROM table"); // add limitations if you want
echo '<table width="100%" align="center"><form method="post" action="pagetopostto">';
echo '<tr>
<td width="33%">
What to buy:
</td>
<td width="33%">
How many to buy:
</td>
<td width="33%">
SUBMIT
</td>
</tr>';
while($row = mysql_fetch_assoc($result)) { // goes through the results
echo '<tr>
<td width="33%">
' . $row['name'] . '<input type="hidden" name="whattobuy" value="' . $row['name'] . '" />
</td>
<td width="33%">
<input type="text" name="quantity" />
</td>
<td width="33%">
<input type="submit" name="submit" value="Buy" />
</td>
</td>';
}
echo '</table></form>';its always better to post your own code.. then ask for corrections rather than script requests...
i guess its one of your lucky days
i guess its one of your lucky days
Code: Select all
$counter=1;
$maxRows=5;
echo '<table width="100%">';
while($counter <= $maxRows){
echo "<form name=\"frm{$counter}\" action=\"secondfile.php\" method=\"post\">";
echo '<tr><td><input type="text" name="text" value=""></td>
<td><input type="submit" name="submit" value="Buy"></td></tr>';
echo '</form>';
}
echo '</table>';Yes this works, thanks. Is it possible to have a .jpg picture instead of the standard submit button?
mickd wrote:something like that?Code: Select all
$result = mysql_query("SELECT * FROM table"); // add limitations if you want echo '<table width="100%" align="center"><form method="post" action="pagetopostto">'; echo '<tr> <td width="33%"> What to buy: </td> <td width="33%"> How many to buy: </td> <td width="33%"> SUBMIT </td> </tr>'; while($row = mysql_fetch_assoc($result)) { // goes through the results echo '<tr> <td width="33%"> ' . $row['name'] . '<input type="hidden" name="whattobuy" value="' . $row['name'] . '" /> </td> <td width="33%"> <input type="text" name="quantity" /> </td> <td width="33%"> <input type="submit" name="submit" value="Buy" /> </td> </td>'; } echo '</table></form>';
Yes it's my lucky day
Thanks. And try to increase the counter next time
Is it possible to use a .jpg picture instead of the standard submit button?
Is it possible to use a .jpg picture instead of the standard submit button?
ruchit wrote:its always better to post your own code.. then ask for corrections rather than script requests...
i guess its one of your lucky daysCode: Select all
$counter=1; $maxRows=5; echo '<table width="100%">'; while($counter <= $maxRows){ echo "<form name="frm{$counter}" action="secondfile.php" method="post">"; echo '<tr><td><input type="text" name="text" value=""></td> <td><input type="submit" name="submit" value="Buy"></td></tr>'; echo '</form>'; } echo '</table>';
yes it is. use
btw when using that and your refering to it in the posted page in PHP, you gotta add _x or _y at the end for example
its because when the form is sent it sends imagename.x and imagename.y as the x and y length. then since you cant have . in the name, it gets auto changed to _.
Code: Select all
<input type="image" name="imagename" src="imagepath" alt="ifpiccantloadwhattext">Code: Select all
if(isset($_POST['imagename_x'])) {
echo 'this will work';
}
if(isset($_POST['imagename'])) {
echo 'this WONT work';
}Thanks, that works. How do I know what row I clicked on?
mickd wrote:yes it is. use
btw when using that and your refering to it in the posted page in PHP, you gotta add _x or _y at the end for exampleCode: Select all
<input type="image" name="imagename" src="imagepath" alt="ifpiccantloadwhattext">
its because when the form is sent it sends imagename.x and imagename.y as the x and y length. then since you cant have . in the name, it gets auto changed to _.Code: Select all
if(isset($_POST['imagename_x'])) { echo 'this will work'; } if(isset($_POST['imagename'])) { echo 'this WONT work'; }
replace
with
use the hidden field to tell the script when its posted to know what to buy.
could use style to add the background image to the submit too if you want.
add
into the input tag
Code: Select all
<input type="submit" name="submit" value="Buy" />Code: Select all
<input type="image" name="imagename" src="imagepath" alt="ifpiccantloadwhattext" />could use style to add the background image to the submit too if you want.
add
Code: Select all
style="background-image: path/to/file"Code: Select all
<input type="submit" name="submit" value="Buy" style="background-image: path/to/file.jpg" />