Forum Moderators: coopster

Message Too Old, No Replies

forms hidden fields not being sent ?

         

cb154

9:16 am on Feb 16, 2010 (gmt 0)

10+ Year Member



Hi, I have a simple form that I am using with sandbox for testing. However it appears that the my hidden field is not being sent with a variable that I put in it. I know this is something simple but having a woods trees moment. I have stripped it out into the simple code below.

My original form looks like this

<?php
$username = $_POST['txtEmail'];
$password = $_POST['txtPwd1'];
$send = $password.'/'.$username;

?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<html>

<body leftmargin="0" topmargin="0" rightmargin="0" marginwidth="0"
class="bgwhite">


<table border="0" cellspacing="0" cellpadding="0">
<tr valign="top">
<td width="517" height="52" bgcolor="#FFFFFF" class="style2" align="center"><form action="pass.php" method="post">
<table width="364" border="1">
<tr>
<td>Email</td>
<td><input name="txtEmail" type="text"></td>
</tr>

<tr>
<td>Password</td>
<td><input name="txtPwd1" type="password"></td>
</tr>
</table>


<input type="hidden" name="custom" value='<?php echo $send ?>'/>
<input type="image" src="https://www.sandbox.paypal.com/en_US/GB/i/btn/btn_buynowCC_LG.gif"
border="0" name="submit" alt="PayPal - The safer, easier way to pay online.">

</form>
</body>
</html>

and I have a simple process page that looks like this

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<?php

$new = $_POST['custom'];

list($user, $pass) = explode('/', $new);

echo $user;
//echo $pass;

?>
<head>
<title></title>
<meta http-equiv="generator" content="CoffeeCup HTML Editor (www.coffeecup.com)" />
<meta name="created" content="Tue, 16 Feb 2010 07:52:38 GMT" />
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
<meta name="description" content="" />
<meta name="keywords" content="" />
</head>
<body>

</body>
</html>

now it appears my field 'custom' is just being sent blank for some reason ?

Matthew1980

9:27 am on Feb 16, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi there CB154,

Welcome to the forum.

After a quick glance this is all I can see:-


<input type="hidden" name="custom" value='<?php echo $send ?>'/>


is missing a ;


<input type="hidden" name="custom" value="<?php echo $send; ?>"/>


And use the double quotes or the sgml parser will throw an error, if your going for w3c compliancy too.

Cheers,

MRb

cb154

9:29 am on Feb 16, 2010 (gmt 0)

10+ Year Member



Indeed had been through this option already (twice I think) just seem to have hit a wall. I have tried changin the form action to use itself and echo the results which are returning fine so not sure what I am doing wrong.

Matthew1980

10:21 am on Feb 16, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi there CB154,

So when you do a print_r($_POST); after the submit, the key for ['custom'] has no value, and you have added the ; at the end of the var $send and still no joy?

Sounds stupid, but have you made sure that all the files that you are pointing to are in the correct places?

Give the submit a value & then check to see if this gets set when you press submit button, as its set as an image an not a submit button - admittedly clutching a straw, but you never know, strange things happen when coding!


<input type="image" src="https://www.sandbox.paypal.com/en_US/GB/i/btn/btn_buynowCC_LG.gif"
border="0" name="submit" alt="PayPal - The safer, easier way to pay online." value="submit">


As I said, just a thought.

Cheers,

MRb

cb154

10:46 am on Feb 16, 2010 (gmt 0)

10+ Year Member



I am being so dim I think. The values of

$username = $_POST['txtEmail'];
$password = $_POST['txtPwd1'];
$send = $password.'/'.$username;

are not being assinged to for some reason so when I submit the form and pass $send there is nothing to send as $_POST is post processing. So should I be using $_GET ?

Matthew1980

11:07 am on Feb 16, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi CB154,

as I understand it, $_GET is only used if you are passing values from the URL ie: index.php?request=some_value

The $_GET['request'] would return 'some_value' as that is what it equals.

When posting from a form ie sending data its a $_POST[].

Try $send = $_POST['txtPwd1']."/".$_POST['txtEmail'];

So I gather as you have tried to see what values are present when you apply the print_r() to the $_POST array?

Cheers,

MRb

cb154

11:14 am on Feb 16, 2010 (gmt 0)

10+ Year Member



yes i did do the print_r. so if i change my code to action itself it gives me the content i.e. print_r ($_POST['txtPwd1']); would give me the content of the pwd field. It seems that my $send is just not getting across to my other page pass.php for some reason as. Think I need a coffee :D this is now the contents of my pass.php


<?php
$gotthem = $_POST['custom'];

list($user, $pass) = explode('/', $gotthem);

//echo $user;
print_r ($_POST['custom']);
//echo $pass;

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title></title>
<meta http-equiv="generator" content="CoffeeCup HTML Editor (www.coffeecup.com)" />
<meta name="created" content="Tue, 16 Feb 2010 07:52:38 GMT" />
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
<meta name="description" content="" />
<meta name="keywords" content="" />
</head>
<body>

</body>
</html>

cb154

11:21 am on Feb 16, 2010 (gmt 0)

10+ Year Member



with my main page looking like this all i get is the / reflected on the other page meaning that the usernam enad password are not getting assigned properly in this setup. arrggghhhhhhhh


<?php
//$username = $_POST['txtEmail'];
//$password = $_POST['txtPwd1'];
//$send = $password.'/'.$username;

$send = $_POST['txtPwd1']."/".$_POST['txtEmail'];


print_r ($send);
?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<html>

<body leftmargin="0" topmargin="0" rightmargin="0" marginwidth="0"
class="bgwhite">


<table border="0" cellspacing="0" cellpadding="0">
<tr valign="top">
<td width="517" height="52" bgcolor="#FFFFFF" class="style2" align="center"><form action="pass.php" method="post">
<table width="364" border="1">
<tr>
<td>Email</td>
<td><input name="txtEmail" type="text", value=""></td>
</tr>

<tr>
<td>Password</td>
<td><input name="txtPwd1" type="password", value=""></td>
</tr>
</table>

<input type="hidden" name="custom" value="<?php echo $send; ?>">
<input type="image" src="https://www.sandbox.paypal.com/en_US/GB/i/btn/btn_buynowCC_LG.gif"
border="0" name="submit" alt="PayPal - The safer, easier way to pay online." value="submit">
</form>
</tbody>
</table>
</body>
</html>

Matthew1980

11:26 am on Feb 16, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



CB154,

Forgive my stupidity, and lack of caffine, are you calling the $_POST and assigning them before the form?


<?php
$username = $_POST['txtEmail'];
$password = $_POST['txtPwd1'];
$send = $password.'/'.$username;

?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<html>

<body leftmargin="0" topmargin="0" rightmargin="0" marginwidth="0"
class="bgwhite">


<table border="0" cellspacing="0" cellpadding="0">
<tr valign="top">
<td width="517" height="52" bgcolor="#FFFFFF" class="style2" align="center"><form action="pass.php" method="post">


Because after re reading your original post it looks like your asking for them before the form is processed?

put:

error_reporting(E_ALL);

at the top of all your php scripts too, this will tell you any hidden non-index errors and the like.. A must for when you are developing.

Cheers,

MRb

cb154

11:31 am on Feb 16, 2010 (gmt 0)

10+ Year Member



yip thats what I'm doing. added that code in and get

Notice: Undefined index: txtPwd1 in C:\xampp\htdocs\testing\index.php on line 7

Notice: Undefined index: txtEmail in C:\xampp\htdocs\testing\index.php on line 7

Let me explain what I need to do. I am trying to assign the values of useername and password concat the string and pass them over in a hidden field. No my guess is I have got this all very very wrong.

Matthew1980

11:43 am on Feb 16, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



CB154,

two files needed:-

first holds the form and no php! (unless your doing error checking...) but still call it a php file ;-p in the form tag assign the action as the second file (in the same working directory or make sure that the path matches where the file is)

Second file holds the PHP parsing instructions, the $_POSTs etc.

use the print_r($_POST) here to make sure that the data is getting there.

The idea is that when you press the submit button, you then SET the names and their values, upon pressing submit, you call the second file, where you can process the data sent by the first file, $_POST will be set then.

I dont mean to sound condescending, but I have no idea how much php/html experience you have, so I thought I would explain the mechanics of a form.

Hopefully this will steer you in the right direction. ;-)

Cheers,

MRb

cb154

2:28 pm on Feb 16, 2010 (gmt 0)

10+ Year Member



I am a reasonable newbie to all this and I understand it works with 2 files however my form is really going to be calling paypal i.e user fills in form details it then goes off to paypal with a couple of form details in a hidden field so that it gets passed to the IPN handler to update my user database. so if I move to 2 files can I seamlessly call paypal still from the buynow button I have on my original form or does the user have to submit request twice ?

Matthew1980

3:09 pm on Feb 16, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi there CD154,

Are these 'values' from a database, or are they just from what the user enters on the main form submit page?

If they are from a database, thats no problem. If they are from a user entered detail ie: name, email etc, then all you already have the detail there and there is no need for the extra field, as the values can be manipulated once the form is posted.

To be honest though, ecommerce & paypal, I have no real experience with, so with regards to IPN stuff, you may have to post another message and detail the parts that you need for doing the IPN processing.

Cheers,

MRb

rocknbil

9:02 pm on Feb 16, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



To make this go away,

Notice: Undefined index: txtPwd1 in C:\xampp\htdocs\testing\index.php on line 7
Notice: Undefined index: txtEmail in C:\xampp\htdocs\testing\index.php on line 7

$username = (isset($_POST['txtEmail']))?$_POST['txtEmail']:NULL;
$password = (isset($_POST['txtPwd1']))?$_POST['txtPwd1']:NULL;
if (! ($username) or ! ($password)) { die("Oops, something is not right, no u and p"); }

... my form is really going to be calling paypal i.e user fills in form details it then goes off to paypal with a couple of form details in a hidden field so that it gets passed to the IPN handler to update my user database. so if I move to 2 files can I seamlessly call paypal still from the buynow button I have on my original form or does the user have to submit request twice ?


First, understand how IPN works (if you already, know, cool, but just in case.)

In PP, you configure the IPN URL. It can be set as a variable in the fom if you use multiples, but for most cases, the setting in PP is fine. Let's call this script "pp-listener.php". It's only job is to listen for IPN tokens from payPal,and send emails of orders completed.

Database, shortened field set for example.

table orders
id|fname|lname|orderid|completed

customer submits form:

id|fname|lname|orderid|completed
1|John|Smith|1234|0

Now they are directed to the payPal payment page. The order ID is sent along with the other variables to payPal as the identifier for this order. If you do it right, when they get their, any non-cc info - name, address, phone, etc. that is used by the payPal payment form will already be populated. All they will have to do is select payment method and enter that info. So to answer the question, "will they have to submit twice?" sorta. :-) But only once to your site.

Payment is completed, payPal sends a token to pp-listener.php with the token for completed payment and the order id.

update orders set completed=1 where orderid=1234

Note that the customer never has to click the "return to merchant" link in payPal. Also, these can come up to three days after the order if they pay with eCheck. It's all good. :-)