Jump to content

Form handling issue


desmond

Recommended Posts

Hi Guys,

 

Can someone please tell me why no echo statements work after my heredoc :?

 

Here's the code:

 

<?php

switch($_POST['options']){

case '1':
$selected1 = 'selected';
break;
case '2':
$selected2 = 'selected';
break;
case '3':
$selected3 = 'selected';
break;
case '4':
$selected4 = 'selected';
break;
default:
$selected1 = $selected2 = $selected3 = $selected4 = '';
}

echo <<<END
<html>
<head>
<script type="text/javascript">
function show_alert()
{
alert("I am an alert box!");
}

function formSubmit()
{
document.getElementById("frm1").submit();
}


</script>
</head>
<body>
<form id="frm1" method="post" action="search.php" />
<select onclick="formSubmit()" name="options" size="1">
<option $selected1 value="1">date</option>
<option $selected2 value="2">year</option>
<option $selected3 value="3">country</option>
<option $selected4 value="4">language</option>
</ select>
</body>
</html>
</form>
END;

if(isset($_POST['options'])){
echo "item chosen";
}

 

It works when I put the 'isset' if clause before the heredoc and even weirder, if i add a submit input type in the form as the last field it works as is? ex:

 

<?php

switch($_POST['options']){

case '1':
$selected1 = 'selected';
break;
case '2':
$selected2 = 'selected';
break;
case '3':
$selected3 = 'selected';
break;
case '4':
$selected4 = 'selected';
break;
default:
$selected1 = $selected2 = $selected3 = $selected4 = '';
}

echo <<<END
<html>
<head>
<script type="text/javascript">
function show_alert()
{
alert("I am an alert box!");
}

function formSubmit()
{
document.getElementById("frm1").submit();
}


</script>
</head>
<body>
<form id="frm1" method="post" action="search.php" />
<select onclick="formSubmit()" name="options" size="1">
<option $selected1 value="1">date</option>
<option $selected2 value="2">year</option>
<option $selected3 value="3">country</option>
<option $selected4 value="4">language</option>
<input type="submit">
</ select>
</body>
</html>
</form>
END;

if(isset($_POST['options'])){
echo "item chosen";
}

 

Any help would be greatly appreciated!

 

Cheers

 

D

 

 

Link to comment
https://forums.phpfreaks.com/topic/253986-form-handling-issue/
Share on other sites

Apologies There is a typo on the above with the closing form tag, it should be this:

 

<?php

switch($_POST['options']){

case '1':
$selected1 = 'selected';
break;
case '2':
$selected2 = 'selected';
break;
case '3':
$selected3 = 'selected';
break;
case '4':
$selected4 = 'selected';
break;
default:
$selected1 = $selected2 = $selected3 = $selected4 = '';
}

echo <<<END
<html>
<head>
<script type="text/javascript">
function formSubmit()
{
document.getElementById("frm1").submit();
}
</script>
</head>
<body>
<form id="frm1" method="post" action="search.php" />
<select onclick="formSubmit()" name="options" size="1">
<option $selected1 value="1">date</option>
<option $selected2 value="2">year</option>
<option $selected3 value="3">country</option>
<option $selected4 value="4">language</option>
</ select>
</form>
</body>
</html>
END;

if(isset($_POST['options'])){
echo "item chosen";
}

 

Issue still the same though!

Link to comment
https://forums.phpfreaks.com/topic/253986-form-handling-issue/#findComment-1302027
Share on other sites

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.