NamePros
Welcome, Guest! Ready to make a name for yourself in the domain business? We welcome both the hobbyist and professional domainer to join the discussion as part of the NamePros community.

Click here to create your profile to start earning reputation for posting, and trader ratings for buying & selling in our free e-marketplace. Build your trader rating with each successful sale. Our system has tracked over 100,000 sales and counting!
FAQ & TOS Register Search Today's Posts Mark Forums Read

Go Back   NamePros.com > Website Development Discussion Forums > Programming
Reload this Page how to autopopulate a form w/ PHP

Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics.

Advanced Search


Closed Thread
 
LinkBack Thread Tools
Old 11-09-2005, 03:28 PM THREAD STARTER               #1 (permalink)
New Member
 
obsidianchrysalis's Avatar
Join Date: Mar 2005
Posts: 24
obsidianchrysalis is an unknown quantity at this point
 



how to autopopulate a form w/ PHP


hey all. i have a bit of a problem getting a form to populate with information from a list of $_GET variables.

i can get text fields to populate with the values from the variables, but i can't get <SELECT> fields to austo select to the values.

any help would be appreciated....
obsidianchrysalis is offline  
Old 11-09-2005, 03:41 PM   #2 (permalink)
RJ
NamePros Webmaster


 
RJ's Avatar
Join Date: Feb 2003
Posts: 12,930
RJ Has achieved greatnessRJ Has achieved greatnessRJ Has achieved greatnessRJ Has achieved greatnessRJ Has achieved greatnessRJ Has achieved greatnessRJ Has achieved greatnessRJ Has achieved greatnessRJ Has achieved greatnessRJ Has achieved greatnessRJ Has achieved greatness
 



Find Marrow Donors! Cystic Fibrosis Parkinson's Disease
Can you share how you currently display the <select> options in your PHP script? Are the options generated dynamically or are they static? There are a few ways to do it.

Here's a basic way,

<select name="field1">
<option value="myvalue1" <? if ($_GET['field1'] == 'myvalue1') echo 'selected';?>>
<option value="myvalue2" <? if ($_GET['field1'] == 'myvalue2') echo 'selected';?>>
</select>
__________________
@DomainBuyer facebook
RJ is offline  
Old 11-10-2005, 09:07 AM   #3 (permalink)
NamePros Expert
 
Peter's Avatar
Join Date: Nov 2003
Location: Scotland
Posts: 5,069
Peter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond repute
 


Child Abuse Save The Children Save The Children Help The Homeless - Holiday 2009 Help The Homeless - Holiday 2009 Help The Homeless - Holiday 2009 Help The Homeless - Holiday 2009
yes the way -RJ- has suggested is the way to go about it even if they are dynamically created you can still do it the way -RJ- mentions you just use the same variable where the value is anjd also in the if statement such as:-

<option value="<?PHP echo $variable1 ?>" <?PHP if ($_GET['field1'] == $variable1) echo 'selected';?>>

Just a note however although short tags work (which is what -RJ- used) it is best practice not to use them so that your code is as portable as possible.
Peter is offline  
Old 11-10-2005, 10:35 PM THREAD STARTER               #4 (permalink)
New Member
 
obsidianchrysalis's Avatar
Join Date: Mar 2005
Posts: 24
obsidianchrysalis is an unknown quantity at this point
 



thanks...this helps out alot.
obsidianchrysalis is offline  
Old 11-10-2005, 11:54 PM   #5 (permalink)
NamePros Member
 
Wybe's Avatar
Join Date: Nov 2005
Location: the Netherlands
Posts: 127
Wybe is on a distinguished road
 



Code:
<?php
$options[] = "myvalue1";
$options[] = "myvalue2";
$options[] = "myvalue3";
$options[] = "myvalue4";
echo '<select name="field1">';
foreach($options as $option) {
if($_GET['field1']==$option) { $blaat = ' selected="selected"'; } else { $blaat = ''; }
echo '<option value="'.$option.'"'.$blaat.'>'.$option.'</option>';
}
echo '</select>';
?>
I think that's about it what you need for loong lists of options.
__________________
accepts paypal and cookies
Wybe is offline  
Closed Thread


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools


Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP Form help - beginner :( neilfahey Programming 6 11-09-2005 07:59 PM
PHP search form Barrucadu Programming 18 08-11-2005 10:12 AM
Populate a dropdown for PHP form static1635 Programming 6 08-10-2005 05:32 AM

Liquid Web Smart Servers  
All times are GMT -7. The time now is 08:53 AM.

Managed Web Hosting by Liquid Web
Domain name forum recommended by Domaining.com Powered by: vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.6.0 Ad Management plugin by RedTyger