Jump to content

[SOLVED] menu


DeFActo

Recommended Posts

i have tried to use it, but getting error

<form method="post" action="menu.php">
<?php
echo  '<select id="selectElemId" name="selectElem[]">';
echo  '<option value="ham">Ham</option>';
echo  '<option value="cheese">Cheese</option>';
echo  '<option value="hamcheese">Ham and Cheese</option>';
echo  '</select>';
$var=$_GET['selectElem'][];
?>
</form>

Link to comment
https://forums.phpfreaks.com/topic/99830-solved-menu/#findComment-510635
Share on other sites

i have tried to use it, but getting error

<form method="post" action="menu.php">
<?php
echo  '<select id="selectElemId" name="selectElem[]">';
echo  '<option value="ham">Ham</option>';
echo  '<option value="cheese">Cheese</option>';
echo  '<option value="hamcheese">Ham and Cheese</option>';
echo  '</select>';
$var=$_GET['selectElem'][];
?>
</form>

Is that all your code? If it is there is a few issues:

1. There is no submit button. In order for PHP to retrieve data from the form it needs to be submitted.

2. Your form method is set to post so you'll use the $_POST superglobal instead, eg $_POST['selectElemId']

3. You should always check to see if user defined variables exists first before using them to prevent the "Underfined index notice" notices (these are not errors)

Link to comment
https://forums.phpfreaks.com/topic/99830-solved-menu/#findComment-510641
Share on other sites

i have tried to use it, but getting error

<form method="post" action="menu.php">
<?php
echo  '<select id="selectElemId" name="selectElem[]">';
echo  '<option value="ham">Ham</option>';
echo  '<option value="cheese">Cheese</option>';
echo  '<option value="hamcheese">Ham and Cheese</option>';
echo  '</select>';
$var=$_GET['selectElem'][];
?>
</form>

Is that all your code? If it is there is a few issues:

1. There is no submit button. In order for PHP to retrieve data from the form it needs to be submitted.

2. Your form method is set to post so you'll use the $_POST superglobal instead, eg $_POST['selectElemId']

i'd like to do it without submit button.

Link to comment
https://forums.phpfreaks.com/topic/99830-solved-menu/#findComment-510644
Share on other sites

Then you'll need use a bit of javascript to submit the form once a user has selected an item from the list

<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<select name="selectElem" onChange="this.form.submit()">
<option>Filling</option>
<option value="ham">Ham</option>
<option value="cheese">Cheese</option>
<option value="hamcheese">Ham and Cheese</option>
</select>
</form>

<?php

if(isset($_POST['selectElem']))
{
    echo $_POST['selectElem'];
}

?>

Link to comment
https://forums.phpfreaks.com/topic/99830-solved-menu/#findComment-510651
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.