Welcome to WebmasterWorld Guest from 54.145.173.147

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Form Options

   
10:03 pm on Mar 25, 2003 (gmt 0)

10+ Year Member



I am using PHP/mySQL and I am trying to find out the best way to get some information into a form into my database. I know how to do this when it is very straightforward entry but what if there are multiple ways that my users need to enter information.

This is not for a shipping cart. Basically they need to enter the type of a widget, then size and quantity of that item. I have a standard table that this information goes in to. Now, this is easy to do, but what I don't understand how to implement is sometimes the user needs to enter multiple types of widgets then the size and quantity of that type as well. The form only has options to enter one. Is there a way to have it so if a user clicks 'add another type' basically another <tr> pops up under the last one with new fields to enter the info? I don't want to have to put a whole bunch of rows there when most of the time they only need one row.

Is there a way to do that and then when the user click submit the info goes into multiple rows in a table.

Am I even making sense? heh

Thanks for looking.

-Russell

10:08 pm on Mar 25, 2003 (gmt 0)

WebmasterWorld Administrator jatar_k is a WebmasterWorld Top Contributor of All Time 10+ Year Member



>>Am I even making sense?

yes you are, strangely. ;)

It would depend on how it all works. Might you have the option before they get to that page to have them choose how many entries they need?

I think for the click and add a row you could post to itself maybe and load the desired number of rows with the default being one. Then reload the posted data into the existing rows.

10:17 pm on Mar 25, 2003 (gmt 0)

10+ Year Member



That might work, I also thought it was somehow possible to have dynamic forms with javascript, but them I wouldnt know how to make sure the field names would get entered correctly when submitted. I think I am confusing myself all too much.
10:43 pm on Mar 25, 2003 (gmt 0)

WebmasterWorld Administrator jatar_k is a WebmasterWorld Top Contributor of All Time 10+ Year Member



well if you do it in php then just create the form dynamically and have the field names be the same and append a number to the end.

product1 price1 quantity1
product2 price2 quantity2
product3 price3 quantity3

easy to create dynamically and parse values after. The processing script could do something like

$counter = 1;
while (isset(${product . $counter})) {
do stuff;
$counter++;
}

the form could be built with the rownum
echo "<form name=blah action=something>";
$counter = 1;
while ($counter <= $rownum) {
echo "<input type=text name=product",$counter,">";
echo "<input type=text name=price",$counter,">";
echo "<input type=text name=quantity",$counter,">";
}
echo "</form>";

or something like that.

3:30 am on Mar 26, 2003 (gmt 0)

10+ Year Member



Cool thanks jatar_k, I think I've got it!
11:31 am on Mar 26, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You donīt really need to append a number to the end of the form [w3.org] element names. If multiple form [w3.org] elements have the same name PHP [php.net] will turn them into arrays.

Andreas

2:43 pm on Mar 26, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You will have to add [] though.

Andreas