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

User avatar
pleigh
Forum Contributor
Posts: 445
Joined: Wed Jan 19, 2005 4:26 am

sticky forms...

Post 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.:)
cbrian
Forum Commoner
Posts: 97
Joined: Sun Feb 27, 2005 12:29 pm

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

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

Post 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...
korto
Forum Commoner
Posts: 36
Joined: Thu Aug 18, 2005 6:30 am
Location: Greece
Contact:

Post by korto »

Use Pleigh's suggestion. If you have already done that and wasn't working post the code you used
User avatar
pleigh
Forum Contributor
Posts: 445
Joined: Wed Jan 19, 2005 4:26 am

Post 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
korto
Forum Commoner
Posts: 36
Joined: Thu Aug 18, 2005 6:30 am
Location: Greece
Contact:

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

Post by pleigh »

yup...thanks korto, i'll try to code that... :D
User avatar
pleigh
Forum Contributor
Posts: 445
Joined: Wed Jan 19, 2005 4:26 am

Post by pleigh »

i received an undefined index -->companyrole...maybe because of this code

Code: Select all

$companyrole = $_GET['companyrole'];
korto
Forum Commoner
Posts: 36
Joined: Thu Aug 18, 2005 6:30 am
Location: Greece
Contact:

Post by korto »

can you please post the whole code ?
User avatar
pleigh
Forum Contributor
Posts: 445
Joined: Wed Jan 19, 2005 4:26 am

Post 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>
korto
Forum Commoner
Posts: 36
Joined: Thu Aug 18, 2005 6:30 am
Location: Greece
Contact:

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

Post 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...
korto
Forum Commoner
Posts: 36
Joined: Thu Aug 18, 2005 6:30 am
Location: Greece
Contact:

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

Post 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>
Post Reply