The id is passing correctly but the post value is returning as empty , Please suggest with a solution what mistake i am doing here
Here is my view
<?php for($i=0;$i<count($array['value']);$i++) { ?>
<?php $id= $room['value'][$i]['Index']; ?>
<ul >
<li>
<?php echo form_open('cont/arraylist/'.$id); ?>
<input type="hidden" name="<?php echo 'foo'.$i ?>" value="<?php echo $room['value'][$i]['foo']?>" />
<input type="hidden" name="<?php echo 'boo'.$i?>" value="<?php echo $room['value'][$i]['boo']?>" />
<input type="hidden" name="<?php echo 'bar'.$i?>" value="<?php echo $room['value'][$i]['bar']?>" />
<input type="hidden" name="<?php echo 'baba'.$i?>" value="<?php echo $room['value'][$i]['baba']?>" />
<input type="submit" />
<?php echo form_close(); ?>
</li>
</ul>
<?php } ?>
Here is My controller
function arraylist($id)
{
echo $id;
echo $this->input->post('foo'.$id);
echo $this->input->post('boo'.$id);
echo $this->input->post('bar'.$id);
echo $this->input->post('baba'.$id);
}
You are trying get the input name 'foo'.$id but in view you are concatenating 'foo'.$i. This occurs to all. Do this:
<input type="hidden" name="<?php echo 'foo'.$id ?>" value="<?php echo $room['value'][$i]['foo']?>" />
<input type="hidden" name="<?php echo 'boo'.$id?>" value="<?php echo $room['value'][$i]['boo']?>" />
<input type="hidden" name="<?php echo 'bar'.$id?>" value="<?php echo $room['value'][$i]['bar']?>" />
<input type="hidden" name="<?php echo 'baba'.$id?>" value="<?php echo $room['value'][$i]['baba']?>" />
Related
In my code for shopping cart, sessions are not formed dynamically. I want to create session in this page and use sessions on the other page for item cart details.
How do I solve this problem?
<form method="post" action="men.php?action=add&id=<?php echo
$product['id']; ?>">
<img src="<?php echo $product['image'];?>">
<img class="hover-img" src="<?php echo $product['h_image'];?>" >
<p><?php echo $product['price'];?></p>
<h6><?php echo $product['name'];?></h6>
<input type="hidden" name="id" value="<?php echo $product['id']; ?>" />
<input type="hidden" name="hidden_name" value="<?php echo
$product['name']; ?>" />
<input type="hidden" name="hidden_price" value="<?php echo
$product['price']; ?>" />
<input type="hidden" name="hidden_image" value="<?php echo
$product['image']; ?>" />
Quantity <input type="text" class="form-control" name="qty" value="1" /><br>
<input type="submit" name="cart" value="Add to Cart" />
</form>
<?php
session_start();
if(isset($_POST['cart']))
{
// not working
if(isset($_SESSION['shopping_cart']))
{
$count= count($_SESSION['shopping_cart']);
$product_ids= array_column($_SESSION['shopping_cart'],'id');
if(!in_array(filter_input(INPUT_GET,'id'), $product_ids))
{
$_SESSION['shopping_cart'][$count]=array
(
'id'=> filter_input(INPUT_GET,'id'),
'name'=> filter_input(INPUT_POST,'hidden_name'),
'price'=> filter_input(INPUT_POST,'hidden_price'),
'quantity'=> filter_input(INPUT_POST,'qty'),
'image'=> filter_input(INPUT_POST,'hidden_image')
);
}
else
{
for($i=0; $i<count($product_ids); $i++)
{
if($product_ids[$i]==filter_input(INPUT_GET,'id'))
{
$_SESSION['shopping_cart'][$i]['quantity']+=
filter_input(INPUT_POST,'quantity');
}
}
}
}
else
{
}
}
?>
Sara. The session_start(); should be the first line in your document.
So, it should look like:
<?php session_start(); ?>
and then the rest of your work
NOTE : IF IT STILL NOT WORKING PLEASE PROVIDE THE ERROR.
Just that, here's some of he code i use
<?php
include('lib_carrito.php');
session_start();
?>
<form action="mete_producto.php" method="POST">
<input type="hidden" name="producto" value="<?php echo $nombre ?>">
<input type="hidden" name="precio" value="<?php echo $precio ?>">
<input type="hidden" name="producto" value="<?php echo $Id ?>">
<?php
if ($stock == 0 || !(isset($_SESSION['usuario'])) || $_SESSION['autoridad'] == 1) {
echo "<input type='submit' class='disabled' value='Añadir al carrito'>";
}
else{
echo "<input type='submit' class='añadir' value='Añadir al carrito'>";
}
?>
<select name="cantidad" style="height:35px; font-size: 25px">
<?php
for ($i=1; $i <= $stock; $i++) {
echo "<option value='".$i."'>".$i."</option>";
}
?>
</select>
</form>
That's on the page with the item the customer would buy,
then this is mete_producto.php
<?php
include("lib_carrito.php");
require('config.php');
session_start();
$_SESSION['ocarrito']->introduce_producto($_REQUEST["Id"], $_REQUEST["Nombre"], $_REQUEST["Precio"], $_REQUEST['Cantidad']);
//header("Location:index.php");
?>
I have the header as a comment so it would show me the errors,
for all of them is the same error 'Undefined index: Id'
You haven't defined either Id or Nombre as name attributes to be sent with your form. You have, however, assigned two producto names which have corresponding PHP variables. I assume this is how you are intending to use these variables.
Instead of:
<input type="hidden" name="producto" value="<?php echo $nombre ?>">
<input type="hidden" name="precio" value="<?php echo $precio ?>">
<input type="hidden" name="producto" value="<?php echo $Id ?>">
You're looking for:
<input type="hidden" name="nombre" value="<?php echo $nombre ?>">
<input type="hidden" name="precio" value="<?php echo $precio ?>">
<input type="hidden" name="Id" value="<?php echo $Id ?>">
We're using the built in Paypal Standard payment system on Opencart but it is not pulling the option price to Paypal.
Here is the code we have in our pp_standard.tpl file
<?php $i = 1; ?>
<?php foreach ($products as $product) { ?>
<input type="hidden" name="item_name_<?php echo $i; ?>" value="<?php echo $product['name']; ?>" />
<input type="hidden" name="item_number_<?php echo $i; ?>" value="<?php echo $product['model']; ?>" />
<input type="hidden" name="amount_<?php echo $i; ?>" value="<?php echo $product['price']; ?>" />
<input type="hidden" name="quantity_<?php echo $i; ?>" value="<?php echo $product['quantity']; ?>" />
<input type="hidden" name="weight_<?php echo $i; ?>" value="<?php echo $product['weight']; ?>" />
<?php $j = 0; ?>
<?php foreach ($product['option'] as $option) { ?>
<input type="hidden" name="on<?php echo $j; ?>_<?php echo $i; ?>" value="<?php echo $option['value']; ?>" />
<input type="hidden" name="os<?php echo $j; ?>_<?php echo $i; ?>" value="<?php echo $option['price']; ?>" />
<?php $j++; ?>
<?php } ?>
<?php $i++; ?>
<?php } ?>
I think the line that is the issue is this
<input type="hidden" name="os<?php echo $j; ?>_<?php echo $i; ?>"
value="<?php echo $option['price']; ?>" />
But I am not sure what to change it to for Paypal to pull the correct price
Here is the code that shows the price in the cart.tpl file
<?php foreach ($product['option'] as $option) { ?>
- <small><?php echo $option['name']; ?>: <?php echo $option['value']; ?>
- Price: <?php echo $option['price']; ?></small><br />
you can't use counter with paypal standard hidden inputs like amount, item_name and other hidden inputs inside foreach
<input type="hidden" name="amount_<?php echo $i; ?>" value="<?php echo $product['price']; ?>" />
in your case, paypal is looking request from input="amount" and you are posting request through input="amount_1"
How do I integrate paybox system to handle deferred payment?
I learned that PBX_DIFF parameter is used to mention no. of days to delay the transaction. Thats exactly what I wanted. But there seems no working code for php with deferred payment for Paybox.
The following code is working fine without mentioning the deferred payment parameter (PBX_DIFF). But when I add that parameter, its not working
<form name="paybox_frm" id="paybox_frm" method="GET" action="<?php echo $payboxUrl;?>">
<input type="hidden" name="PBX_SITE" value="<?php echo $PBX_SITE; ?>">
<input type="hidden" name="PBX_RANG" value="<?php echo $PBX_RANG; ?>">
<input type="hidden" name="PBX_IDENTIFIANT" value="<?php echo $PBX_IDENTIFIANT; ?>">
<input type="hidden" name="PBX_TOTAL" value="<?PHP echo $MONTANT;?>">
<input type="hidden" name="PBX_DEVISE" value="<?php echo $PBX_DEVISE; ?>">
<input type="hidden" name="PBX_CMD" value="<?PHP echo $REFERENCE;?>">
<input type="hidden" name="PBX_PORTEUR" value="<?PHP echo $PORTEUR;?>">
<input type="hidden" name="PBX_RETOUR" value="<?php echo $PBX_RETOUR;?>">
<input type="hidden" name="PBX_HASH" value="<?php echo $PBX_HASH;?>">
<input type="hidden" name="PBX_TIME" value="<?PHP echo $datetime;?>">
<input type="hidden" name="PBX_HMAC" value="<?PHP echo $pbx_hmac;?>">
<!-- Code added for return url-->
<input type="hidden" name="PBX_REFUSE" value="<?PHP echo $PBX_REFUSE;?>" />
<input type="hidden" name="PBX_ANNULE" value="<?PHP echo $PBX_ANNULE;?>" />
<input type="hidden" name="PBX_EFFECTUE" value="<?PHP echo $PBX_EFFECTUE;?>" />
<input type="hidden" name="PBX_LANGUE" value="<?PHP echo $PBX_LANGUE;?>" />
Any help greatly appreciated. Thanks in advance.
<section class="rl-box">
<div class="container padd-xs-0">
<div class="content-section1">
<div class="left-cont col-md-12 col-sm-12"
<div class="container-fluid">
<?php
$PBX_SITE = "1999888";
$PBX_RANG = "32";
$PBX_IDENTIFIANT = "your identifiant id";
$secretKeyTest = "0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF";
$PBX_PORTEUR = "your-email";
$PAYBOX_DOMAIN_SERVER = "tpeweb.paybox.com";
$dateTime = date("c");
$PBX_TOTAL = 4000; //$_POST["PBX_TOTAL"]; // Amount
$PBX_DEVISE = 978;
//$PBX_CMD = $_POST["PBX_CMD"]."|".$_POST["user"]."|".$_POST["typed"]."|".$_POST["period"]."|".$_POST["id"]; // order ID no.
$PBX_CMD = 1; // order ID no.
$PBX_RETOUR = "Mt:M;Ref:R;Auto:A;Erreur:E";
$PBX_HASH = "SHA512";
$PBX_TIME = $dateTime;
//$PBX_EFFECTUE = "http://www.leader-underwriting.eu/payment/payment.php";
$msg = "PBX_SITE=$PBX_SITE" .
"&PBX_RANG=$PBX_RANG" .
"&PBX_IDENTIFIANT=$PBX_IDENTIFIANT" .
"&PBX_TOTAL=$PBX_TOTAL" .
"&PBX_DEVISE=$PBX_DEVISE" .
"&PBX_CMD=$PBX_CMD" .
"&PBX_PORTEUR=$PBX_PORTEUR" .
"&PBX_RETOUR=$PBX_RETOUR" .
"&PBX_HASH=$PBX_HASH" .
"&PBX_TIME=$PBX_TIME";
$binKey = pack("H*", $secretKeyTest);
$hmac = strtoupper(hash_hmac('sha512', $msg, $binKey));
$cuu = str_replace(",", "", $ramount);
?>
<form method="POST" name="form_payment" action="https://preprod-tpeweb.paybox.com/cgi/MYchoix_pagepaiement.cgi">
<input type="hidden" name="PBX_SITE" value="<?php echo $PBX_SITE; ?>">
<input type="hidden" name="PBX_RANG" value="<?php echo $PBX_RANG; ?>">
<input type="hidden" name="PBX_IDENTIFIANT" value="<?php echo $PBX_IDENTIFIANT; ?>">
<input type="hidden" name="PBX_TOTAL" value="<?php echo $PBX_TOTAL; ?>"> <!--dynamic-->
<input type="hidden" name="PBX_DEVISE" value="<?php echo $PBX_DEVISE; ?>">
<input type="hidden" name="PBX_CMD" value="<?php echo $PBX_CMD; ?>"> <!--dynamic-->
<input type="hidden" name="PBX_PORTEUR" value="<?php echo $PBX_PORTEUR ?>">
<input type="hidden" name="PBX_RETOUR" value="<?php echo $PBX_RETOUR; ?>">
<input type="hidden" name="PBX_HASH" value="<?php echo $PBX_HASH; ?>">
<input type="hidden" name="PBX_TIME" value="<?php echo $PBX_TIME; ?>">
<input type="hidden" name="PBX_HMAC" value="<?php echo $hmac; ?>">
<button type="submit" class="btn btn-primary payment">
Payer
</button>
</form>
<center>
</center>
</div>
</div>
</div> <!-- .container-fluid -->
</div>
</div>
</div>
</section>
I have a big form that contains X amount of posts that has 15 fields per post along with 1 hidden field.
Let's assume I have 14 posts. This means my form would send 211 fields (14x15 fields plus 1 hidden field).
The user does not have to fill in all fields.
I want to count the number of posts that the form sends but I seem to be running into difficulty.
Using count($_POST) returns 152. This leads me to believe that count() is ignoring empty fields.
As a result, using a formula such as (count($_POST) - 1) / 15 would return the wrong result (10.0666) and is inefficient should the number of fields change in the future.
So, does anyone have any ideas as to how to get the proper count of my posts?
My form looks like so:
<form name="scraped" action="<?php echo str_replace( '%7E', '~', $_SERVER['REQUEST_URI']); ?>" method="post">
<input type="hidden" name="OSscraper_hidden" value="N">
<?php
$inpCnt = 0;
foreach($articles as $item) {
?>
<input type="text" name="title_<?php echo $inpCnt; ?>">
<input type="text" name="name_<?php echo $inpCnt; ?>">
<input type="text" name="url_<?php echo $inpCnt; ?>">
<input type="text" name="img_<?php echo $inpCnt; ?>">
<input type="text" name="pet_<?php echo $inpCnt; ?>">
<input type="text" name="color_<?php echo $inpCnt; ?>">
<input type="text" name="value_<?php echo $inpCnt; ?>">
<input type="text" name="height_<?php echo $inpCnt; ?>">
<input type="text" name="weight_<?php echo $inpCnt; ?>">
<input type="text" name="hair_<?php echo $inpCnt; ?>">
<input type="text" name="eyes_<?php echo $inpCnt; ?>">
<input type="text" name="race_<?php echo $inpCnt; ?>">
<input type="text" name="phone_<?php echo $inpCnt; ?>">
<input type="text" name="address_<?php echo $inpCnt; ?>">
<input type="text" name="zip_<?php echo $inpCnt; ?>">
<?php
$inpCnt++;
} ?>
<input type="submit" value="Submit">
</form>
Change your form to look like:
<input type="text" name="foo[<?php echo $inpCnt; ?>][title]">
<input type="text" name="foo[<?php echo $inpCnt; ?>][name]">
<input type="text" name="foo[<?php echo $inpCnt; ?>][url]">
Then you will get:
$_POST['foo'] = [
0 => ['title' => '...', 'name' => '...', 'url' => '...'],
1 => ...,
...
];
It saves you from having to do the grouping yourself, and is easier to count or iterate over the input.
why not just count($articles)*15 and echo into a hidden input. You are using another hidden input anyway....
Try this code, and demo is here
Please just use the idea not the exact copy.
<?php
error_reporting(E_ALL ^ E_NOTICE);
//debugging
if(#$_POST['submit'] == 'Submit'){
echo '<pre>';
print_r($_POST);
echo '</pre>';
echo "<br>\n";
echo 'Number of posts = count($_POST["posts"])='.count(#$_POST['posts'])."<br>\n";
//finding number of posts that are set and not empty
$count = 0;
foreach($_POST['posts'] as $v1){
//$v is an array
foreach($v1 as $v1k=> $v1v){
if(strlen($v1v) > 0){
++$count;
$inputs[$v1k] = $v1v;
}
}
}
echo 'Count of non-empty posts = $count = '.$count."<br>\n";
echo '<pre>';
print_r($inputs);
echo '</pre>';
}
?>
<form name="scraped" action="" method="post">
<input type="hidden" name="OSscraper_hidden" value="N">
<?php
$articles =array('test');
$inpCnt = 0;
foreach($articles as $item) {
?>
<input type="text" name="posts[][title_<?php echo $inpCnt; ?>]">
<input type="text" name="posts[][name_<?php echo $inpCnt; ?>]">
<input type="text" name="posts[][url_<?php echo $inpCnt; ?>]">
<input type="text" name="posts[][img_<?php echo $inpCnt; ?>]">
<input type="text" name="posts[][pet_<?php echo $inpCnt; ?>]">
<input type="text" name="posts[][color_<?php echo $inpCnt; ?>]">
<input type="text" name="posts[][value_<?php echo $inpCnt; ?>]">
<input type="text" name="posts[][height_<?php echo $inpCnt; ?>]">
<input type="text" name="posts[][weight_<?php echo $inpCnt; ?>]">
<input type="text" name="posts[][hair_<?php echo $inpCnt; ?>]">
<input type="text" name="posts[][eyes_<?php echo $inpCnt; ?>]">
<input type="text" name="posts[][race_<?php echo $inpCnt; ?>]">
<input type="text" name="posts[][phone_<?php echo $inpCnt; ?>]">
<input type="text" name="posts[][address_<?php echo $inpCnt; ?>]">
<input type="text" name="posts[][zip_<?php echo $inpCnt; ?>]">
<?php
$inpCnt++;
} ?>
<input type="submit" value="Submit" name="submit">
</form>