Page 1 of 1
I need help with form
Posted: Tue Oct 04, 2005 2:24 am
by vigour
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?
Posted: Tue Oct 04, 2005 2:50 am
by mickd
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>';
something like that?
Posted: Tue Oct 04, 2005 3:00 am
by ruchit
its always better to post your own code.. then ask for corrections rather than script requests...
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>';
Posted: Tue Oct 04, 2005 3:22 am
by vigour
Yes this works, thanks. Is it possible to have a .jpg picture instead of the standard submit button?
mickd wrote: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>';
something like that?
Posted: Tue Oct 04, 2005 3:35 am
by vigour
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?
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 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>';
Posted: Tue Oct 04, 2005 3:40 am
by mickd
yes it is. use
Code: Select all
<input type="image" name="imagename" src="imagepath" alt="ifpiccantloadwhattext">
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
Code: Select all
if(isset($_POST['imagename_x'])) {
echo 'this will work';
}
if(isset($_POST['imagename'])) {
echo 'this WONT work';
}
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 _.
Posted: Tue Oct 04, 2005 4:32 am
by vigour
Thanks, that works. How do I know what row I clicked on?
mickd wrote:yes it is. use
Code: Select all
<input type="image" name="imagename" src="imagepath" alt="ifpiccantloadwhattext">
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
Code: Select all
if(isset($_POST['imagename_x'])) {
echo 'this will work';
}
if(isset($_POST['imagename'])) {
echo 'this WONT work';
}
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 _.
Posted: Tue Oct 04, 2005 4:52 am
by pilau
Why do that if you could just set a background-image using CSS to the submit button?
Posted: Tue Oct 04, 2005 6:11 am
by mickd
replace
Code: Select all
<input type="submit" name="submit" value="Buy" />
with
Code: Select all
<input type="image" name="imagename" src="imagepath" alt="ifpiccantloadwhattext" />
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
Code: Select all
style="background-image: path/to/file"
into the input tag
Code: Select all
<input type="submit" name="submit" value="Buy" style="background-image: path/to/file.jpg" />