On submit get button's value - php

Im with a problem..
When i click in a normal button, for example <input type="button" value="1">, he executes the form and i don't wanna do that way.
What i need?
I need, when i submit the form, he will get the value of the button with a simple POST method.
Im using this at the moment:
<form method="post">
<button name="list_items_qt" value="16">
<button name="list_items_qt" value="32">
<input type="submit" value="Send">
</form>
In summary, i just need to post the value of the button that i selected before!
Sorry for the bad english!
Thanks in advance!

using jquery
<form method="post">
<button name="list_items_qt_1" value="16" id="list_items_qt_1">
<button name="list_items_qt_2" value="32" id="list_items_qt_2">
<input type="submit" value="Send" id="submit">
</form>
<script type="text/javascript">
$(document).ready(function(){
$('#submit').click(function(){
var btn1 = $('#list_items_qt_1').val();
var btn2 = $('#list_items_qt_1').val();
alert(btn1+=+btn2);
});
});
</script>

(i'll do it for 1 button)
i'm using Jquery here.
<form method="post">
<input id="btn1" type="hidden" name="btn1" value=""/>
<input type="submit" value="Send">
</form>
<button id="list_items_qt" onClick="btn1()">
<script>
function btn1(){
$('#btn1').val('32');
}
</script>
Then on page form you can find
$_POST['btn1'];
The code is untested and is an example.

Related

Does a jquery event overwrite the submit action?

I have one form with a few submit buttons. I want to submit the form via POST to itself to process the filled out form fields... does the jquery override the submit?
$('#myButton').click('myAction') <!-- not actual code, just for the idea -->
<input type="button" type="submit" id="myButton" value="do something">
you can use something like this:
html form:
<form id="myform" method="post" name="form" action="">
<input type="text" name="name" value="">
<input type="text" name="other" value="">
<input type="submit" type="submit" name="myButton" value="do something">
</form>
js:
$('#myform').on('submit',function(e){
e.preventDefault();
var addnew='&addnew=1234';//additional data
var _data = $('#myform').serialize();
_data = _data+addnew;
console.log(_data);
});
sample jsfiddle

How do I filter a jquery form submission through a Button

I am submitting one of my forms in the following way where I needed to do some processing before it get submitted. So I can't use
Submit type button. When I changed it to Button type and submitted the form using jQuery.
My form, button set and jQuery looks like:
<form id="materialreceiveform" action="<?php echo base_url();?>index.php/Materialreceive_control/handleForm" method="post">
<td>
<input id="savebutton" type="button" value="Save" class="btn" name="btnsave" />
</td>
<td>
<input type="submit" value="Update" class="btn" name="btnupdate" />
</td>
<td><a id="reprint" target="_blank" class="btn" href="">Re-print</a>
</td>
<td>
<input type="submit" value="Clear All" class="btn" name="btnclear" />
</td>
<script>
$( "#savebutton" ).click(function() {
var myDate = moment(new Date()).format("YYYY-MM-DD HH:mm:ss");
$('[id$=hiddentime]').val(myDate);
$( "#materialreceiveform" ).submit();
});
</script>
In my PHP controller I caught this submission by using an isset before where the button type was in Submit. But now after making it Button and submitting through jQuery I cant capture the submission by isset value as follows.
public function handleForm(){
if(isset($_POST['btnsave'])){
//code goes here
}
}
Please help me to find a solution for this.

Input field not submitting on enter press

I have a problem with submitting a input field. I know I am not the first one who ask this question but I looked at the answers and they didn't work.
I have an input field and a submit button inside a div. I have the code working so that you can search on button press but I can't get submitting on enter press working.
html:
<div class="search singers" action="templates/search/search_singer.php" method="POST">
<input name="search" type="text" id="search" placeholder="Search here for singers" onkeyup="autosug();" data-file="search_singers"/><input class="button" type="submit" value="Search" onclick="search();"/>
<div id="output" class="output">
</div>
</div>
Jquery code:
var link = '#search';
//post input
$(function(){
$(link).keydown(function(e){
if (e.keyCode == 13) {
$(link).submit();
//He detect an enter press but stops then
}
});
});
I found the Jquery code on this site
And here a similar question: here
problem sovled I came at the idea that I have a function that makes the ajax request to send the data to php. I now call that function on enter press.
Your form should be like this. You forgot the form tag in your code, and that's why the form won't submit.
<div class="search singers">
<form name='your form' action="templates/search/search_singer.php" method="POST">
<input name="search" type="text" id="search" placeholder="Search here for singers" onkeyup="autosug();" data-file="search_singers"/>
<input class="button" type="submit" value="Search"/>
</form>
<div id="output" class="output">
</div>
</div>
And second thing your autonsan function like this
<script>
function autosug() {
alert("You you are here");
}
</script>
You need to use a form. So when you will press enter, then form will be submitted including input field value.
<div class="search singers">
<form action="templates/search/search_singer.php" method="POST">
<input name="search" type="text" id="search" placeholder="Search here for singers" onkeyup="autosug();" data-file="search_singers"/>
<input class="button" type="submit" value="Search" onclick="search();"/>
</form>
<div id="output" class="output">
</div>
</div>

Hiding div when is submitted and send values to PHP

<?php
echo $_POST['textvalue'];
echo $_post['radiovalue'];
?>
<div id="hidethis">
<form method="POST" action="">
<label>Tekst Value</label>
<input type="text" name="textvalue">
<label>Radio Value</label>
<input type="radio" name="radiovalue" value="autogivevalue">
<input type="submit" id="submit" name="submit" value="submit">
</div>
http://jsfiddle.net/Bjk89/2/ here is it with the jQuery.
What i try to do is to hide the <div id="hidethis"> when it's clicking submit.
I know i can make another page where i can recieve the values without the <form> section, but i want to put both in one page, make the <div id="hidethis"> hidden after submit.
So i'll be able to get echo $_POST['textvalue']; and echo $_post['radiovalue']; as results
RESULT MUST BE LIKE
A Text // This is the value you input into Tekst Value
autogivevalue // This is the value from the radio button
----- INVISIBLE -----
<form is hidden because we set it in jQuery so>
</form>
Try this. No need to use jQuery here.
<?php
if($_POST) {
echo $_POST['textvalue'];
echo $_post['radiovalue'];
} else {
?>
<form method="POST" action="">
<label>Tekst Value</label>
<input type="text" name="textvalue">
<label>Radio Value</label>
<input type="radio" name="radiovalue" value="autogivevalue">
<input type="submit" id="submit" name="submit" value="submit">
</form>
<?php
}
?>
Try adding '#' in your jquery code. Your version does not have # next to submit. Also your form is missing a closing tag here and in your JSFiddle code.
Try this:
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script>
$(document).ready(function () {
$('#submit').click(function () {
$('form').submit();
$('#hidethis').hide();
});
});
</script>
<form method='post' id="hidethis" name='form'>
<input type="text" name="textvalue">
<input type="radio" name="radiovalue" value="1">
<input type="button" id="submit" name="submit" value="submit">
</form>

get value of input to button attributed

i have input type and button, i need when insert into
<input type="text" name="bills_ID" id="bills_ID" value="2">
i will get id for this item and put it into here
BillsPrint.php?bills_ID=id
this is full code
<form id="wrapper">
<input type="text" name="bills_ID" id="bills_ID" value="2">
<input name="print" type="submit" id="print" value="print" class="css3buttonblue" onclick="window.open('BillsPrint.php?bills_ID='this.id, '_blank')" />
</form>
​
how can i put the id on this link BillsPrint.php?bills_ID=2 without refresh page
You could do this:
<form id="wrapper">
<input type="text" name="bills_ID" id="bills_ID" value="2">
<input name="print" type="submit" id="print" value="print" class="css3buttonblue" />
</form>
<script>
$(function(){
$('#print').click(function(){
window.open('BillsPrint.php?bills_ID='+$('#bills_ID').val(), '_blank')
});
});
</script>
<form id="wrapper">
<input type="text" name="bills_ID" id="bills_ID" value="2">
<input name="print" type="submit" id="print" value="print" class="css3buttonblue"
onclick="window.open('BillsPrint.php?bills_ID=' + $("#bills_ID").val(), '_blank')" />
</form>
​
Remove the onclick etc. And use get method. Use this simple code and the variables will come in URL as query string.
<form action="BillsPrint.php" method="get" id="wrapper">
<input type="text" name="bills_ID" id="bills_ID" value="2">
<input name="print" type="submit" id="print" value="print" class="css3buttonblue">
</form>
You forget to specify action of form. Use this code it will work. :)
Hope it will help.
Try this:
$(document).ready(function(){
$('form').submit(function(){
var id = $('input[name="bills_ID"]').val();
window.open('BillsPrint.php?bills_ID='+id, '_blank');
return false;
});
});
$("#print").click(function(){
var id = $("#bills_ID").val();
$.ajax({
url: 'BillsPrint.php?bills_ID=' + id,
success: function(data) {
$('.result').html(data);
alert(data); //alerts output from the BillsPrint.php page
}
});
});

Categories