sticky forms...
Moderator: General Moderators
this is my code so far, still undefined index...korto wrote:try using $_REQUEST instead of $_POST and let me know (how are you submitting the form and what is the form action and method?)
Code: Select all
<select name='companyrole'>
<option value=''> - Select Company's Role - </option>
<option value='Contractor' <? if ($_REQUEST['companyrole'] == 'Contractor') echo "selected"; ?>>Contractor</option>
<option value='Sub-Contractor' <? if ($_REQUEST['companyrole'] == 'Sub-Contractor') echo "selected"; ?>>Sub-Contractor</option>
<option value='Outsourcing' <? if ($_REQUEST['companyrole'] == 'Outsourcing') echo "selected"; ?>>Outsourcing</option>
</select>Code: Select all
<form action="<? echo $_SERVER['PHP_SELF']; ?>" method="post" >That is not an error that would normally prevent the page from displaying correctly, it depends on the conf. But anyway try this:
It puts sends the $_POST['companyrole'] to a variable named $companyrole and if $_POST['companyrole'] is not set - which is the case when you first load the page- it passes an null value so that you won't get the error message.
Code: Select all
<? if(!isset($_POST['companyrole'])) {
$companyrole = '';
}
else {
$companyrole = $_POST['companyrole'];
}
?>
<select name='companyrole'>
<option value=''> - Select Company's Role - </option>
<option value='Contractor' <? if ($companyrole == 'Contractor') echo "selected"; ?>>Contractor</option>
<option value='Sub-Contractor' <? if ($companyrole == 'Sub-Contractor') echo "selected"; ?>>Sub-Contractor</option>
<option value='Outsourcing' <? if ($companyrole == 'Outsourcing') echo "selected"; ?>>Outsourcing</option>
</select>