www.webdeveloper.com
Results 1 to 8 of 8

Thread: [RESOLVED] Pass data via the URL

  1. #1
    Join Date
    Sep 2009
    Posts
    18

    resolved [RESOLVED] Pass data via the URL

    I have a web form created in front page for example

    <a shape="rect" href="mailto:example.com/update-mail.htm?oldaddress=johndoe@example.com" shape="rect">example.com/update-mail.htm

    on it is a field called eMail. I want to pass data to this field via the URL.

    I have tried

    <a shape="rect" href="mailto:example.com/update-mail.htm?eMail=johndoe@example.com" shape="rect">example.com/update-mail.htm?eMail=johndoe@example.com


    but although we didn't get an error, it didnt appear to populate the field.

    Do I need to do something else ?

    Also if I wanted to pass two fields - what would the syntax be.

  2. #2
    Join Date
    Sep 2008
    Location
    Mexico
    Posts
    786
    Would be good to see the form....
    and why are you using "mailto:" in the link??
    ...but stupidity is terminal.

  3. #3
    Join Date
    Sep 2009
    Posts
    18
    Wow! Fast reply. Thanks!

    Without mailto: it's going to work?

    I can send you the code right now because I'm at work. I will post the code later. Thanks a lot for reply.

  4. #4
    Join Date
    Sep 2009
    Posts
    18
    Quote Originally Posted by opifex View Post
    Would be good to see the form....
    and why are you using "mailto:" in the link??
    What I have tried is http://www.mysite.com/myform.htm?Reccid=123456 to populate the field called Reccid, but nothing appears in the field - I hope this clarifies things.

    Kind regards!

  5. #5
    Join Date
    Nov 2008
    Posts
    2,477
    When you say "populate a field", do you mean you want the actual form element on the page to be pre-filled with the data in the URL? I don't understand what you are trying to do.

  6. #6
    Join Date
    Sep 2009
    Posts
    18
    Yes ! that's it.

  7. #7
    Join Date
    Nov 2008
    Posts
    2,477
    If you have a page called example.php and you want to send data to the script via the URL, use the following syntax:

    Code:
    example.php?variable1=foo&variable2=bar&answer=42
    Then within example.php you can access the values via the $_GET superglobal:

    PHP Code:
    echo $_GET['variable1']; // foo
    echo $_GET['variable2']; // bar
    echo $_GET['answer']; // 42 
    So to pre-populate a text field:

    PHP Code:
    <input type="text" name="somefield" value="<?php echo $_GET['variable1'?>" />
    Bear in mind that that you should always validate data before outputting it like this. It is less dangerous in a textbox, but if you are echoing user input directly you leave yourself open to a variety of attacks.

  8. #8
    Join Date
    Sep 2009
    Posts
    18
    Quote Originally Posted by Mindzai View Post
    If you have a page called example.php and you want to send data to the script via the URL, use the following syntax:

    Code:
    example.php?variable1=foo&variable2=bar&answer=42
    Then within example.php you can access the values via the $_GET superglobal:

    PHP Code:
    echo $_GET['variable1']; // foo
    echo $_GET['variable2']; // bar
    echo $_GET['answer']; // 42 
    So to pre-populate a text field:

    PHP Code:
    <input type="text" name="somefield" value="<?php echo $_GET['variable1'?>" />
    Bear in mind that that you should always validate data before outputting it like this. It is less dangerous in a textbox, but if you are echoing user input directly you leave yourself open to a variety of attacks.
    Thanks a lot ! It was perfect! It works! Thank you!

    Regards!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

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



Recent Articles