Jump to content

parse to new page from form


ryanmetzler3

Recommended Posts

I have not been able to find this on YouTube or the internet surprisingly. Anyways I got a simple select form here. I was not real sure where to put "name" and "value" tags. Anyways here it is:

<html>

<head>

</head>

<body>
Select Your School:
		
<form method="post">
  <select>
  <option value="LCCC">Lorain County Community College</option>
  <option value="CSU">Cleveland State University</option>
  <input type="submit" value="Submit" />
  </select>
</form>

</body>
</html> 

How can I use PHP to parse to a new page based on their selection? For example if they choose LCCC then it will go to "lccc.php" or if they choose CSU it will go to "csu.php"?

 

Link to comment
Share on other sites

You wouldn't use php for that. Its a client side issue, use Javascript.

 

 

<html>

<head>
<script src="http://codeorigin.jquery.com/jquery-1.10.2.min.js"></script>
<script>
$(document).ready( function() {
  $('#select').change( function() {
    location.href = $(this).val();
  });
});
</script>
</head>
<body>
Select Your School:
<form method="post">
  <select>
    <option value="lccc.php">Lorain County Community College</option>
    <option value="csu.php">Cleveland State University</option>
  </select>
</form>
</body>
</html>
Link to comment
Share on other sites

As trq suggested, you could use JavaScript/jQuery to direct visitors to the proper page. Just keep in mind that JavaScript can be disabled. Since this seems like a critical interaction, it's a good idea to have a backup.

 

To redirect visitors using PHP, you would need to name the <select> element. That lets you access the selection in PHP. You can then redirect the visitor to the proper page using the header() function.


 

With that said, can the pages for LCCC and CSU be merged? If they are similar enough, perhaps you could use the form selection to populate one page based on a database?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.