Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: Fill in Fields with PHP

  1. #1
    Join Date
    May 2006
    Location
    Sydney, Australia - Near the coast.
    Posts
    1,995
    Thanks
    0
    Thanked 8 Times in 7 Posts

    Default Fill in Fields with PHP

    Hi,

    How do you fill in fields automatically with PHP?

    Example:

    Code:
    <a href="fillIn.php?name=Peter">Fill in name with Peter</a>
    and then when you go into the fillIn.php page there's a form with a field called 'name' and the value "Peter"

    Thanks,


    Peter
    Peter - alotofstuffhere[dot]com - Email Me - Donate via PayPal - Got spare hardware? Donate 'em to me :) Just send me a PM.
    Currently: enjoying the early holidays :)
    Read before posting: FAQ | What you CAN'T do with JavaScript | Form Rules | Thread Title Naming Guide

  2. #2
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    That's all you need on the first page with the link.

    The next page, fillIn.php should be like this:

    <input .... value="<?php echo $_GET['name']; ?>">

    You can put that php code anywhere on the page and it will output "Peter" into the html. It will also output "" (blank string) if there is no value, so just like it wasn't there.


    Note that you need php installed on the server and the second page (or both) to be of the extension .php as opposed to .htm etc.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  3. #3
    Join Date
    May 2006
    Location
    Sydney, Australia - Near the coast.
    Posts
    1,995
    Thanks
    0
    Thanked 8 Times in 7 Posts

    Default

    Thanks!

    And do you know how to do that for drop-down select menus? Like select the right one.

    (Just noticed the "Phrase Center" in Quick Reply Section)
    Peter - alotofstuffhere[dot]com - Email Me - Donate via PayPal - Got spare hardware? Donate 'em to me :) Just send me a PM.
    Currently: enjoying the early holidays :)
    Read before posting: FAQ | What you CAN'T do with JavaScript | Form Rules | Thread Title Naming Guide

  4. #4
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    "...like the right one."
    Hmmm? Right? as opposed to left? As in correct? or something else?

    With php and get variables, you can do that fairly easily.
    The method depends on exactly what you want to happen.
    I can see two options:
    1. you create/add to a select menu. (Do this as you did the last one... just output, with php, a value into the select. Note that you can use strings, like "text".$var."moretext.$anothervar... and then you have your html)
    2. If you mean send the chosen item from a select menu by php, then simply use ifs...
    here's an example of one if:
    PHP Code:
    <select>
    .....
    <option value="CA" <?php
    if ($_GET['item'] == "CA") {
         echo 
    "selected";
         }
    ?>>California</option>
    .....
    </select>
    Do that for each option in the select, and it will go to the one in the URL.

    The above, assuming the url was ?item=CA, would output:
    <select>
    <option value="CA" selected>California</option>
    </select>


    If the above php looked complex, it could be rewritten as:
    PHP Code:
    <select>
    .....
    <option value="CA" <?php if ($_GET['item'] == "CA") { echo "selected"; } ?>>California</option>
    .....
    </select>
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  5. #5
    Join Date
    May 2006
    Location
    Sydney, Australia - Near the coast.
    Posts
    1,995
    Thanks
    0
    Thanked 8 Times in 7 Posts

    Default

    "...like the right one."
    Hmmm? Right? as opposed to left? As in correct? or something else?
    As in the correct one.
    Peter - alotofstuffhere[dot]com - Email Me - Donate via PayPal - Got spare hardware? Donate 'em to me :) Just send me a PM.
    Currently: enjoying the early holidays :)
    Read before posting: FAQ | What you CAN'T do with JavaScript | Form Rules | Thread Title Naming Guide

  6. #6
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    k.
    The above work for you?
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  7. #7
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    it will also output "" (blank string) if there is no value, so just like it wasn't there.
    Yes, but it will also throw a NOTICE. You should really check:
    Code:
    <?php echo(isset($_GET['name']) ? $variable : ''); ?>
    Code:
    <select>
    .....
    <option value="CA" <?php
    if ($_GET['item'] == "CA") {
         echo "selected";
         }
    ?>>California</option>
    .....
    </select>
    Preferred would be:
    Code:
    <select>
      <option value="CA" <?php
        if (isset($_GET['item']) && $_GET['item'] === 'CA')
         echo 'selected="selected"';
      ?>>California</option>
    </select>
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  8. #8
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    $_GET['item'] === 'CA'
    Or, just ==.... no need for the "exactly equal to" as there isn't much else that would be kinda equal to "CA" But.. sure.

    Ah, well, one of the servers I've been working on has a nice habit of not showing errors (which is out of my control, unfortunately, shoot me a PM, twey, if there's a way to do it in the script... I've tried, but failed...), so that's likely why I haven't bothered checking if it has no value.
    good point, though.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  9. #9
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    error_reporting(E_ALL) should do it.
    no need for the "exactly equal to" as there isn't much else that would be kinda equal to "CA"
    Which is exactly why === should be used Since it doesn't have to convert the operands to a dozen different types before deciding they're not equal, === should be more efficient than ==.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  10. #10
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    In what sense of efficient?
    Personally, I'm happy sticking with my lazy two equals signs.
    I suppose, though, that you're talking about server run time.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •