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