I want to retain the data from a form and enter it into another form

Discussion in 'PHP' started by jc@ukzone.com, Oct 28, 2007.

  1. #1
    I have a form contact.php and I use a captcha code to protect from spam.
    On the form I have a field:
    <input type="text" size=25 name="myname">
    The form action is:
    <form action="contact.php" method="get" target="_new">

    If the captcha code is entered wrong I have coded it to go back to the contact.php page:
    header("Location: /contact.php");

    I want to send the contents of the form back to the contact.php page so that the user does not have to fill in the form again.
    I'm trying:
    header("Location: /contact.php?myname=$myname");

    I am using:
    $name = $_GET['name'];
    to obtain the form data.

    If the captcha code is entered correctly there is no problem with sending the form.
    The above is only a sample of a few form data that I want to retain
    Can anybody advise me why the form data is not being retained and entered on the new form.

    Thanks.

    John C
     
    jc@ukzone.com, Oct 28, 2007 IP
  2. Lordy

    Lordy Peon

    Messages:
    1,643
    Likes Received:
    29
    Best Answers:
    0
    Trophy Points:
    0
    #2
    <input type="text" size=25 name="myname" value="<?php=$name ?>"

    should work
     
    Lordy, Oct 28, 2007 IP
  3. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #3
    Except that there's no <?php= tag, yes. It should be either <? or <?php. All other tags are deprecated.
     
    nico_swd, Oct 29, 2007 IP
  4. jc@ukzone.com

    jc@ukzone.com Guest

    Messages:
    35
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Hi Folks..
    Thanks for your replies.
    However, I just don't understand.
    Maybe it is me who didn't explain properly.

    I have a form that is loaded by contact.php.
    contact.php loads contact.tpl which is the form page.

    $template = join('',file('contact-sample.tpl'));

    If($action==""){print $template;}


    The form is then sent to contact.php and is directed to the next part, which is:
    else if($action=="send"){

    It then checks the captcha code.
    If the captch code is WRONG it is directed to:
    header("Location: /contact.php?name=$name&mymessage=$mymessage");
    The contact.php page is reloaded with contact.tpl BUT the $name and $mymessage do not load into fields of the form.

    I did think that they should be.

    Am I doing something wrong ???

    Any help will be appreciated.

    Thanks,

    John C
     
    jc@ukzone.com, Oct 29, 2007 IP
  5. Lordy

    Lordy Peon

    Messages:
    1,643
    Likes Received:
    29
    Best Answers:
    0
    Trophy Points:
    0
    #5
    your form has to set them as a value.

    please post your code if im not understanding properly
     
    Lordy, Oct 29, 2007 IP
  6. bLuefrogx

    bLuefrogx Peon

    Messages:
    28
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Depreciated doesn't mean there isn't. It just means its going to be phased out eventually :)
     
    bLuefrogx, Oct 29, 2007 IP
  7. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #7
    Yes, but he was using <?php= tags, which do not exist. Read my post again.
     
    nico_swd, Oct 29, 2007 IP
  8. jc@ukzone.com

    jc@ukzone.com Guest

    Messages:
    35
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Hi nico_swd..
    You said: "Yes, but he was using <?php= tags, which do not exist. Read my post again."

    My php script uses: <? and finishes with ?>

    Thanks...

    John C
     
    jc@ukzone.com, Oct 29, 2007 IP
  9. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #9
    nico_swd, Oct 29, 2007 IP
  10. jc@ukzone.com

    jc@ukzone.com Guest

    Messages:
    35
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #10
    Hi Lordy..
    Here is the script that I am using. It is cut down for test purposes:
    =================================================

    <?

    // INITIALISE

    $template = join('',file('contact-sample.tpl'));

    $action = $_GET['act'];
    $name = $_GET['name'];
    $mymessage = $_GET['mymessage'];

    // DIRECT TO THE REQUIRED ACTION

    If($action==""){

    print $template;

    }

    else if($action=="send"){

    // CHECK SECURITY CODE
    session_start();
    if(($_SESSION['security_code'] == $_GET['security_code']) && (!empty($_SESSION['security_code'])) ) {

    // # SEND RESPONSE ########

    $content = "<center><br /><font size=4 ><b>Name: $name.....<br />\n";
    $content .= "Message: $mymessage</b></font> </center>";

    print $content;

    // WRONG SECURITY CODE
    }
    else {

    header("Location: /contact-sample.php?name=$name&mymessage=$mymessage");

    exit;
    }
    // WRONG SECURITY CODE

    }

    ?>

    =================================================

    You can see the contact-sample.tpl here:

    http://www.countrymusic.org.uk/contact-sample.php

    As you can see if you test the form. If you input the code correctly you get a returned page. If you input the code incorrectly you get the form returned.

    I want to do this because in the 'real' form, the message could be quite long and if it's lost it has to be re-typed.

    Thanks for your help...

    John C
     
    jc@ukzone.com, Oct 29, 2007 IP
  11. Lordy

    Lordy Peon

    Messages:
    1,643
    Likes Received:
    29
    Best Answers:
    0
    Trophy Points:
    0
    #11
    you will need to edit contact.tpl and set the a value
     
    Lordy, Oct 29, 2007 IP
  12. dadougalee

    dadougalee Peon

    Messages:
    589
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #12
    Am I missing something, but $_GET['name'] will not read any information from header("Location: /contact.php?myname=$myname");

    Using $_GET['myname'] would read the information.

    Maybe you wrote the info in wrong and thats what you meant, but glancing at your code really quick, I see a problem there. Maybe I misunderstand the question though.
     
    dadougalee, Oct 29, 2007 IP
  13. jc@ukzone.com

    jc@ukzone.com Guest

    Messages:
    35
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #13
    Hi dadougalee...
    I'm sorry to have confused you.
    In my first post I used &myname etc...
    In my latest post, where I sent the full script, I used &name etc. This script was used for practical demonstration purposes only.

    Hope this clarifies it for you.

    John C
     
    jc@ukzone.com, Oct 29, 2007 IP
  14. jc@ukzone.com

    jc@ukzone.com Guest

    Messages:
    35
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #14
    Hi Lordy...
    The code that you suggested doesn't seem to work:
    <input type="text" size=25 name="myname" value="<?php=$name ?>"
    If I put this code, with the value value="<?php=$name ?>" this value shows in the form as it is written here.
    How does this help to take the data from the original form to the re-presented form ???

    Maybe I need to redirect it to a new form with the values already included as you suggest.
    What do you think ???

    Thanks,

    John C
     
    jc@ukzone.com, Oct 29, 2007 IP
  15. Brewster

    Brewster Active Member

    Messages:
    489
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    60
    #15
    If you read nico's posts you will understand why Lordy's code does not work. Try this:

    <input type="text" size="25" name="myname" value="<?php echo $name; ?>" />
    PHP:
    Brew
     
    Brewster, Oct 29, 2007 IP
  16. jc@ukzone.com

    jc@ukzone.com Guest

    Messages:
    35
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #16
    Many thanks to all who tried to help.
    However, none of the suggestions worked.
    I finished up using str_replace() to get the data across.

    Now I have another problem:
    I use a referer trap for extra security from bots.
    The referer trap works fine UNLESS a security code is input wrong.
    Then the referer becomes "http://website.com?act=resend&name=John%20Craven&mymessage=message" etc...
    And this will change every time.

    I need to extract the "http://website.com" from the referer and then use the result to be tested by the referer trap.

    Can anybody tell me what the code is to extract "http://website.com"

    Thanks...

    John C
     
    jc@ukzone.com, Oct 30, 2007 IP
  17. Lordy

    Lordy Peon

    Messages:
    1,643
    Likes Received:
    29
    Best Answers:
    0
    Trophy Points:
    0
    #17
    you can do an explode on ? since there seems to be only one ? in the line, although im not sure if its only for arrays.

    as for the other guys, thanks! :) I knew <?php was wrong for some reason, but i wrote it down anyway.
     
    Lordy, Oct 30, 2007 IP
  18. jc@ukzone.com

    jc@ukzone.com Guest

    Messages:
    35
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #18
    Thanks very much to everybody who helped me with my little problems.
    I call them little. I suppose they are to you guys, but to me they are major problems.

    I did use the explode() function to split the referer and it worked absolutely prefectly

    Thanks again for all your help....

    John C
     
    jc@ukzone.com, Oct 31, 2007 IP