Set multiple fields of form on particular radio button click - php

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);
});

Related

hidden values are not passing in form action

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; ?>' **/>**

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.

PHP email send form - drop down list on $_POST send form

Here is my html and php code:
<!-- Form Code Start -->
<form id='contactus' action='<?php echo $formproc->GetSelfScript(); ?>' method='post' enctype="multipart/form-data" accept-charset='UTF-8'>
<fieldset >
<input type='hidden' name='submitted' id='submitted' value='1'/>
<input type='hidden' name='<?php echo $formproc->GetFormIDInputName(); ?>' value='<?php echo $formproc->GetFormIDInputValue(); ?>'/>
<input type='text' class='spmhidip' name='<?php echo $formproc->GetSpamTrapInputName(); ?>' />
<div><span class='error'><?php echo $formproc->GetErrorMessage(); ?></span></div>
<div class='container'>
Years Active (from and to):<br/>
<select name='years_active_from'>
<option value='<?php echo $formproc->SafeDisplay('NULL') ?>'>select</option>
<option value='<?php echo $formproc->SafeDisplay('from 2013') ?>'>2013</option>
<option value='<?php echo $formproc->SafeDisplay('from 2012') ?>'>2012</option>
</select>
<br/>
<span id='contactus_name_errorloc' class='error'></span>
</div>
<div class='container'>
<input type='submit' name='Submit' value='Submit' />
</div>
</fieldset>
</form>
I am trying to get the different drop down options to change the var $years_active_from; to each of the different years, 2012, 2013 and post NULL if the drop down menu is not used.
value='<?php echo $formproc->SafeDisplay('NULL') ?>' is not changing the $years_active_from, what is the correct coding for this?
Honestly, I am not 100% sure I understand what you are looking for, but my guess is that you want to have the first drop down option pre-selected on page load. For that, you would need to do add the selected attribute to the option you want to show as selected:
<option selected value='<?php echo $formproc->SafeDisplay('NULL') ?>'>select</option>

Removing the variables in url

Before I am told to look at other posts that are similar, please note that I have tried to apply them but to no avail.
I need to clear the variables in the url after a series of if statements are true. I have the following code:
<?php
$_SESSION['passlevel']='0';
if ($_SESSION['passlevel'] == '0')
{
if(isset($_GET['box_1_color']))
{
$color=$_GET['box_1_color'];
if($color == "#800080")
{
echo "you have passed step one.";
$_SESSION['passlevel'] = '1';
// add something that removes url string
}
else
{
echo "you didn't select purple.";
}
}
else echo "login with your colorlock passcode.";
}
if ($_SESSION['passlevel'] == '1')
{
if(isset($_GET['box_1_color']))
{
$color=$_GET['box_1_color'];
if($color == "#DD7500")
{
echo "you have passed step two.";
$_SESSION['passlevel']='2';
// add something that removes url string
}
else
{
echo "you didn't select orange.";
}
}
else echo "enter remaining colors.";
}
?>
This is for color dependent password that has the background of each of 10 divs change to one of 10 colors after a div is clicked on (note that some of the echoes are only there for now as a method of debugging). The information is sent to the url through multiple forms:
<form>
<div id="box1" class="box" onclick='this.parentNode.submit()'></div>
<input type='hidden' name='box_1_color' value='<?php echo $box1color ?>'/>
<input type='hidden' name='name' value='box1color'/>
</form>
<form>
<div id="box2" class="box" onclick='this.parentNode.submit()'></div>
<input type='hidden' name='box_1_color' value='<?php echo $box2color ?>'/>
<input type='hidden' name='name' value='box2color'/>
</form>
<form>
<div id="box3" class="box" onclick='this.parentNode.submit()'></div>
<input type='hidden' name='box_1_color' value='<?php echo $box3color ?>'/>
<input type='hidden' name='name' value='box3color'/>
</form>
<form>
<div id="box4" class="box" onclick='this.parentNode.submit()'></div>
<input type='hidden' name='box_1_color' value='<?php echo $box4color ?>'/>
<input type='hidden' name='name' value='box4color'/>
</form>
<form>
<div id="box5" class="box" onclick='this.parentNode.submit()'></div>
<input type='hidden' name='box_1_color' value='<?php echo $box5color ?>'/>
<input type='hidden' name='name' value='box5color'/>
</form>
<form>
<div id="box6" class="box" onclick='this.parentNode.submit()'></div>
<input type='hidden' name='box_1_color' value='<?php echo $box6color ?>'/>
<input type='hidden' name='name' value='box6color'/>
</form>
<form>
<div id="box7" class="box" onclick='this.parentNode.submit()'></div>
<input type='hidden' name='box_1_color' value='<?php echo $box7color ?>'/>
<input type='hidden' name='name' value='box7color'/>
</form>
<form>
<div id="box8" class="box" onclick='this.parentNode.submit()'></div>
<input type='hidden' name='box_1_color' value='<?php echo $box8color ?>'/>
<input type='hidden' name='name' value='box8color'/>
</form>
<form>
<div id="box9" class="box" onclick='this.parentNode.submit()'></div>
<input type='hidden' name='box_1_color' value='<?php echo $box9color ?>'/>
<input type='hidden' name='name' value='box9color'/>
</form>
<form>
<div id="box10" class="box" onclick='this.parentNode.submit()'></div>
<input type='hidden' name='box_1_color' value='<?php echo $box10color ?>'/>
<input type='hidden' name='name' value='box10color'/>
</form>
An example of the url after one of the colors (purple) is selected:
http://localhost/colorlock/index.php?box_1_color=%23800080&name=box9color
So I want to remove the ?box_1_color=%23800080&name=box9color part. How could i remove it where the code says "// add something that removes url string" so that when the next block of code is initiated it doesnt run immediately with the same color code in the url before a user can select their next color?
I hope my question is clear (i understand that it a confusing) and i hope that it is answerable. Thank you.
You need to do one/some of 3 things:
Use POST. This is a good idea but it would still be best combined with...
Redirect to the same page without the URL arguments after processing the form.
Use ajax to process the user input.
The easiest of these to integrate with your existing code is probably a combination of 1 and 2. To do this, add these lines where your comment is:
header("HTTP/1.1 303 See Other");
header("Location: http://{$_SERVER['HTTP_HOST']}{$_SERVER['PHP_SELF']}");
exit;
...and change all the <form> elements in your HTML so that they read:
<form method="post">
...and obviously change all occurrences of $_GET in your PHP code to $_POST
Could you use POST instead of GET? You use $_POST in your PHP instead of $_GET and you never have to worry about what's in the URL - it's always clean.
Try
unset($_GET['box_1_color']);
in aproriate place of your code

Categories