Bluehost.com Web Hosting $6.95

write jsp /php form so user can control ho many input fields

This is a discussion on write jsp /php form so user can control ho many input fields within the alt.comp.lang.php forums, part of the PHP Programming Forums category; Hi, I currently have an html form with which I gather the same information for 5 items, and then post ...


Go Back   Usenet Forums > PHP Programming Forums > alt.comp.lang.php

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 01-03-2006
ghadley_00@yahoo.com
 
Posts: n/a
Default write jsp /php form so user can control ho many input fields

Hi,

I currently have an html form with which I gather the same information
for 5 items, and then post all the data for processing to a jsp file. I
would like to make a form (using jsp or php) that allows the user to
choose how many items they would like to compare (1 through 5) , and
then have the form change to list the appropriate set(s) of form entry
fields, with each field's variable appropriately named uniquely (e.g.
at present I have Color1, Color2, Color3, Color4, Color5 all as
variables submitted via my form, I would like this naming convention to
continue).

In other words, if the user chooses to only compare 3 items, I would
like for only 3 sets of entry fields to be presented, for each of which
the field names would be fieldname1, fieldname2, fieldname3.

To accomodate the java class file I am sending the data to for
processing, I would also like the code to pass zero values for the
fields not chosen. In other words, if only 3 items are chosen, the
values that would have been submitted for items 4 and 5 are submitted
as zeros.

Any help that can be provided would be greatly appreicated. A
solutionin either jsp or php would be fine.

Best wishes,

George Hadley
ghadley...@yahoo.com

Reply With Quote
  #2 (permalink)  
Old 01-03-2006
Zilla
 
Posts: n/a
Default Re: write jsp /php form so user can control ho many input fields

[snip]

Try something like this:

<?php
$number = $_REQUEST['number']; //Number of items to compare
$the_rest = 5 - $number;
?>
<form action="url_to_send_to.html" method="post">
<?php
$i = 1;
while($i <= $number) {
echo "Item " . $i . "<input type='text' name='fieldname" . $i . "'>";
$i++;
}
if($the_rest > 0) {
$x = 1;
while($x <= $the_rest) {
echo "<input type='hidden' name='fieldname" . $i . "' value='0'>";
$x++;
$i++;
}
}
?>

Zilla.
Reply With Quote
  #3 (permalink)  
Old 01-03-2006
Zilla
 
Posts: n/a
Default Re: write jsp /php form so user can control ho many input fields

I forgot to end the form... Put this at the end:

<input type="submit" value="Whatever">
</form>

Zilla
Reply With Quote
  #4 (permalink)  
Old 01-03-2006
Colin McKinnon
 
Posts: n/a
Default Re: write jsp /php form so user can control ho many input fields

ghadley_00@yahoo.com wrote:

> Hi,
>
> I currently have an html form with which I gather the same information
> for 5 items, and then post all the data for processing to a jsp file. I
> would like to make a form (using jsp or php) that allows the user to
> choose how many items they would like to compare (1 through 5) , and
> then have the form change to list the appropriate set(s) of form entry
> fields, with each field's variable appropriately named uniquely (e.g.
> at present I have Color1, Color2, Color3, Color4, Color5 all as
> variables submitted via my form, I would like this naming convention to
> continue).
>


Why not do it in javascript - that way you don't need to submit between
changing the number of rows.

C.
Reply With Quote
  #5 (permalink)  
Old 01-04-2006
ghadley_00@yahoo.com
 
Posts: n/a
Default Re: write jsp /php form so user can control ho many input fields

Thanks to all who replied. The php version looks great, but I would
like the option to not have to resubmit to change the number of rows -
would you mind showing / pointing to a code sample that could do this?

Thanks,

George

Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 03:22 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0