SunQuest
           PHP Coding
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Click Here
Go Back   Codewalkers ForumsPHP RelatedPHP Coding

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
You eat, breathe and sleep innovation. Build your mobile intelligence with BlackBerry® experts this July. Register Today!
  #1  
Old May 13th, 2008, 09:44 AM
p8ball4life p8ball4life is offline
Registered User
Codewalkers Newbie (0 - 499 posts)
 
Join Date: May 2008
Posts: 2 p8ball4life User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 51 m 54 sec
Reputation Power: 0
_POST not working with form

I'm having trouble gettting my _POST to grab the variables from the initial page onto the secondary page.

The initial page consists of a form that reloads itself upon submission to validate client side. If the validation is succesful then the page redirects to the secondary page using javascript. The second page can not pick up the variables unless I change the action of the form to that page itself.

Am I doing something wrong?

Here is some of the code:

PHP Code:
<?php
$page 
"home";
include_once(
"includes/header.inc");

$url 'pag2';


$email2 " ";
$fname2 " ";
$lname2 " ";
$address2 " ";
$city2 " ";
$state2 " ";
$zipcode2 " ";
$hphone2 " ";
$wphone2 " ";
$comments2 " ";

if (
$_POST['process'] == 1) {
    
$email2   $_POST['email'];
    
$comments2 $_POST['comments'];
    
$fname2 $_POST['fname'];
    
$lname2 $_POST['lname'];
    
$address2 $_POST['caddress'];
    
$city2 $_POST['city'];
    
$state2 $_POST['state'];
    
$zipcode2 $_POST['zip'];
    
$hphone2 $_POST['hphone'];
    
$wphones2 $_POST['wphone'];
}

require_once(
'recaptchalib.php');
$publickey "xxx";
$privatekey "xxx";
?>
    
<!--- Content Starts Here ---->

<table width="455" border="1" cellpadding="8" cellspacing="0">
<tr>
<td valign="top">
<font face="'MS Sans Serif',Geneva,sans-serif" size="-1">
<form method="post" action="page1.php" name="xform">
<table>
<tr>
  <td><font color="#990000"><font face="'MS Sans Serif',Geneva,sans-serif" size="-1"><b>E-Mail:</b> </font></td>
  <td><input name="email" type=text size=35 value="<?print $email2?>"></td>
</tr>
<tr>
  <td><font color="#990000"><font face="'MS Sans Serif',Geneva,sans-serif" size="-1"><b>First 

Name:</b></font></td>
  <td><input name="fname" type=text size=35 value="<?print $fname2?>"></td>
</tr>

...form creation continues...


<!--Captcha Start-->

<?php

echo recaptcha_get_html($publickey);

//the response from reCAPTCHA
$resp recaptcha_check_answer ($privatekey,
                                
$_SERVER["REMOTE_ADDR"],
                                
$_POST["recaptcha_challenge_field"],
                                
$_POST["recaptcha_response_field"]);

//the error code from reCAPTCHA, if any
$error null;


//are we submitting the page?
if ($_POST["Submit"]) {
      if (!
$resp->is_valid) {
        echo 
"<B><FONT COLOR = 'red'>Your response was incorrect.  Please try again.</FONT></B>";
    }

    else {


        echo 
"<script language=\"javascript\">
        location.href=\"$url\";
        </script>"
;

        echo 
"<B>If you have javascript disabled you may click on this link to process the form: </B>
    <A HREF='page2.php'>page2.php</A>"
;    
    }
}


echo 
"<script language=\"javascript\">
    var RecaptchaOptions = {
       theme : 'white'};
    </script>"
;

echo 
recaptcha_get_html($publickey$error);
?>
</p>

<!--Captcha End-->

<input type="hidden" name="process" value="1">
<p> <input type="submit" name="Submit" value="Submit"></p></div></form>


And trying to grab them on the second page for processing:

PHP Code:
<?php

$fname 
$HTTP_POST_VARS['fname'];
$lname1 $HTTP_POST_VARS['lname'];
$lname stripslashes($lname1);
$email $HTTP_POST_VARS['email'];


I tried using just _POST becuase I read that the http_post_vars was a little antiquated, but the result was the same.

Thanks for your help!

-Tyler

Last edited by p8ball4life : May 13th, 2008 at 09:50 AM.

Reply With Quote
  #2  
Old May 14th, 2008, 03:41 PM
icandothat's Avatar
icandothat icandothat is offline
Moderator
Click here for more information.
 
Join Date: Apr 2007
Location: San Diego, CA
Posts: 1,548 icandothat User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 Days 2 h 20 m 4 sec
Reputation Power: 3
the post wont carry to the second page. you posted to the first page, that's where the post variables are available. When you redirect they go away. If you want to maintain your current scheme I would suggest storing the $_POST vars in the $_SESSION then reading and cleaning them on the second page.

so on page1 before you redirect do this
$_SESSION['p1Post'] = $_POST;
then on page two you can retrieve the vars from $_SESSION['p1Post']

dont forget to do session_start(); at the top of both of the pages.
__________________
There is no spoon.

Reply With Quote
  #3  
Old May 14th, 2008, 04:45 PM
RevRaz RevRaz is offline
Registered User
Codewalkers Newbie (0 - 499 posts)
 
Join Date: May 2008
Posts: 8 RevRaz User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 16 m 20 sec
Reputation Power: 0
You start your form here

<form method="post" action="page1.php" name="xform">

So your next page should be page1.php to receive the posts

Reply With Quote
  #4  
Old May 15th, 2008, 08:49 AM
p8ball4life p8ball4life is offline
Registered User
Codewalkers Newbie (0 - 499 posts)
 
Join Date: May 2008
Posts: 2 p8ball4life User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 51 m 54 sec
Reputation Power: 0
I read into sessions, but decided to simply migrate the processing from page2 into page1.

Is there any reduced security involved with this?

Reply With Quote
  #5  
Old May 15th, 2008, 11:51 AM
icandothat's Avatar
icandothat icandothat is offline
Moderator
Click here for more information.
 
Join Date: Apr 2007
Location: San Diego, CA
Posts: 1,548 icandothat User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 Days 2 h 20 m 4 sec
Reputation Power: 3
no but it leads to spaghetti code. As you become a more sophisticated programmer and start coding more complicated projects you will not want to do this. The trend is to separate out your display from your logic and database interaction. Putting it all on one page will work but it will get complicated and reduce the reuseablilty of your code.

That having been said, who cares. If you can make it work then make it work. You can fix it later, you won't, but you can.

Reply With Quote
Reply

Viewing: Codewalkers ForumsPHP RelatedPHP Coding > _POST not working with form


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway