Current location: Hot Scripts Forums » Programming Languages » PHP » How To Make Form Processor Handle Unlimited Fields


How To Make Form Processor Handle Unlimited Fields

Reply
  #1 (permalink)  
Old 01-19-05, 02:16 PM
cebuy cebuy is offline
Newbie Coder
 
Join Date: Jun 2003
Posts: 78
Thanks: 0
Thanked 0 Times in 0 Posts
How To Make Form Processor Handle Unlimited Fields

I have a form that is dynamically generated with php but I am trying to code for it to email the differnt color options of a product. My problem is this.. if they choose 10 products in form then they can choose a different color for each one and I have these form names generated by the script...
p1_options_pitcher2
p1_options_pitcher3
p1_options_pitcher4
p1_options_pitcher5
p1_options_pitcher6
p1_options_pitcher7
p1_options_pitcher8
p1_options_pitcher9
p1_options_pitcher10

Example of 2 products chosen's form output..
PHP Code:

 <br><br> <font size=1 face=arial>Choose 2 Product Color:</font> <select name="p1_options_pitcher2">

                                                              <
option selected>Pick Color</option>
                                                              <
option value="Blue">Blue</option>
                                                              <
option value="Green">Green</option>
                                                              <
option value="Yellow">Yellow</option>
                                                              <
option value="Yellow/Blue">Yellow/Blue</option>
                                                              <
option value="Yellow/Green">Yellow/Green</option>
                                                              </
select>
                                                     <
br><br> <font size=1 face=arial>Choose 3 Product Color:</font>        
                                                              <
select name="p1_options_pitcher3">
                                                              <
option selected>Pick Color</option>
                                                              <
option value="Blue">Blue</option>
                                                              <
option value="Green">Green</option>
                                                              <
option value="Yellow">Yellow</option>
                                                              <
option value="Yellow/Blue">Yellow/Blue</option>
                                                              <
option value="Yellow/Green">Yellow/Green</option>
                                                              </
select
NOw my question is this... Is there any way to get a form to accept ANY form field field posted to it? What I am trying to say, is that I do not want to code for 50 like this...

PHP Code:

if (p1_options_pitcher2) {echo $p1_options_pitcher2;} else {} 

if (
p1_options_pitcher3) {echo $p1_options_pitcher3;} else {} 
if (
p1_options_pitcher4) {echo $p1_options_pitcher4;} else {} 
if (
p1_options_pitcher5) {echo $p1_options_pitcher5;} else {} 
if (
p1_options_pitcher6) {echo $p1_options_pitcher6;} else {} 
if (
p1_options_pitcher7) {echo $p1_options_pitcher7;} else {} 
if (
p1_options_pitcher8) {echo $p1_options_pitcher8;} else {} 
if (
p1_options_pitcher9) {echo $p1_options_pitcher9;} else {} 
if (
p1_options_pitcher10) {echo $p1_options_pitcher10;} else {} 
if (
p1_options_pitcher11) {echo $p1_options_pitcher11;} else {} 
if (
p1_options_pitcher12) {echo $p1_options_pitcher12;} else {} 
if (
p1_options_pitcher13) {echo $p1_options_pitcher13;} else {} 
if (
p1_options_pitcher14) {echo $p1_options_pitcher14;} else {} 
if (
p1_options_pitcher15) {echo $p1_options_pitcher15;} else {} 
if (
p1_options_pitcher16) {echo $p1_options_pitcher16;} else {} 
if (
p1_options_pitcher17) {echo $p1_options_pitcher17;} else {} 
if (
p1_options_pitcher18) {echo $p1_options_pitcher18;} else {} 
if (
p1_options_pitcher19) {echo $p1_options_pitcher19;} else {} 
if (
p1_options_pitcher20) {echo $p1_options_pitcher20;} else {} 
if (
p1_options_pitcher21) {echo $p1_options_pitcher21;} else {} 
if (
p1_options_pitcher22) {echo $p1_options_pitcher22;} else {} 
if (
p1_options_pitcher23) {echo $p1_options_pitcher23;} else {} 
if (
p1_options_pitcher24) {echo $p1_options_pitcher24;} else {} 
if (
p1_options_pitcher25) {echo $p1_options_pitcher25;} else {} 
if (
p1_options_pitcher26) {echo $p1_options_pitcher26;} else {} 
if (
p1_options_pitcher27) {echo $p1_options_pitcher27;} else {} 
if (
p1_options_pitcher28) {echo $p1_options_pitcher28;} else {} 
if (
p1_options_pitcher29) {echo $p1_options_pitcher29;} else {} 
if (
p1_options_pitcher30) {echo $p1_options_pitcher30;} else {} 
if (
p1_options_pitcher31) {echo $p1_options_pitcher31;} else {} 
if (
p1_options_pitcher32) {echo $p1_options_pitcher32;} else {} 
if (
p1_options_pitcher33) {echo $p1_options_pitcher33;} else {} 
if (
p1_options_pitcher34) {echo $p1_options_pitcher34;} else {} 
if (
p1_options_pitcher35) {echo $p1_options_pitcher35;} else {} 
if (
p1_options_pitcher36) {echo $p1_options_pitcher36;} else {} 
if (
p1_options_pitcher37) {echo $p1_options_pitcher37;} else {} 
if (
p1_options_pitcher38) {echo $p1_options_pitcher38;} else {} 
if (
p1_options_pitcher39) {echo $p1_options_pitcher39;} else {} 
if (
p1_options_pitcher40) {echo $p1_options_pitcher40;} else {} 
if (
p1_options_pitcher41) {echo $p1_options_pitcher41;} else {} 
if (
p1_options_pitcher42) {echo $p1_options_pitcher42;} else {} 
if (
p1_options_pitcher43) {echo $p1_options_pitcher43;} else {} 
if (
p1_options_pitcher44) {echo $p1_options_pitcher44;} else {} 
if (
p1_options_pitcher45) {echo $p1_options_pitcher45;} else {} 
if (
p1_options_pitcher46) {echo $p1_options_pitcher46;} else {} 
if (
p1_options_pitcher47) {echo $p1_options_pitcher47;} else {} 
if (
p1_options_pitcher48) {echo $p1_options_pitcher48;} else {} 
if (
p1_options_pitcher49) {echo $p1_options_pitcher49;} else {} 
if (
p1_options_pitcher50) {echo $p1_options_pitcher50;} else {} 
What if someone orders 51? I do not know how to ask this really but surely someone understands what I am asking. Working on http://www.somethingsouthernpottery....ts_testing.htm order first product to see what I am doing.
__________________
Thanks!
Chris Chandler
WebMaster of:
Loan Quote, Christian eBuy, & North Alabama,
Reply With Quote
  #2 (permalink)  
Old 01-19-05, 03:22 PM
cebuy cebuy is offline
Newbie Coder
 
Join Date: Jun 2003
Posts: 78
Thanks: 0
Thanked 0 Times in 0 Posts
I thought about making the form on second page ask for number of colors of each option instead of what I am trying to do. I think it will be simpler.

Output of Example...
PHP Code:

  Number of:<br>

  
Blue: <input type="text" name="p1_Blue" size="6"> <br>
  
Green: <input type="text" name="p1_Green" size="6"><br>
  
Blue-Green: <input type="text" name="p1_Blue-Green" size="6"etc... 
__________________
Thanks!
Chris Chandler
WebMaster of:
Loan Quote, Christian eBuy, & North Alabama,
Reply With Quote
  #3 (permalink)  
Old 01-21-05, 12:58 AM
nassau nassau is offline
Wannabe Coder
 
Join Date: May 2004
Posts: 211
Thanks: 0
Thanked 0 Times in 0 Posts
if someone has a solution for the original question i'd still be very interested. i have the exact same problem on my hands.

thanks
Reply With Quote
  #4 (permalink)  
Old 01-22-05, 04:12 PM
digioz's Avatar
digioz digioz is offline
Community VIP
 
Join Date: Oct 2003
Location: Chicago, IL
Posts: 2,171
Thanks: 3
Thanked 9 Times in 9 Posts
Maybe I am not understanding your question correctly. But wouldn't it be much easier to put one of the lines:


Code:
 if (p1_options_pitcher2) {echo $p1_options_pitcher2;} else {} 
inside a FOR loop or a do - while loop and have it loop through n times to do what you want?
__________________
Reply With Quote
  #5 (permalink)  
Old 01-22-05, 05:50 PM
cebuy cebuy is offline
Newbie Coder
 
Join Date: Jun 2003
Posts: 78
Thanks: 0
Thanked 0 Times in 0 Posts
Well if you notice, the variable name changes everytime from $p1_options_pitcher2 to $p1_options_pitcher3 and so forth. how would you "generate" the variables based on a certain number (in this case $p1="50"; or whatever)?
__________________
Thanks!
Chris Chandler
WebMaster of:
Loan Quote, Christian eBuy, & North Alabama,
Reply With Quote
  #6 (permalink)  
Old 01-23-05, 07:07 AM
ben.periton ben.periton is offline
Wannabe Coder
 
Join Date: Oct 2004
Posts: 183
Thanks: 0
Thanked 0 Times in 0 Posts
How about something like

PHP Code:

foreach ($_POST as $key=>$value) {

    if ((
strstr($key,'p1_options_pitcher') && isset($key)) {
        echo 
$value;
    }

__________________
Ben Periton
http://ben.periton.co.uk
Reply With Quote
  #7 (permalink)  
Old 01-24-05, 03:04 AM
SwitchBlade SwitchBlade is offline
Newbie Coder
 
Join Date: Jan 2005
Posts: 51
Thanks: 0
Thanked 0 Times in 0 Posts
a for loop would be the easiest thing to do probably
Reply With Quote
  #8 (permalink)  
Old 01-24-05, 11:22 AM
cebuy cebuy is offline
Newbie Coder
 
Join Date: Jun 2003
Posts: 78
Thanks: 0
Thanked 0 Times in 0 Posts
I looked on php.net for information on isset (i am pretty much newbie to all this) and found this example...
PHP Code:

<?php


$a 
= array ('test' => 1'hello' => NULL);

var_dump(isset($a['test']));            // TRUE
var_dump(isset($a['foo']));            // FALSE
var_dump(isset($a['hello']));          // FALSE

// The key 'hello' equals NULL so is considered unset
// If you want to check for NULL key values then try: 
var_dump(array_key_exists('hello'$a)); // TRUE

?>
Do I need to set up an array like this?

Also, please look here for an idea on the overall picture of what I am trying to do... http://www.phpbuilder.com/board/show...4#post10587644 I am not so much doing it like I was at start of this post (as indicated by my post here at 01-19-05 09:22 PM) , but you can see where I am at by going to phpbuilder's forum.
__________________
Thanks!
Chris Chandler
WebMaster of:
Loan Quote, Christian eBuy, & North Alabama,
Reply With Quote
  #9 (permalink)  
Old 01-25-05, 12:30 AM
khurram khan khurram khan is offline
New Member
 
Join Date: Jan 2005
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
you need to do something like this..

PHP Code:

$num_fields 50;


for (
$i 0$i < $50$i++)
{
          print 
"<select name=\"p1_options_pitcher[$i]\">";
          ...
          print 
"</select>";

That will print the form in the first place... then after it is submitted... you can access the form variables by doing something like...

PHP Code:



foreach ($_POST[p1_options_pitcher] as $key=>$val)
{
          print 
"$key$val;"

Reply With Quote
  #10 (permalink)  
Old 01-25-05, 04:39 AM
feha feha is offline
Wannabe Coder
 
Join Date: Mar 2004
Posts: 141
Thanks: 0
Thanked 0 Times in 0 Posts
Contact me I have made a universal form processor
__________________
www.flashwebshop.org/
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
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 On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
RESELLER WEB HOSTING - $9.99/MONTH For 4GB HD & 30GB BW! CPanel, PHP, MySQL & MORE! IncognitoNet General Advertisements 0 11-25-04 02:09 AM
RESELLER WEB HOSTING - $9.99/MONTH For 4GB HD & 30GB BW! CPanel, PHP, MySQL & MORE! IncognitoNet General Advertisements 2 11-12-04 03:25 PM
RESELLER WEB HOSTING - $9.99/MONTH For 4GB HD & 30GB BW! CPanel, PHP, MySQL & MORE! IncognitoNet General Advertisements 0 10-30-04 01:19 PM
formmail problem gscraper Perl 12 08-27-04 03:06 AM
Special Hosting Offers From SiSHCO! Very Hot! SiSHCO General Advertisements 0 06-09-04 01:10 PM


All times are GMT -5. The time now is 05:27 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.