Wrox Home  
Search P2P Archive for: Go

  Return to Index  

pro_php thread: validating selectboxes


Message #1 by "morad" <moradphp@h...> on Tue, 24 Dec 2002 15:23:03
Ok, your URL example doesn't match your code.

Your code would have the URL:
http://www.url.com/page.php?cat=0001&type=ISBN&data=123&ent

Second, your for loop is creating to location headers.  Not one with
appended data.  So if two select boxes are used, your for loop would return
this (assuming the URL in the code is the correct one):

http://www.url.com/page.php?cat=0001&type=ISBN&data=123&ent
http://www.url.com/page.php?cat=0001&type=ISBN&data=1234&ent

So, the first thing you are going to have to decide is how you want to
handle multiple data.

Since you are using an array, I am going to assume you want to handle this
dynamically.

Let's assume you'll just use multiple "data" variables (data1, data2, etc.).

Next, for the loop to work correctly, you need to separate the static
content from the dynamic.

$myURL = "http://www.url.com/page.php?cat=0001&type=ISBN";
$myURLend = "&ent=20";

Now you'll add your loop.

$count=count($assigned_to);
    for ($i=0; $i<$count; $i++) {
    // Going to add the data elements onto the first part of the URL
    // "data" . $i + 1 will give us the incremented element name.
    // Do not use +1 if you are ok with starting with 0
    $myURL .= "&data" . $i + 1 . "=" . $assigned_to[$i];
    }

// Now append the last of your URL

    $myURL .= $myURLend;

This will let you append dynamic amounts of information to your URL.  Of
course the page receiving will have to check to see how many elements you
will be getting.

As usual, double check code submissions.  It is written on the fly so not
debugged.

Adam Lang
Systems Engineer
Rutgers Casualty Insurance Company
http://www.rutgersinsurance.com
----- Original Message -----
From: "morad" <moradphp@h...>
To: "professional php" <pro_php@p...>
Sent: Tuesday, December 24, 2002 3:23 PM
Subject: [pro_php] validating selectboxes


> Hello!I have exhausted all avenues before asking the pro channel!
>
> I have a question regarding html page being validated through php.
> I would like to have multiple select boxes that will allow users to
> select a shirt size and when they submit it the value(value="123") would
> be attached to a link like that in turn will take them to the appropriate
> page.
> this would be the link.
> http://www.url.com/page.php?cat=0001&type=ISBN=123&ent
>
> that would take the user to the appropriate place based on their
> selection and the value in the select field. Now I am able to do this
> with one select box, but when I add more than one I have a problem trying
> to validate it because of the naming convention that I try to use. How do
> I go abouts trying to have it so I can maybe have the same name for each
> select box or even the same name but a number at the end of it. Such as
> selectbox1, selectbox2
>
> this is what it looks like with two boxes.
>
> php--------------------
> <?php
>   $count=count($assigned_to);
>     for ($i=0; $i<$count; $i++) {
>   echo header("location:http://www.url.com/page.php?
> cat=0001&type=ISBN&data=".$assigned_to[$i]."&ent=20");
>   }
> ?>
> ----------------------------
>
> HTML----------------
> <form action="passing.php" method="get">
> <SELECT NAME="assigned_to[]" >
>           <option selected value="0">Select Size</option>
>           <option value="123">Small</option>
>           <option value="1234">Medium</option>
>           <option value="1233">Large</option>
>           <option value="12333">X-Large</option>
>   </SELECT>
>
> <br>2nd
> <SELECT NAME="assigned_to[]" >
>     <OPTION VALUE="0" SELECTED>Select Size</OPTION>
>     <OPTION VALUE="111">Small</OPTION>
>     <OPTION VALUE="112">Medium</OPTION>
>     <OPTION VALUE="122">Large</OPTION>
>     <OPTION VALUE="323">X-Large</OPTION>
>     <OPTION VALUE="222">XXL-Large</OPTION>
>     <OPTION VALUE="222">XXX- Large</OPTION>
> </SELECT>
> <input type=submit name=hit value=submit>
> </form>
>
>
> All the assistance is greatly appreciated....
> I hope I gave enough info to determine what the problem is or how to go
> about fixing it....
>
> THaks to all.


  Return to Index