View Full Version : I want to retain the data from a form and enter it into another form
jc@ukzone.com
Oct 28th 2007, 1:50 pm
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
Lordy
Oct 28th 2007, 1:53 pm
<input type="text" size=25 name="myname" value="<?php=$name ?>"
should work
nico_swd
Oct 29th 2007, 3:46 am
Except that there's no <?php= tag, yes. It should be either <? or <?php. All other tags are deprecated.
jc@ukzone.com
Oct 29th 2007, 9:29 am
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
Lordy
Oct 29th 2007, 11:00 am
your form has to set them as a value.
please post your code if im not understanding properly
bLuefrogx
Oct 29th 2007, 12:32 pm
Depreciated doesn't mean there isn't. It just means its going to be phased out eventually :)
nico_swd
Oct 29th 2007, 12:47 pm
Yes, but he was using <?php= tags, which do not exist. Read my post again.
jc@ukzone.com
Oct 29th 2007, 1:53 pm
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
nico_swd
Oct 29th 2007, 2:00 pm
I know I know, I was referring to this post:
http://forums.digitalpoint.com/showpost.php?p=4997043&postcount=2
jc@ukzone.com
Oct 29th 2007, 2:00 pm
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
Lordy
Oct 29th 2007, 2:49 pm
you will need to edit contact.tpl and set the a value
dadougalee
Oct 29th 2007, 2:52 pm
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.
jc@ukzone.com
Oct 29th 2007, 5:41 pm
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 29th 2007, 5:47 pm
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
Brewster
Oct 29th 2007, 5:55 pm
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; ?>" />
Brew
jc@ukzone.com
Oct 30th 2007, 3:37 pm
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
Lordy
Oct 30th 2007, 5:28 pm
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.
jc@ukzone.com
Oct 31st 2007, 10:38 am
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
vBulletin® v3.6.8, Copyright ©2000-2008, Jelsoft Enterprises Ltd.