Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to pass an array through a hidden field

Status
Not open for further replies.

gokeeffe

Programmer
Jan 11, 2005
170
IE
I am trying to pass an array through a hidden field in a form I have on my
confirmation page, all of my other variable pass through fine but I can't get the
array to pass through to the reponse page




----------------------- Step 3 Page -----------------------------------

This is where i have set the array

// Set the array
$_SESSION['grind_array'][] = array(
'Interest' => $_SESSION['Interest'],
'Subject' => $_SESSION['Subject'],
'Level' => $_SESSION['Level'],
'counter' => $_SESSION['counter']
);




-------------- confirmation page ----------------------------------


$tmp = "$timestamp.$merchantid.$orderid.$amount.$curr";
$md5hash = md5($tmp);
$tmp = "$md5hash.$secret";
$md5hash = md5($tmp);

$qualifications = escape_data($_SESSION['qualifications']);
$experience = escape_data($_SESSION['experience']);
$add_location = escape_data($_SESSION['additional_locations']);
$availability = escape_data($_SESSION['availability']);
$rate= escape_data($_SESSION['rate_per_hour']);
$add_number = escape_data($_SESSION['additional_number']);
$email_address = escape_data($_SESSION['email_address']);
$add_info = escape_data($_SESSION['additional_information']);

$grind_array = $_SESSION['grind_array'];




?>

</form>

<form action= method=post>

<input type=hidden name="MERCHANT_ID" value="<?=$merchantid?>">
<input type=hidden name="ORDER_ID" value="<?=$orderid?>">
<input type=hidden name="CURRENCY" value="<?=$curr?>">
<input type=hidden name="AMOUNT" value="<?=$amount?>">
<input type=hidden name="TIMESTAMP" value="<?=$timestamp?>">
<input type=hidden name="MD5HASH" value="<?=$md5hash?>">
<input type=hidden name="AUTO_SETTLE_FLAG" value="1">
<input type=hidden name="USER_ID" value="<?=$_SESSION['user_id']?>">
<input type=hidden name="QUALIFICATIONS" value="<?=$qualifications?>">
<input type=hidden name="EXPERIENCE" value="<?=$experience?>">
<input type=hidden name="ADD_LOCATION" value="<?=$add_location?>">
<input type=hidden name="AVAILABILITY" value="<?=$availability?>">
<input type=hidden name="RATE" value="<?=$rate?>">
<input type=hidden name="ADD_NUMBER" value="<?=$add_number?>">
<input type=hidden name="EMAIL_ADDRESS" value="<?=$email_address?>">
<input type=hidden name="ADD_INFO" value="<?=$add_info?>">

<input type=hidden name="GRINDS" value="<?=$grind_array?>">



------------------ Response Page--------------------------------------



$timestamp = $TIMESTAMP;
$result = $RESULT;
$orderid = $ORDER_ID;
$message = $MESSAGE;
$authcode = $AUTHCODE;
$pasref = $PASREF;
$user_id=$USER_ID;
$qualifications= $QUALIFICATIONS;
$experience = $EXPERIENCE;
$add_location = $ADD_LOCATION;
$availability = $AVAILABILITY;
$rate= $RATE;
$add_number = $ADD_NUMBER;
$email_address = $EMAIL_ADDRESS;
$add_info = $ADD_INFO;

$grind_array = $GRINDS;



if ($result_two)
{
foreach ($grind_array as $entry)
{
$query_three = "INSERT INTO grind_record

(user_id,id_interest,id_subject,id_level,grind_date)
VALUES ('$user_id','{$entry['Interest']}','{$entry['Subject']}','{$entry['Level']}',NOW()

)";
// Run the query
$result_three = @mysql_query ($query_three);
echo'success';
}
}
else
{
echo'failure';
}
 
I've just come up against the same problem (was literally about to post the same question). Will let U know if I come up with anything.
 
it would seem the only way to do this is to convert the array to a deliminated sting and pass that, then at the other end rebuild the array.
eg:
$myarray = ("a", "b", "c")
$convertedstring = "a-b-c-"
and I guess if you have an indexed array you'd do something similar:
$myindexedarray = ( a -> 1, b -> 2)
$convertedstring = "a:1-b:2"

Hope this helps.... now to write the conversion routines

Oh PS there is a php command serialize but I'm never had much luck with it...
 
I have a few comments on the OP's coding and a question for mes123.

mes123: What problems do you have with serialize and unserialize. I have been using them for about 6 years with no problems, as have most other PHP programers.

OP:
Yes, mes123 is correct, you can't pass an "normal" array via a form, you have to serialize it first.
Your line
Code:
<input type=hidden name="GRINDS" value="<?=$grind_array?>">
should read
Code:
<input type=hidden name="GRINDS" value="<? echo serialize($grind_array); ?>">
To retrieve the array:
Code:
$grind_array = unserialize($_POST['GRINDS']);

Your programming style suggests that you are assuming tha register_globals is turned on. This is the section that suggests this:
Code:
$timestamp = $TIMESTAMP;
$result = $RESULT;
$orderid = $ORDER_ID;
$message = $MESSAGE;
$authcode = $AUTHCODE;
$pasref = $PASREF;
$user_id=$USER_ID;
$qualifications= $QUALIFICATIONS;
$experience = $EXPERIENCE;
$add_location = $ADD_LOCATION;
$availability = $AVAILABILITY;
$rate= $RATE;
$add_number = $ADD_NUMBER;
$email_address = $EMAIL_ADDRESS;
$add_info = $ADD_INFO;
You should be specifying the superarray $_POST in each of these lines. For example:
Code:
$user_id=$_POST['USER_ID'];

Note to all posters: When you include code in your posts, please surround all code with the TGML tags [red][ignore]
Code:
[/ignore][/red]
.

Ken
 
my problem with serialise and unserialize probably stems from the fact I'm not use to a loosely typed langauge like PHP (I usually program in Java) and keep getting problems with arrays that have only one item suddenly becoming strings when passed via the $_POST vars.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top