hidden values are not passing in form action - php

When I save this form all type="text" fields are working fine. But hidden field values are not passing.
If I changed from "hidden" to "text" it works fine. I don't know why I am getting this problem.
<form action="../model/meter-reading-model" method="POST">
<input type='hidden' name='hdnTakenDate' id='hdnTakenDate' value='<?php echo $TakenDate; ?>' />
<input type='hidden' name='hdnSiteHeadDbKey' id='hdnSiteHeadDbKey' value='<?php echo $SiteHeadDbKey; ?>' />
<button type='submit' name="btnSaveData" id="btnSaveData" class='btn btn-lg btn-danger'> Save Reading Data </button>
</form>
Receiving in another page
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
if(isset($SaveData)){
$TakenDate = mysqli_real_escape_string($conn, $_POST['hdnTakenDate']);
$SiteHeadDbKey = mysqli_real_escape_string($conn, $_POST['hdnSiteHeadDbKey']);
}
}

It solved for me when i change this
<input type='hidden' name='hdnTakenDate' id='hdnTakenDate' value='<?php echo $TakenDate; ?>' />
<input type='hidden' name='hdnSiteHeadDbKey' id='hdnSiteHeadDbKey' value='<?php echo $SiteHeadDbKey; ?>' />
to this
<input type='hidden' name='hdnTakenDate' id='hdnTakenDate' value='<?php echo $TakenDate; ?>' **/>**
<input type='hidden' name='hdnSiteHeadDbKey' id='hdnSiteHeadDbKey' value='<?php echo $SiteHeadDbKey; ?>' **/>**

Related

Passed data value will stay on page after submitting form

I have a 2 pages and I want to stay the data value that i passed from page1.php
page1.php
<form action='page2.php' method='POST' class='form-inline'>
<input type='submit' class='btn btn-info' value='Manage Child'
name='manage'>;
<input type='hidden' value='<?php echo $id;?>' name='id'>
</form>
page2.php
$id = $_POST['id'];
if(isset($_POST['passinfo'])){
$studentid=$_POST['studid'];
}else{
$studentid='';
}
<form>
<input type='hidden' name='parentid' value='<?php echo $id;?>'
<input type='hidden' name='studentid' value='<?php echo $studentid;?>'
<input type='text' name='studentname'>
</form>
<form action='' method='POST'>
<input type='hidden' name=studid value='<?php echo $stud_id?'>
<input type='submit' class='btn btn-primary' value='Assign' name='passinfo'>
</form>
my problem is if I click the 'passinfo' button and submit the 'studid' value the '$parentid' value will be unindentified variable. My question is how do I maintain the value of the '$parentid' even if I submit a form
You must place hidden inputs in one form:
<form action='' method='POST'>
<input type="hidden" name="parentid" value='<?=$id?>'>
<input type="hidden" name="studentid" value='<?=$studentid?>'>
<input type='hidden' name=studid value='<?=$stud_id?'>
<input type='submit' class='btn btn-primary' value='Assign' name='passinfo'>
</form>

Sending php in a name value which is an html form

<form action='itemEdit.php' method='post' />
<input type='hidden' name='<?php $row['id'];?>' value='' />
<input type='submit' name='submit' value='Edit'
</form>
is it possible to send this php script to the 'itemEdit.php' page and put the row output into a php variable? I've tried this and haven't had any success. I can't figure this out by just using mySql. Thanks
You should do the following..
<form action='itemEdit.php' method='post' />
<input type='hidden' name="YouFieldNameHERE" value="<?php $row['id'];?>" />
<input type='submit' name='submit' value='Edit'/>
</form>
Then in your itemEdit.php you can access it like ...
$fieldValue = $_POST['YouFieldNameHERE'];
You need to use the name attribute to indicate what value you are passing and either use echo or a shorttag or no value will be in the name attribute:
<input type='hidden' name='id' value='<?= htmlentities($row['id']) ?>'>
<input type='hidden' name='id' value='<?php echo htmlentities($row['id']) ?>'>
If you are naming your attribute with the id, it would look like this:
<input type='hidden' name='<?= htmlentities($row['id']) ?>' value=''>
<input type='hidden' name='<?php echo htmlentities($row['id']) ?>' value=''>
The htmlentities helps protect against XSS.
Also be sure to close the submit tag.
If it is HTML5, you don't need the />
two thing one use value for not name for input value.
another use echo or <?= to print value in input
instead of this
<input type='hidden' name='<?php $row['id'];?>' value='' />
use
<input type='hidden' name='inputname' value='<?php echo $row['id'];?>' />
to get value in next page
echo $_POST['inputname'];

paypal get multiple item_number

I have created a paypal cart form which add multiple product for payment:
<?php
$i=1;
foreach($p_result as $prod):
?>
<div class="image">
<img src="images/<?php $result = $SimpleUsers->prod($prod['pid']); foreach($result as $row):echo $row['product_img'];?>" alt="" width="97px" height="110px"/>
</div>
<div class="name">
<?php echo $row['product'].' -- ';echo $prod['month']." mesi";?>
</div>
<div class="price">
<?php echo "N. licenze:".$prod['quantity'];?>
</div>
<div class="price">
Price: <?php echo $row['price']*$prod['month']*$prod['quantity'];?>0€
</div>
<div class="btn">
<form action='<?php echo $paypal_url; ?>' method='post' name='cart'>
<input type='hidden' name='business' value='<?php echo $paypal_id;?>'>
<input type='hidden' name='cmd' value='_cart'>
<input type="hidden" name="upload" value="1">
<input type="hidden" name="quantity_<?php echo $i; ?>" value="<?php echo $prod['quantity']; ?>">
<input type='hidden' name='item_name_<?php echo $i; ?>' value='<?php echo $row['product'];?>'>
<input type='hidden' name='item_number_<?php echo $i; ?>' value='<?php echo $prod['pid'];?>'>
<input type='hidden' name='amount_<?php echo $i; ?>' value='<?php echo $row['price']*$prod['month'];endforeach; ?>'>
<?php $i++; ?>
<input type='hidden' name='no_shipping' value='1'>
<input type='hidden' name='currency_code' value='EUR'>
<input type='hidden' name='handling' value='0'>
<input type='hidden' name='cancel_return' value='http://www.example.com/paypal/cancel.php'>
<input type='hidden' name='return' value='http://www.example.com/paypal/success.php'>
<?php
endforeach;
?>
But on success.php page, I get all the variables, except item_number which is void
Success.php(part where I get variables)
$uid = $_SESSION['uid'];
$username=$_SESSION['username'];
$item_no = $_GET['item_number'];
$item_transaction = $_GET['tx'];
$item_price = $_GET['amt'];
$item_currency = $_GET['cc'];
How I can get item_number variable?
You have to use the array in input name to get the multiple values
<input type='hidden' name='item_number[]' value='<?php echo $prod['pid'];?>'>
You can get the values using
print_r($_GET['item_number']) //You will get a array of item number
Well when you're naming it in the form you're usinh
'item_number_<?php echo $i; ?>' (which can look like "item_number_3")
but when you try to call it your using $_GET['item_number']
you would have to call $_GET['item_number_2'] with the way you're naming it.
Hope that shed some light on it, for you.
edit ++++++++++++++++++++++++++++
If I were you I would change
<input type='hidden' name='item_number_<?php echo $i; ?>' value='<?php echo $prod['pid'];?>'>
to
<input type='hidden' name='item_number' value='<?php echo $prod['pid'];?>'>
and you call to $_GET['item_number'] should work fine.

how to get multiple products from cart to paypal payment

I want to get multiple products on paypal payment page. I am only getting a single first product at the moment. can someone help me out where I am wrong. below is my code..i searched google and found two more things to be changed. i.e. _xclick to _cart and one more <input type='hidden' value='1' name='upload'/>
Now I am getting your cart is empty.
$query = mysql_query("SELECT * FROM temporderdetails WHERE omid = '$ordermaster_id' " ) or die(mysql_error());
while($row = mysql_fetch_array($query)){
$productid = $row['productid'];
$quantity = $row['qty'];
$price = $row['price'];
$subtotal = $row['subtotal'];
$query1 = mysql_query("select product_name from products where product_id = '$productid'" ) or die(mysql_error());
while($row1 = mysql_fetch_array($query1)){
$product = $row1['product_name'];
<form action='<?php echo $payment_url ;?>' method='post'>
<input type="hidden" name="cmd" value="_cart">
<input type='hidden' name='business' value='<?php echo $payment_email;?>'>
<input type='hidden' name='item_name' value='<?php echo $product;?>'>
<input type='hidden' name='upload' value='1'>
<input type='hidden' name='quantity' value='<?php echo $quantity; ?>'>
<input type='hidden' name='amount' value='<?php echo $grandtotal;?>'>
<input type='hidden' name='currency_code' value='USD'>
<input type='hidden' name='return' value='<?php echo $payment_success;?>'>
<input type='hidden' name='cancel_return' value='<?php echo $payment_failed;?>'>
}
}
In case of multiple products you have to use the following variables for each product:
amount_x
item_name_x
where x is the product number (starting from 1). So, what you have to do is something like this:
<form action='<?php echo $payment_url ;?>' method='post'>
<input type="hidden" name="cmd" value="_cart">
<input type='hidden' name='business' value='<?php echo $payment_email;?>'>
<input type='hidden' name='upload' value='1'>
<input type='hidden' name='currency_code' value='USD'>
<input type='hidden' name='return' value='<?php echo $payment_success;?>'>
<input type='hidden' name='cancel_return' value='<?php echo $payment_failed;?>'>
In here you can get all your products (your "while" statement), use a counter variable, and then:
<input type='hidden' name='amount_<?php echo $counter;?>' value='<?php $price ?>'>
<input type='hidden' name='item_name_<?php echo $counter;?>' value='<?php echo $product?>'>
<?php $counter++ ?>
Finally close the form
</form>

Set multiple fields of form on particular radio button click

I'm developing a web app in which I've to integrate a Paypal account. There are many radio buttons on the page that represents various credits and it's price and like wise. My Problem is, I want some functionality through which I can set various other fields of form on one of the radio button click. And those values are different for every radio button.
<form action='<?php echo $paypal_url; ?>' method='post' name='form'>
<div class="crea_paka_title">Creadit Pakages</div>
<?php
foreach($admin_credits as $credits){
?>
<div class="creadit_fields">
<span class="for_radio">
<input type="radio" name="1" id="<?php echo $credits['AdminCredit']['id'];?>" value="" />
</span>
<span class="for_creadit">
<?php echo $credits['AdminCredit']['tx_total_credits']; ?> Credits
</span>
<span class="for_cre_value">
$<?php echo $credits['AdminCredit']['nu_total_price']; ?>
</span>
</div>
<div style="clear:both;"></div>
<?php
}
?>
<input type='hidden' name='business' value='<?php echo $paypal_id; ?>'>
<input type='hidden' name='cmd' value='_xclick'>
<input type='hidden' name='item_name' value='<?php echo $credits['AdminCredit']['tx_total_credits'];?> Credits'>
<input type='hidden' name='item_number' value='<?php echo $credits['AdminCredit']['id'];?>'>
<input type='hidden' name='amount' value='<?php echo $credits['AdminCredit']['nu_total_price'];?>'>
<input type='hidden' name='no_shipping' value='1'>
<input type='hidden' name='currency_code' value='USD'>
Like as above in my code I've to change the values of inputs on radio button click. Any suggestions are appreciated.
jQuery will do it:
$("#rbID").click(finction(){
$("otherRB").attr("checked",true);
});

Categories