Page 1 of 2

sticky forms...

Posted: Wed Jul 13, 2005 7:25 am
by pleigh
hi there guys,

is there a way i can do sticky forms to textarea and dropdown lists??if yes,how?i have here sticky form for textbox only

Code: Select all

<input name=&quote;location&quote; type=&quote;text&quote; size=&quote;31&quote; value=&quote;<? if (isset($_POST&#1111;'location'])) echo $_POST&#1111;'location']; ?>&quote;>
how about textarea and dropdown?

thanks.:)

Posted: Wed Jul 13, 2005 8:31 am
by cbrian
For a text area, something like

Code: Select all

<textarea><?php echo $sticky_variable; ?></textarea>
For a drop down list, something like

Code: Select all

<select>
<option name="option1" <?php if ($sticky_selected == "option1") echo "selected"; ?>>Option 1
<option name="option2" <?php if ($sticky_selected == "option2") echo "selected"; ?>>Option 2
<option name="option3" <?php if ($sticky_selected == "option3") echo "selected"; ?>>Option 3
</select>
Untested, but it should work.

Posted: Thu Jul 14, 2005 3:46 am
by pleigh
any idea how can i format my code below?considering the idea of the above code...thanks a lot guys

Code: Select all

<select name='companyrole'>
					<option value=''> - Select Company's Role - </option>
					<option value='Contractor'>Contractor</option>
					<option value='Sub-Contractor'>Sub-Contractor</option>
					<option value='Outscoring'>Outscoring</option>
					</select>

Posted: Fri Aug 19, 2005 3:11 am
by pleigh
again, can somebody help me construct my code below to become sticky form??help please...

Code: Select all

<select name='companyrole'>
					<option value=''> - Select Company's Role - </option>
					<option value='Contractor'>Contractor</option>
					<option value='Sub-Contractor'>Sub-Contractor</option>
					<option value='Outsourcing'>Outsourcing</option>
</select>
i have done the previous suggestion, but i have no luck doing it...thanks in advance...

Posted: Fri Aug 19, 2005 3:49 am
by korto
Use Pleigh's suggestion. If you have already done that and wasn't working post the code you used

Posted: Fri Aug 19, 2005 3:55 am
by pleigh
thanks korto, i did the above suggestion and returns me an error message to the 3 options
undefine variable: sticky_selected
in this case, i have no idea on where should i declare the variable, the code below

Code: Select all

<option value='Contractor' name="option1" <?php if ($sticky_selected == "option1") echo "selected"; ?>>Contractor</option>
<option value='Sub-Contractor' name="option2" <?php if ($sticky_selected == "option2") echo "selected"; ?>>Sub-Contractor</option>
<option value='Outsourcing' name="option3" <?php if ($sticky_selected == "option3") echo "selected"; ?>>Outsourcing</option>
by the way...i am pleigh... :D

Posted: Fri Aug 19, 2005 4:03 am
by korto
$companyrole = $_GET['companyrole'];

<select name='companyrole'>
<option value=''> - Select Company's Role - </option>
<option value='Contractor' <?php if ($companyrole == "Contractor") echo "selected"; ?>>Contractor</option>

same for th rest options

Posted: Fri Aug 19, 2005 4:07 am
by pleigh
yup...thanks korto, i'll try to code that... :D

Posted: Fri Aug 19, 2005 4:11 am
by pleigh
i received an undefined index -->companyrole...maybe because of this code

Code: Select all

$companyrole = $_GET['companyrole'];

Posted: Fri Aug 19, 2005 4:13 am
by korto
can you please post the whole code ?

Posted: Fri Aug 19, 2005 4:15 am
by pleigh
ok...sorry...here's the code

before the form, i declared this code

Code: Select all

$companyrole = $_GET['companyrole'];
then inside the form

Code: Select all

<select name='companyrole'>
<option value=''> - Select Company's Role - </option>
<option value='Contractor' <?php if ($companyrole == "Contractor") echo "selected"; ?>>Contractor</option>
<option value='Sub-Contractor' <?php if ($companyrole == "Sub-Contractor") echo "selected"; ?>>Sub-Contractor</option>
<option value='Outsourcing' <?php if ($companyrole == "Outsourcing") echo "selected"; ?>>Outsourcing</option>
					</select>

Posted: Fri Aug 19, 2005 4:25 am
by korto
well first of all you didn't quite understand the logic :
You are using the same if clause in all options whereas you should actually check if the specific value is the one selected so to be displayed. {if $companyrole=='Contractor', if $companyrole=='Subcontractor' etc}
It is actually very simiral to the input box that you said worked for you but instead, since you have a list of values the select box can obtain, you put an if clause at each option in order to display the one that has the value of the select box.
The value of the select box is obtained by $_REQUEST['companyrole'] , or post or get

Posted: Fri Aug 19, 2005 4:40 am
by pleigh
i did this

Code: Select all

<select name='companyrole'>
<option value=''> - Select Company's Role - </option>
<option value='Contractor' <? if (isset($_POST['companyrole'])) echo "selected"; ?>>Contractor</option>
<option value='Sub-Contractor' <? if (isset($_POST['companyrole'])) echo "selected"; ?>>Sub-Contractor</option>
<option value='Outsourcing' <? if (isset($_POST['companyrole'])) echo "selected"; ?>>Outsourcing</option>
</select>
still do not work but instead of posting the " - Select Company's Role - ", the oursourcing is selected...can't understand why because the oursourcing code is the same as the contractor and the sub-contractor...

Posted: Fri Aug 19, 2005 4:49 am
by korto
You are putting 3 valid if statement and as a result the action of the last one is kept so outsourcing is selected. That 's why I said that you need to stand back and understand the logic first.
if(isset($_POST['companyrole'])) is a valid statement, what you need is to get the value of it


<option value='Contractor' <? if ($_POST['companyrole']=='Contractor') echo "selected"; ?>>Contractor</option>
<option value='Sub-Contractor' <? if ($_POST['companyrole']=='Sub-Contractor') echo "selected"; ?>>Contractor</option>
<option value='Outsourcing' <? if ($_POST['companyrole']=='Outsourcing') echo "selected"; ?>>Contractor</option>

Posted: Fri Aug 19, 2005 5:20 am
by pleigh
thank you for your patience, but it returned an error
undefined index: companyrole
i did this

Code: Select all

<select name='companyrole'>
<option value=''> - Select Company's Role - </option>
<option value='Contractor' <? if ($_POST['companyrole'] == 'Contractor') echo "selected"; ?>>Contractor</option>
<option value='Sub-Contractor' <? if ($_POST['companyrole'] == 'Sub-Contractor') echo "selected"; ?>>Sub-Contractor</option>
<option value='Outsourcing' <? if ($_POST['companyrole'] == 'Outsourcing') echo "selected"; ?>>Outsourcing</option>
</select>