GIDForums  

Go Back   GIDForums > Computer Programming Forums > MySQL / PHP Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 11-Sep-2008, 21:35
crazygol4 crazygol4 is offline
New Member
 
Join Date: Aug 2008
Posts: 10
crazygol4 is on a distinguished road

PHP - Form


Okay so I've looked all around on Google and can't find what I'm looking for...check this out ->

I have a standard HTML form where users enter information blah blah blah, and one of these inputs is a drop down menu of all the states. SO that information is sent to a php page that accepts the information, it basically ensures that people didn't forget to fill required fields in, aren't injecting code, and a few more things. If there are any problems it will flag the errors and set headers for the previous page. All the information that was submitted the first time is sent back into the forms so that users don't have to enter it all in again.

THE QUESTION:
How do I send back information to the state DROPDOWN input?

I know that you would use selected as such: <option value="OH" selected="selected">OHIO</option>
BUT, what is the best way to take the value (OH) and use it to select Ohio from the dropdown menu.

Should I just do a php if statement for each option, or is there a better option?

This is my idea right now:
PHP Code:

<option value="OH" selected="<? if($_POST[returnedvalue] == "OH") {
echo "selected"; } ?>">OHIO</option> 


  #2  
Old 11-Sep-2008, 21:57
admin's Avatar
admin admin is offline
Administrator
 
Join Date: Sep 2002
Posts: 841
admin will become famous soon enough

Re: PHP - Form


Perhaps something like this:

PHP Code:

// flags
$flags["option_state_selected"] = ( isset($_POST["state_code"])  &&  $_POST["state_code"] );

foreach( $option_values_states as $state_code=>$state )
{
    $selected = null;
    if( $flags["option_state_selected"] )
    {
        if( $state_code == $_POST["state_code"] )
        {
            $flags["option_state_selected"] = false;
            $selected = " selected=\"selected\"";
        }
    }
    echo "<option value=\"$state_code\"$selected>$state</option>\n";
} 


__________________
Custom BB codes you can use here:
[HTML] | [C++] | [CSS] | [JAVA] | [PY] | [VB]
  #3  
Old 12-Sep-2008, 15:31
crazygol4 crazygol4 is offline
New Member
 
Join Date: Aug 2008
Posts: 10
crazygol4 is on a distinguished road

Re: PHP - Form


Thanks Mr. Admin That looks like it's going to do the trick, I'll pop it in when I get back. Now I'm wondering how people achieve real time error checking on forms (ex Facebook)... Is that done with JScript or another lang? Does anyone know where I might find a script to that will bring out an error box (or even just text) to the side if the password (username, etc) doesn't meet criteria?

Thanks,
Crazygol4
  #4  
Old 13-Sep-2008, 04:20
admin's Avatar
admin admin is offline
Administrator
 
Join Date: Sep 2002
Posts: 841
admin will become famous soon enough

Re: PHP - Form


Yes, a client-side script is something you will need to achieve "real time error checking on forms". The most popular of which is Java Script.

Unfortunately, I am cannot help you with the example JS codes you requested -- I am the world's worst Java Script coder

Try starting a new discussion in the Web Development Forum, maybe a kind and helpful member will pick it up.
__________________
Custom BB codes you can use here:
[HTML] | [C++] | [CSS] | [JAVA] | [PY] | [VB]
  #5  
Old 13-Sep-2008, 11:46
crazygol4 crazygol4 is offline
New Member
 
Join Date: Aug 2008
Posts: 10
crazygol4 is on a distinguished road

Re: PHP - Form


Sure enough. Thanks again for all the help!
 
 

Recent GIDBlogOnce again, no time for hobbies by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
HTML Form to PHP File - Help Requested vigilantweather MySQL / PHP Forum 15 07-Aug-2006 20:22
Flash login form and PHP Error MySQL / PHP Forum 2 14-Nov-2005 19:38
PHP form needs validation jabesign MySQL / PHP Forum 16 05-Jan-2005 01:23
Php Form....help spyko05 MySQL / PHP Forum 0 12-Nov-2003 12:00
Automate a data change php form mjfmn MySQL / PHP Forum 4 20-Oct-2003 10:37

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 00:51.


vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd.