I'm trying to figure out how to get the choices in a form's drop-down list to act as links, without using cgi. Does anyone have any idea how to do this?

    Set links as a values for your options and then call out the script (form handler) like this:

    <?php 
    
    if(isset($_POST['link'])){
          $link = $_POST['link'];
          header("Location:$link");
    }
    ?>

      Thanks for the quick response, bodzan. What you're saying then is that I will need 2 documents, one that has the form, and one that is referenced by the ACTION= attribute of the "<FORM>" tag. The document that is referenced by the ACTION= would contain the code above, yes?

      As you can tell, I'm rather new at this - any further help would be appreciated!

        That is the main idea I had in this.

        You should mind that this is not the best solution that you can have.

        One much better and safer is to have one document where the dropdown is populated with numbers instead of links. Like:

        <form action="other_page.php" method="post">
        
        <select name="links">
        <option value="1">Link 1</option>
        <option value="2">Link 2</option>
        <option value="3">Link 3</option>
        <option value="4">Link 4</option>
        <option value="5">Link 5</option>
        <option value="6">Link 6</option>
        </select><br />
        
        <insert type="submit" name="submit" value="Go!" />
        </form>
        

        And in other_page.php you should have a switch statement like:

        if(isset($_POST['links'])){
             switch($_POST['links']){
                  default:
                       header("Location:some_link1.com");
                       break;
                  case 1:
                       header("Location:some_link1.com");
                       break;
                  case 2:
                       header("Location:some_link2.com");
                       break;
                  case 3:
                       header("Location:some_link3.com");
                       break;
                  case 4:
                       header("Location:some_link4.com");
                       break;
                  case 5:
                       header("Location:some_link5.com");
                       break;
                  case 6:
                       header("Location:some_link6.com");
                       break;
             }
        }
        

          Here's what I have (it's not formatted yet - I just want to get it working first):

          template.php:

          <TABLE WIDTH=98% CELLPADDING=0 CELLSPACING=0>

          <TR>
            <TD COLSPAN=3 BGCOLOR=#004488 ALIGN="center"><IMG SRC="images/logo.gif"><BR><BR><FONT SIZE=1><A 

          HREF="pages/site.html">PLACEHOLDER</A></FONT></TD>
          </TR>

          <TR>
            <TD ROWSPAN=5 WIDTH=200px BGCOLOR=#004488 ALIGN="center">

          <FORM ACTION="redirect.php" METHOD="post">
          <SELECT NAME="links">
          <OPTION SELECTED> Please Select</OPTION>
          <OPTION VALUE="1">Sci-Fi Gallery</OPTION>
          <OPTION VALUE="2"> This is Option Number 2</OPTION>
          <OPTION VALUE="3"> This is Option Number 3</OPTION>
          <OPTION VALUE="4"> This is Option Number 4</OPTION>
          <OPTION VALUE="5"> This is Option Number 5</OPTION>
          <OPTION VALUE="6"> This is Option Number 6</OPTION>
          </SELECT><BR>

          <INPUT TYPE="submit" NAME="submit" VALUE="Go!">
          </FORM>
          </TD>
          <TD WIDTH=40%>&nbsp</TD>
          <TD WIDTH=*>&nbsp</TD>
          </TR>
          </TABLE>

          </BODY>

          </HTML>

          redirect.php:

          <HTML>

          <HEAD><TITLE>ReFlash Studios</TITLE>

          </HEAD>

          <BODY BGCOLOR="black" TEXT="white" LINK="white">

          <?php

          if(isset($POST['links'])){
          switch($
          POST['links']){
          default:
          header("Location:http://www.reflashstudios.com/template.php");
          break;
          case 1:
          header("Location:http://www.reflashstudios.com/gall/gall11.html");
          break;
          case 2:
          header("Location:some_link2.com");
          break;
          case 3:
          header("Location:some_link3.com");
          break;
          case 4:
          header("Location:some_link4.com");
          break;
          case 5:
          header("Location:some_link5.com");
          break;
          case 6:
          header("Location:some_link6.com");
          break;
          }
          }

          ?>

          </BODY>

          </HTML>

          Here's the output I get:

          Warning: Cannot modify header information - headers already sent by (output started at /home/reflash/www/www/redirect.php:9) in /home/reflash/www/www/redirect.php on line 17

          The address bar reads "... redirect.php"

          Any ideas?

            You dont need any html in redirect.php, it never gets seen anyway, and it is the cause of your error.

            However, I would also suggest using javascript for such a task as this. Php just isn't required here.

              On the subject of options, can someone tell me how to create an array for say 50 numerical options using the select field?

              For instance:

              <SELECT CLASS='TXT_BOX' NAME="raids_att" SIZE="1">
              		<option>1</option>
              		<option>2</option>
              		<option>3</option>
              		<option>4</option>
              		<option>5</option>
              		<option>6</option>
              		<option>7</option>
              		<option>8</option>
              		<option>9</option>
              		<option>10</option>
              		<option>11</option>
              		<option>12</option>
              		<option>13</option>
              		<option>14</option>
              		<option>15</option>
              		<option>16</option>
              		<option>17</option>
              		<option>18</option>
              		<option>19</option>
              		<option>20</option>
              		<option>21</option>
              		<option>22</option>
              		<option>23</option>
              		<option>24</option>
              		<option>25</option>
              		<option>26</option>
              		<option>27</option>
              		<option>28</option>
              		<option>29</option>
              		<option>30</option>
              		<option>31</option>
              		<option>32</option>
              		<option>33</option>
              		<option>34</option>
              		<option>35</option>
              		<option>36</option>
              		<option>37</option>
              		<option>38</option>
              		<option>39</option>
              		<option>40</option>
              		<option>41</option>
              		<option>42</option>
              		<option>43</option>
              		<option>44</option>
              		<option>45</option>
              		<option>46</option>
              		<option>47</option>
              		<option>48</option>
              		<option>49</option>
              		<option>50</option>
              	</SELECT>

              I want this to be an array so I don't have to list so many options. I know it's probably simple for some, but I'm not into arrays yet and could use some assistance.

              Thanks,

                Drabin wrote:

                ...can someone tell me how to create an array for say 50 numerical options using the select field?

                echo '<select name="raids_att">';
                for ($i = 1; $i <= 50; $i++) {echo '<option>' . $i . '</option>';}
                echo '</select>';
                

                  I figured it would be cleaner - thanks a lot!

                    Woo Hoo! Thanks Thorpe! That solved the issue! Many thanks also to bodzan for the code!

                      Write a Reply...