Forum Moderators: coopster

Message Too Old, No Replies

Begginner: can't get form variable to pass to 2nd .php page

despearate for help!

         

jwm_Az

12:31 am on Nov 2, 2007 (gmt 0)

10+ Year Member


I'm very new to PHP and am not an .HTML expert either; I do have some programming background (ancient history).

The basic issue: I need to pass a form variable ("PartnerName"[smilestopper]) to a PHP variable another page, which is invoked as the action on a Submit button. On the second page I want to make decisions using a Switch/Case control block.

The problem: no matter what I try -- and I've looked at many "solutions" online - I simply can't seem to get the variable's value to transfer.

One twist: the variable in question, "PartnerName", I managed to get to come from a prior page (index.html). So I just need to pass this var's value along to a third page:

index.html - "PartnerName" ---> content passed to page2.php
page2.html - "PartnerName" ---> does NOT come across to page3.php

Relevant snippets of code:

[from index.html]:

<form name="Partners" method="post" action="pape2.php">

<input type="hidden" name="PartnerName" value="">


<div align="center">
<select name="Partners" onChange="document.Partners.PartnerName.value=this.value">
<option selected>&lt; Choose a Partner &gt;</option>
<option value="WAG">Bill Goth</option>
<option value="WRN">Bill Nuts Norwalk</option>

</select>
</div>
<input type="submit" value="Submit IT!">
</form>

[from page2.php:]


<?php
// Retrieve the hidden form variable (using PHP).
$PassedVar = $_POST['PartnerName'];
$PartnerName=$PassedVar;

?>
<form action="page3.php" method="post" enctype="multipart/form-data" name="taxassign" target="_self">
<input type ="hidden" name="PartnerPassed" value="<?=$PartnerName?>" />

<select name= "Role">
<option selected value="">Choose One</option>
<option value="Admin">Admin</option>
<option value="Partner">Partner</option>
<option value="TesterJ">James</option>
<option value="TesterB">Brian</option>
</select>

<input name="submit" type="submit" value="Submit">

[from page3.php - note that "Role comes across, but not "PartnerName"]:

// Receiving variables
@$PartnerName = $_GET['PartnerPassed'];
@$PassedVar = addslashes($_POST['PassedVar']);

...
Switch ($PartnerName)
{
Case "WAG":
Switch ($Role)
{
Case "Admin":
$email_to = "emailaddr0@domain.com"; // tax manager
$email_from = "emailaddr1@domain.com"; // for proper formatting of email Sent From header
break;

::::::::
The Switch statement sees $PartnerName as being empty...! And that's the heart of my problem.

Any help is ENORMOUSLY appreciated!

sonjay

2:49 am on Nov 2, 2007 (gmt 0)

10+ Year Member



You're POSTing the form data, but trying to access $_GET['PartnerPassed'].

If you change that to $_POST['PartnerPassed'] it should work.

cameraman

6:34 am on Nov 2, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Try adding a semicolon to this line:
<input type ="hidden" name="PartnerPassed" value="<?=$PartnerName?>" />

<input type ="hidden" name="PartnerPassed" value="<?=$PartnerName;?>" />

jwm_Az

3:51 pm on Nov 2, 2007 (gmt 0)

10+ Year Member



I want to thank both of you who replied to me -- the combination of your replies *immediately* solved my problem!

whoisgregg

4:49 pm on Nov 2, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Welcome to WebmasterWorld [webmasterworld.com], jwm_Az!

You may want to avoid the use of short tags (and the shorthand echo method). It causes issues if you ever need to handle XML tags (which also start with a

<?
) and because short tags will be completely disabled in future versions of PHP.

Just replace

<?=$var;?>
with
<?php echo $var;?>
and you'll be all set. :)