I have a script that will take a page name and change the form action, which will then take me to that page. However, I also want the ID for the page content to be passed to it. I assumed that a hidden field would work. I get the page, but there is no content.
<script language="javascript">
<!-- Script courtesy of http://www.web-source.net - Your Guide to Professional Web Site Design and Development
function goto(form) { var index=form.select.selectedIndex
if (form.select.options[index].value != "0") {
location=form.select.options[index].value;}}
//-->
</script>
<form name="form1">
<input type="hidden" name="id" id="id" value="<?php echo $row['id'];?>">
<select name="select" onchange="goto(this.form)">
<option value="">-------Choose a Selection-------
<option value="view.php">View
<option value="download.php">Download
</select>
</form>
I then capture the ID on the receiving page with.
if ($_SERVER["REQUEST_METHOD"] == "POST") {
// collect value of input field
$app_id = $_POST['id'];
}
2
Answers
You can do this to change the form method based on a condition in PHP. About the hidden field, your solution implementation looks reasonable (provided I don’t have more details on what you are trying to do).
The default form is a GET request.
So you only need to add method="POST"
Or when receiving data in PHP, change it to: