sticky forms...

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

korto
Forum Commoner
Posts: 36
Joined: Thu Aug 18, 2005 6:30 am
Location: Greece
Contact:

Post by korto »

try using $_REQUEST instead of $_POST and let me know (how are you submitting the form and what is the form action and method?)
User avatar
pleigh
Forum Contributor
Posts: 445
Joined: Wed Jan 19, 2005 4:26 am

Post by pleigh »

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?)
this is my code so far, still undefined index...

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>
here's the orm action/method code

Code: Select all

<form action="<? echo $_SERVER['PHP_SELF']; ?>" method="post" >
korto
Forum Commoner
Posts: 36
Joined: Thu Aug 18, 2005 6:30 am
Location: Greece
Contact:

Post by korto »

That is not an error that would normally prevent the page from displaying correctly, it depends on the conf. But anyway try this:

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>
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.
User avatar
pleigh
Forum Contributor
Posts: 445
Joined: Wed Jan 19, 2005 4:26 am

Post by pleigh »

that is so brilliant....thanks a lot... : :D
Post Reply