Variable to store values depending upon button clicked - php

I am trying to integrate PayU Money Payment Gateway to my website
I have three buttons. Each button holds a different value of amount.
What i exactly want is that if a user clicks button1 then 999 INR must be passed to the payU, on clicking button2 1999 should be passed to payU.
if($_POST['d1'] == '999'){ $amount = 999;}if($_POST['d1'] == '1999'){$amount = 1999;}
<input name="d1" type="button" class="btn btn-danger book-btn" data-toggle="modal" data-target="#payment" value="999">
<input name="d1" type="button" class="btn btn-danger book-btn" data-toggle="modal" data-target="#payment" value="1999">

<form method="post">
<input type="submit" name="test1" value="99" />
<input type="submit" name="test1" value="999" />
</form>
then ur $_POST['test1'] will be eather 99 or 999.
u can also use
<form method="post">
<button type="submit" name="test1" value="99" >99 Cookies ?</button>
<button type="submit" name="test1" value="999" >GIMME 999!</button>
</form>
so u can set a Custom text on the button.
CAREFULL
if u use only $_POST['test1'] and set an value. someone can manipulate the value="99" to maybe 9999999 and then ur PayU will take that value.

Related

laravel multi update row with input data

View app
I made a multi update row with js ... the button function uses put to retrieve the id of each row ...
this success but..
I want to add input form for data that is updated
I don't know what to do
<form action="{{ url('UpdateAll') }}" >
<input type="text" name="name" placeholder="test">
<input type="submit" class="btn btn-primary delete_all" value="Mass Update">
</form>
code detail
I just had a look at your code in the link provided. Is it because your ajax request PUT url is set to :
url: $(this).data('url'),
But you're not actually setting that URL on your input? eg.
This:
<input type="submit" class="btn btn-primary delete_all" value="Mass Update">
Should be:
<input type="submit" class="btn btn-primary delete_all" value="Mass Update" data-url="/your-put-url-here">

woocommerce login form submit with button instead on input

I'm wanting to use a button element rather than input on the woocommerce login form, purely for styling reasons. So rather than
<input type="submit" class="btn btn-outline-primary" name="login" value="Login" />
I want to use
<button type="submit" class="btn btn-outline-primary">Login</button>
This doesn't work though and I've no idea why.
Just found it out the button element need the value setting the same as the input i.e.
<button type="submit" class="btn btn-outline-primary" name="login" value="Login">Login</button>

capture buttons values on submission

<form method="post">
<button name="Day1" value="16">
<button name="Day2" value="32">
<input type="submit" value="Send">
</form>
I have some javascript that toggles the values of each button based on number of clicks
how do i catch values to submit as POST for backend handling
Regards,
H
Instead of incrementing the button values, increment the values of hidden inputs related to each button.
<form method="post">
<button type="button" onclick="this.nextElementSibling.value++;">Day1</button>
<input type="hidden" name="Day1" value="0">
<button type="button" onclick="this.nextElementSibling.value++;">Day2</button>
<input type="hidden" name="Day2" value="0">
<input type="submit" value="Send">
</form>
This way they can easily be submitted with your form.

PHP: Getting the value of a radio button and storing it into a database

I have never really used radio buttons before. So what I am trying to achieve is, using two radio buttons 'Public' and 'Private'. This is for the user's profile. My HTML code for the buttons is;
<div class="btn-group" data-toggle="buttons-radio">
<button type="button" class="btn btn-primary" id="privacy" name="privacy" value="0">Private</button>
<button type="button" class="btn btn-primary" id="privacy" name="privacy" value="1">Public</button>
</div>
As for the PHP, I'm not sure how to get the value and store it. Any help is appreciated!
Use a form.
<form method="get" action="yourscript.php">
<input type="radio" id="private" name="privacy" value="0">
<label for="private">Private</label>
<input type="radio" id="public" name="privacy" value="1">
<label for="public">Public</label>
<input type="submit" value="Save">
</form>
Change your buttons to input elements, which, together with the form, provide a HTML native way to send data to a script without the need for Javascript (although you can use Javascript to enhance the usability later on).
Using the label tag, you can assign a text to a radiobutton. This allows this text to be clicked as well, and it also provides better support for screen readers, because they can actually see which text belongs to the radiobutton.
An id needs to be unique, so I changed it to private and public. The ids are also used to link the label to.
The name determines by which name the value is sent to your script.
In PHP, you can use the superglobal $_GET. $_GET['privacy'] will contain '0' or '1' depending on the choice made. If the method of the form was post, you could use the superglobal $_POST instead, or you can use $_REQUEST, which contains values from either, so in that case your script doesn't care whether the values were send in the url (get) or in the chunk of invisible post data that is sent along with the request.
change type to radio and donot use the same id for morethan one element id is supposed to be unique
Also when you post the form type=button values will not be passed with the form
<div class="btn-group" data-toggle="buttons-radio">
<input type="radio" class="btn btn-primary" name="privacy" value="0"/>Private
<input type="radio" class="btn btn-primary" name="privacy" value="1"/>Public
</div>
assuming its posted on $_POST['privacy'] should contain either a 1 or a 0
also dont use an ID twice - they are supposed to be unique
You don't have form and submit button.
HTML page:
<div class="btn-group" data-toggle="buttons-radio ">
<form name="privacyForm" action="action.php" method="post">
<button type="radio" class="btn btn-primary" name="privacy" value="0">Private</button>
<button type="radio" class="btn btn-primary" name="privacy" value="1">Public</button>
<input type="submit" value="Submit">
</form>
</div>
action.php
<?php
echo $_POST['privacy']; // should be 0 or 1
?>
i have assumes that your form is something as follows.
<form name="sample" action="form_submit.php" method="POST">
<div class="btn-group" data-toggle="buttons-radio">
<input type="button" class="btn btn-primary" id="private" name="privacy" value="0">Private</input>
<label for="private">Private</label>
<input type="button" class="btn btn-primary" id="public" name="privacy" value="1">Public</input>
<label for="public">Public</label>
</div>
<input type="submit" name ="submit" value ="Submit"/>
</form>
you can use the following code inside the action (form_submit.php) to get the selected radio button value.
form_submit.php
<?php
$selected_radio = $_POST['privacy'];
print $selected_radio;
?>
make sure that you are not duplicating the IDs because they should be unique.

How do I post button value to PHP?

I want use A-Z buttons on a html page like shown below (only sample and few words)
<INPUT TYPE="BUTTON" VALUE=" A " ONCLICK="A">
<INPUT TYPE="BUTTON" VALUE=" B " ONCLICK="B">
<INPUT TYPE="BUTTON" VALUE=" C " ONCLICK="C">
<INPUT TYPE="BUTTON" VALUE=" D " ONCLICK="D">
<INPUT TYPE="BUTTON" VALUE=" E " ONCLICK="E">
<INPUT TYPE="BUTTON" VALUE=" F " ONCLICK="F">
<INPUT TYPE="BUTTON" VALUE=" G " ONCLICK="G">
<INPUT TYPE="BUTTON" VALUE=" H " ONCLICK="H">
<INPUT TYPE="BUTTON" VALUE=" I " ONCLICK="I">
<INPUT TYPE="BUTTON" VALUE=" J " ONCLICK="J">
when I click on each button I want to post respective values on button to a PHP variable.
How can I do this?
Change the type to submit and give it a name (and remove the useless onclick and flat out the 90's style uppercased tags/attributes).
<input type="submit" name="foo" value="A" />
<input type="submit" name="foo" value="B" />
...
The value will be available by $_POST['foo'] (if the parent <form> has a method="post").
Give them all a name that is the same
For example
<input type="button" value="a" name="btn" onclick="a" />
<input type="button" value="b" name="btn" onclick="b" />
Then in your php use:
$val = $_POST['btn']
Edit, as BalusC said; If you're not going to use onclick for doing any javascript (for example, sending the form) then get rid of it and use type="submit"
As Josh has stated above, you want to give each one the same name (letter, button, etc.) and all of them work. Then you want to surround all of these with a form tag:
<form name="myLetters" action="yourScript.php" method="POST">
<!-- Enter your values here with the following syntax: -->
<input type="radio" name="letter" value="A" /> A
<!-- Then add a submit value & close your form -->
<input type="submit" name="submit" value="Choose Letter!" />
</form>
Then, in the PHP script "yourScript.php" as defined by the action attribute, you can use:
$_POST['letter']
To get the value chosen.
Keep in mind that what you're getting in a POST on the server-side is a key-value pair. You have values, but where is your key? In this case, you'll want to set the name attribute of the buttons so that there's a key by which to access the value.
Additionally, in keeping with conventions, you'll want to change the type of these inputs (buttons) to submit so that they post their values to the form properly.
Also, what is your onclick doing?
Using input tag is going to leave the mark on the page. Trying button tag will show the button and also can send the value as well.
<button type="submit" value="the value you want" >Update</button>
use as:
button type="submit" value="A" name="btn"
input type="submit" value="B" name="btn"
when you will post data use:
$_REQUEST['btn'];
$restore = $this->createElement('submit', 'restore', array(
'label' => 'FILE_RESTORE',
'class' => 'restore btn btn-small btn-primary',
'attribs' => array(
'onClick' => 'restoreCheck();return false;'
)
));

Categories