Jump to content

Passing variables to URL


Darkmatter5

Recommended Posts

Okay I have two droplists "system" and "genre" and a submit button.

 

1. How can I create code that would execute when the button is pressed?

2. How can I take the values of "system" and "genre" and put them into a string variable that have the pages current URL, but appends the values to the end and then reloads the page with those variables passed in the URL?

 

Example:

Current URL "http://www.something.com/page.php"

System value "1"

Genre value "1"

 

Reload the page with "http://www.something.com/page.php?system=1&genre=1"

 

Thanks!

Link to comment
https://forums.phpfreaks.com/topic/139549-passing-variables-to-url/
Share on other sites

Okay I have two droplists "system" and "genre" and a submit button.

 

1. How can I create code that would execute when the button is pressed?

2. How can I take the values of "system" and "genre" and put them into a string variable that have the pages current URL, but appends the values to the end and then reloads the page with those variables passed in the URL?

 

Example:

Current URL "http://www.something.com/page.php"

System value "1"

Genre value "1"

 

Reload the page with "http://www.something.com/page.php?system=1&genre=1"

 

Thanks!

 

Hmm...Almost sounds like homework.

 

Have you tried something like:

 

<?php
if(isset($_GET['submit']))
{
   if(isset($_GET['system']) && isset($_GET['genre']))
   {
      /* load the content specific for that system and genre */
   }
   else
   {
      /* error? */
   }
}

/*if the info HASN'T been submitted yet */
?>

<html>
<head>
   <title>Blah</title>
</head>

<body>
   <form action="<?php $_SERVER['PHP_SELF'] ?>" method="get">
      <select name="system">
         <!-- all of the 'system' options go here -->
      </select>

      <select name="genre">
         <!-- all of the 'genre' options go here -->
      </select>

      <input type="submit" name="submit" value="Submit" />
   </form>
</body>

</html>

how you ever tried

 

<body>
<form id="form1" name="form1" method="link" action="somepage.php?">
  <table>
    <tr>
      <td><select name="system">
      	<option value="system_option_1">system_option_1</option>
        <option value="system_option_2">system_option_2</option>
      </select>      </td>
      <td><select name="genre">
      	<option value="genre_option_1">genre_option_1</option>
        <option value="genre_option_2">genre_option_2</option>
      </select>      </td>
    </tr>
    <tr>
      <td> </td>
      <td><input type="submit" value="Submit" /></td>
    </tr>
  </table>
</form>
</body>

Perfect ideas. I went with the first one and here's what I got.

 

<form method="get" name="vgames" action="<?php $_SERVER['PHP_SELF'] ?>">
          <table align="left" cellpadding="0" cellspacing="0" border="0">
            <tr>
              <td bgcolor="#993366">
                <?php $vein->list_systems(1,$_GET['systems']); echo " "; $vein->list_genres(2,$_GET['genres']); ?> <input name='search' type='submit' class='button' tabindex='3' value='Search now'/><br>
                <?php $vein->list_numalpha_games($_GET['systems']); ?>
              </td>
            </tr>
          </table>
          </form>

 

Now here's the URL it produces "http://www.something.com/site/vgames.php?systems=6&genres=4&search=Search+now".  How can I get it to ignore search, which is the button?

But by using the mentioned method it's automatically taking all values from all form items within the form tags and applying them to the action which is reloading the page.  how can I get it to ignore search?

 

you can simply remove name attribute from form element.

i.e.  <input type="text" value="Some_Value">

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.