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
https://forums.phpfreaks.com/topic/281834-parse-to-new-page-from-form/
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>
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?

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.