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
Except that there's no <?php= tag, yes. It should be either <? or <?php. All other tags are deprecated.
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
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
I know I know, I was referring to this post: http://forums.digitalpoint.com/showpost.php?p=4997043&postcount=2
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
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.
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
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
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
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
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.
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