ecabrera Posted January 25, 2012 Share Posted January 25, 2012 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] Quote Link to comment https://forums.phpfreaks.com/topic/255711-hidden-fileds/ Share on other sites More sharing options...
floridaflatlander Posted January 25, 2012 Share Posted January 25, 2012 I think it's with POST or GET just like a regular variable. Quote Link to comment https://forums.phpfreaks.com/topic/255711-hidden-fileds/#findComment-1310842 Share on other sites More sharing options...
ecabrera Posted January 25, 2012 Author Share Posted January 25, 2012 i tryed it but notinh happens Quote Link to comment https://forums.phpfreaks.com/topic/255711-hidden-fileds/#findComment-1310843 Share on other sites More sharing options...
AyKay47 Posted January 25, 2012 Share Posted January 25, 2012 i tryed it but notinh happens you retrieve it like you would a normal input field. Quote Link to comment https://forums.phpfreaks.com/topic/255711-hidden-fileds/#findComment-1310849 Share on other sites More sharing options...
Pikachu2000 Posted January 25, 2012 Share Posted January 25, 2012 Put this at the top of the script that does the processing and see what the values are in the $_POST array after the form has been submitted. echo '<pre>'; print_r($_POST); echo '</pre>'; Quote Link to comment https://forums.phpfreaks.com/topic/255711-hidden-fileds/#findComment-1310853 Share on other sites More sharing options...
ecabrera Posted January 25, 2012 Author Share Posted January 25, 2012 ok i got some value so would i just do this to call them out $_POST = ['item_name_' . $x . '']; Quote Link to comment https://forums.phpfreaks.com/topic/255711-hidden-fileds/#findComment-1310854 Share on other sites More sharing options...
AyKay47 Posted January 25, 2012 Share Posted January 25, 2012 $item = $_POST['item_name']; Quote Link to comment https://forums.phpfreaks.com/topic/255711-hidden-fileds/#findComment-1310855 Share on other sites More sharing options...
nine7ySix Posted January 25, 2012 Share Posted January 25, 2012 It appears that you are looping this, so yes, you would use $_POST = ['item_name_' . $x]; etc. You don't need the ." at the end. Quote Link to comment https://forums.phpfreaks.com/topic/255711-hidden-fileds/#findComment-1310857 Share on other sites More sharing options...
ecabrera Posted January 25, 2012 Author Share Posted January 25, 2012 $_POST = ['item_name_' $x]; and $item = $_POST['item_name']; does not work i try both and they didnt show up Quote Link to comment https://forums.phpfreaks.com/topic/255711-hidden-fileds/#findComment-1310861 Share on other sites More sharing options...
AyKay47 Posted January 25, 2012 Share Posted January 25, 2012 post the relevant form handling code. Quote Link to comment https://forums.phpfreaks.com/topic/255711-hidden-fileds/#findComment-1310862 Share on other sites More sharing options...
ecabrera Posted January 25, 2012 Author Share Posted January 25, 2012 what do you mean Quote Link to comment https://forums.phpfreaks.com/topic/255711-hidden-fileds/#findComment-1310865 Share on other sites More sharing options...
nine7ySix Posted January 25, 2012 Share Posted January 25, 2012 I'm not exactly sure, but you might want to store $x in a hidden input and get the value of $x in checkout.php. Because right now, $_POST = ['item_name_' . $x . '']; which I presume is on checkout.php, is meaningless without the $x value. Quote Link to comment https://forums.phpfreaks.com/topic/255711-hidden-fileds/#findComment-1310871 Share on other sites More sharing options...
ecabrera Posted January 25, 2012 Author Share Posted January 25, 2012 X is the the quannty Quote Link to comment https://forums.phpfreaks.com/topic/255711-hidden-fileds/#findComment-1310872 Share on other sites More sharing options...
nine7ySix Posted January 25, 2012 Share Posted January 25, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/255711-hidden-fileds/#findComment-1310876 Share on other sites More sharing options...
ecabrera Posted January 25, 2012 Author Share Posted January 25, 2012 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>'; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/255711-hidden-fileds/#findComment-1310898 Share on other sites More sharing options...
ecabrera Posted January 25, 2012 Author Share Posted January 25, 2012 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 ) Quote Link to comment https://forums.phpfreaks.com/topic/255711-hidden-fileds/#findComment-1310909 Share on other sites More sharing options...
AyKay47 Posted January 25, 2012 Share Posted January 25, 2012 again, post the form handling script. Quote Link to comment https://forums.phpfreaks.com/topic/255711-hidden-fileds/#findComment-1311024 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.