I have a form with action="autosave.php". This saves as normal when enter is clicked or the submit button is pressed.
<input type="submit" id="save" value="Save Changes" />
I am also using jquery autosave, which automatically submits the form every 10 secs
$('form.checklist').autosave({interval:10000,......});
My problem is, i want to put jquery validation on the form, but i dont want it to validate for any any the above 3 processes.
I only want the validation to take place when a button is clicked.
<button class="ui-state-default ui-corner-all" onclick="location.href='submit.php'" type="button">Submit</button>
Any help would be appreciated.
Thanks in advance
<button id="submit" class="ui-state-default ui-corner-all" type="button">Submit</button>
<script>
$('#submit').click(function(e){
dovalidation (obviously this must be your validation function)
if(validation==true){
location.href='submit.php';
}else{
e.preventDefault; return false;
}
});
</script>
Related
I have Laravel 5.5 a page that has two forms but uses the same controller and method. First form is to cater for initial details but the second form is a search form. My search form works but only if you click the search button twice is there a way I could force to click once to submit that form.
View
<form name="FormSearch" id="FormSearch" method="post" action="{!! action(MyController#index',$customID) !!}">
<input type="text" name="searchDets" id="searchDets" value="" />
<input type="submit" class="btn btn-default" name="searchMe" id="searchMe" value= "Search Me"/>
</form>
Js
$('#FormSearch').click(function(e){
e.preventDefault();
$('#filterSearchForm').submit();
});
I would like my view page to submit once.
First of all, I couldn't find the element with id filterSearchForm, so, here is an edit that I made that submits the same form (i.e. FormSearch) when you click on it:
$('#FormSearch').click(function(e){
//e.preventDefault();
$('#FormSearch').trigger('submit');
});
I have used the trigger event that is fired which submits the form FormSearch when you click on the form FormSearch.
Here is it how it works:
$('#FormSearch').click(function(e) {
//e.preventDefault();
$('#FormSearch').trigger('submit');
});
$("#FormSearch").submit(function(e){
e.preventDefault();
alert('submitted');
});
#FormSearch{
background: black;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<form name="FormSearch" id="FormSearch" method="post" action="{!! action(MyController#index',$customID) !!}">
<input type="text" name="searchDets" id="searchDets" value="" />
<input type="submit" class="btn btn-default" name="searchMe" id="searchMe" value="Search Me" />
</form>
<p>
** Click anywhere on the black area.
</p>
I hope this was helpful.
I have faced the same issue and it was due to js version . So please check your jquery.validate's version.
You can get more information here submit button twice click issue
I am currently using PHP form element : the submit button as
<input type="submit" name="submit" value"set"/>
and the form was being submitted like :
if(isset($_POST['submit']) && $_POST['submit'] == 'set'){..do something..}
Now in bootstrap a submit button is usually written as
<button type="submit" class="btn btn-success btn-sm">set</button>
My question is how to submit this form data since I cannot do it like the previous way. It might be a noob question but I am new to bootstrap. Any suggestions would be of great help.
This has little to do with bootstrap. You can set a name and value attribute on a button as well as an input[submit].
<button type="submit" class="btn btn-success btn-sm" name="submit" value="set">
set
</button>
I have a markup like this
<button type="button" class="btn btn-success pull-right add-customer" name="add-new-customer">Add New Cusomer</button>
so when the add new customer will be clicked it should show some message. like this
<?php
if(isset($_POST['add-new-customer'])) {
echo 'Set';
}
?>
but it is not doing isset for the button. So can somone tell me how to solve this using php. I have not used any kind of form. I want to simply check the button is set and show some message. Any help will be really appreciable. Thanks
This is because if you click a button within a form it doesnt actually submit the form.
Try using
<input type="submit" value="Submit" name="add-new-customer" />
EDIT:
Having just seen your comment, you must wrap the elements in a
<form>
Button elements aren't linked to anything in HTML. PHP won't detect if you click on a button.
You have to use a form or an AJAX query in order to populate the $_POST variable.
<form action="" method="post">
<input type="submit" value="Submit" name="add-new-customer" />
</form>
button type must be submit like type="submit" not type="button"
<button type="submit" class="btn btn-success pull-right add-customer" name="add-new-customer">Add New Cusomer</button>
also use form tag
i got following code i want to know which button pressed then pass the value to input box.
<button type="button" name="buttonpassvalue" value="1" onclick="">Value1</button>
<button type="button" name="buttonpassvalue1" value="2" onclick="">value 2 </button>
<?php
if buttonpassvalue pressed then add the buttonpassvalue value
<input type="text" name="value">
else
add value of buttonpassvalue1
?>
i am tried to solve but stock here.
please help me
thanks
The best way to do this is with Javascript.
As PHP is a server side language, it requires you to send some information to the server, meaning you would have to submit the form, and reload the page with the details of the request from the user.
With a javascript library like jQuery you can do something like the following.
<button class="some-button" value="1">Button 1</button>
<button class="some-button" value="2">Button 2</button>
<input type="hidden" name="buttonValue" class="button-value-hidden" />
<script>
$(document).ready(function(){
$('button.some-button').on('click', function(){
$('input.button-value-hidden').val($(this).val());
});
});
</script>
Now $_GET['buttonValue'] will contain your button value when the form is submitted.
Make sure you are including the jQuery library!
How do I get the "state" of buttons which have been pressed in bootstrap?
I.e. I am using this code, which makes buttons 'toggle' like a checkbox:
<div class="btn-group" data-toggle="buttons-checkbox">
<button type="button" class="btn btn-primary">Left</button>
<button type="button" class="btn btn-primary">Middle</button>
<button type="button" class="btn btn-primary">Right</button>
</div>
Which is from the bootstrap manual here.
But which I then click a submit button - there is no data contained in the $_POST. How do I know which button(s) have been selected?
I have tried adding 'value="1" name="1"' etc aswell to the buttons - but still nothing.
Edit: Here is the full solution, which I was able to create using the help from Felix below.
<form method="post" action="" id="mform" class="form-horizontal">
<div class="btn-group" data-toggle="buttons-checkbox">
<button type="button" name="left" value="1" class="btn btn-primary">Left</button>
<button type="button" name="middle" value="1" class="btn btn-primary">Middle</button>
<button type="button" name="right" value="1" class="btn btn-primary">Right</button>
</div>
<button type="submit" class="btn">Submit</button>
</form>
<script>
$('#mform').submit(function() {
$('#mform .btn.active').each(function() {
var input = document.createElement("input");
input.setAttribute("type", "hidden");
input.setAttribute("name", this.name);
input.setAttribute("value", this.value);
document.getElementById("mform").appendChild(input);
});
});
</script>
Buttons that are "selected" will have the active class attached to them. You can then use jQuery to only select those buttons. Since buttons are form elements, they can have name and value attributes and it's probably best to make use of those.
Example:
var data = {};
$('#myButtonGroup .btn.active').each(function() {
data[this.name] = this.value;
});
To send the data to the server, you'd could use Ajax and set the data manually / merge it with other form data (if it exists).
You could also try to mirror the values into hidden form elements on submit if you want to use "traditional" form submission (see Change form values after submit button pressed).