Jump to content

Recommended Posts

how would i retrieve a hidden field from this form

 

 

 

	

$checkoutBtn .= '<form action="checkout.php" method="POST" id="checkform">
        <input type="hidden" name="item_name_' . $x . '" value="' . $eventname . '">
        <input type="hidden" name="amount_' . $x . '" value="' . $studentsprice . '">
        <input type="hidden" name="quantity_' . $x . '" value="' . $each_item['quantity'] . '">;[
        <input type="hidden" name="custom" value="' . $product_id_array . '">
        <input type="submit" class="checkoutbtn" name="checkoutbtn" value="CHECKOUT" />
</form>';

/code]

Link to comment
https://forums.phpfreaks.com/topic/255711-hidden-fileds/
Share on other sites

Why are you saving the in quantity as the name of an input?

Why can't you save the quantity as a separate input, in that case, you don't have to worry about $_POST['item_name_'.$x] not working.

It would be a lot easier to understand the situation if you posted all of your code here.

Link to comment
https://forums.phpfreaks.com/topic/255711-hidden-fileds/#findComment-1310876
Share on other sites

Checkouy button is where my code is at

 

<?php 
// render the cart for the user to view on the page)
$cartOutput = "";
$cartoutput = "";
$cartTotal = "";
$checkoutBtn = '';
$product_id_array = '';
if (!isset($_SESSION["cart"]) || count($_SESSION["cart"]) < 1) {
    $cartoutput = "<h2 align='center'>Your shopping cart is empty</h2>";
} else {

     //start the form here to get some data form the other varablie
    $checkoutBtn .= '<form action="checkout.php" method="POST" id="checkform">';
    
// Start the For Each loop
$i = 0; 
    foreach ($_SESSION["cart"] as $each_item) { 
	$item_id = $each_item['item_id'];
	$sql = mysql_query("SELECT * FROM events WHERE id='$item_id' LIMIT 1");
	while ($row = mysql_fetch_array($sql)) {
		$eventname = $row["eventname"];
		$eventinfo = $row["eventinfo"];
		$studentsprice = $row["studentsprice"];
		$category = $row["category"];

	}
	//steeing the money function to make it look like money haha
	$pricetotal  = $studentsprice * $each_item['quantity'];
	$cartTotal = $pricetotal  + $cartTotal;
	setlocale(LC_MONETARY, "en_US");
        $pricetotal  = money_format("%10.2n", $pricetotal );
        
        //checotut
$x = $i + 1;
$checkoutBtn .= '<input type="hidden" name="item_name_' . $x . '" value="' . $eventname . '">
        <input type="hidden" name="amount_' . $x . '" value="' . $studentsprice . '">
        <input type="hidden" name="quantity_' . $x . '" value="' . $each_item['quantity'] . '">  ';
        
	// Create the product array variable
	$product_id_array .= "$item_id-".$each_item['quantity'].","; 
	// Dynamic table row assembly
	$cartOutput .= "<tr>";
        $cartOutput .= '<td>' . $eventname . '</td>';
        $cartOutput .= '<td>' . $category . '</td>';
	$cartOutput .= '<td>' . $eventinfo . '</td>';
	$cartOutput .= '<td>$' . $studentsprice . '</td>';
	$cartOutput .= '<td><form action="cart.php" method="post">
	<input name="quantity" type="text" value="' . $each_item['quantity'] . '" size="3" maxlength="2" />
	<input name="adjustBtn' . $item_id . '" type="submit" class="change" value="Update" />
	<input name="item_to_adjust" type="hidden" value="' . $item_id . '" />
	</form></td>';
	//$cartOutput .= '<td>' . $each_item['quantity'] . '</td>';
	$cartOutput .= '<td>' . $pricetotal  . '</td>';
	$cartOutput .= '<td><form action="cart.php" method="post"><input name="deleteBtn' . $item_id . '" type="submit" class="remove" value="" /><input name="index_to_remove" type="hidden" value="' . $i . '" /></form></td>';
	$cartOutput .= '</tr>';
	$i++; 
    } 
setlocale(LC_MONETARY, "en_US");
        $cartTotal = money_format("%10.2n", $cartTotal);
$cartTotal = "<div class='total'>Cart Total : ".$cartTotal." USD</div> ";

//making it finish 
	$checkoutBtn .= '<input type="hidden" name="custom" value="' . $product_id_array . '">
        <input type="submit" class="checkoutbtn" name="checkoutbtn" value="CHECKOUT" />
</form>';

}
?>

Link to comment
https://forums.phpfreaks.com/topic/255711-hidden-fileds/#findComment-1310898
Share on other sites

i get this what  can i do Pikachu2000

 

Array
(
    [items] => 3
    [item_name_1] => RND VS RBC
    [amount_1] => 5.00
    [quantity_1] => 3
    [item_name_2] => RND VS MRH
    [amount_2] => 5.00
    [quantity_2] => 1
    [item_name_3] => RND vs RBC
    [amount_3] => 5.00
    [quantity_3] => 1
    [custom] => 8-3,10-1,12-1,
    [checkoutbtn] => CHECKOUT
)

Link to comment
https://forums.phpfreaks.com/topic/255711-hidden-fileds/#findComment-1310909
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.