I have a simple php form and it's action link is another php file/page.
I am trying to show a popup before sending the PHP form to it's action page.
I tried onsubmit , onclick but nothing is working.
this is my form
<form method="post" action="/actions.php/" data-js-validate="true" data-js-highlight-state-msg="true" data-js-show-valid-msg="true">
<input type="text" name="amount[]" placeholder="Amount" class="inputChangeVal" data-js-input-type="number" />
<button class="btn" type="submit" name="confirm" >Pay Now</button>
</form>
this form send the amount value to the actions.php
but before sending this I want to show a poup that shows 'Edit' , 'Continue' with this message "Your about to make a online payment. Click 'Edit' to review the data before proceeding or click 'Continue' to confirm the details for payment."
if user clicks 'Edit' form submission should be stopped and popup should be closed.
if user clicks 'Continue' form should submit the data to the action.php
I tried:
<button class="btn" type="submit" name="confirm" onclick="return foo();">Pay Now</button>
<script>
jQuery( document ).ready(function() {
function foo()
{
alert("Submit button clicked!");
return true;
}
});
</script>
this does not work..
I tried
<form method="post" action="/actions.php/" data-js-validate="true" data-js-highlight-state-msg="true" data-js-show-valid-msg="true" onsubmit="return foo()">
also not working..
Both just go to the actions.php
how can I show the popup and then send the form based on the selection?
Basically the best way I see to achieve this is to use the bootstrap modal, so what you need to do is to stop the form from submission when the button is clicked, then show the bootstrap modal using jquery , then you form will have two buttons one the edit which will then have the data-dismiss="modal" which will just close the modal and show back the form, then the continue button when clicked you will just force the form to submit using jquery as well with $('form').submit(); this tells the form to submit to the form action.
$('document').ready(function(){
$('#payBtn').on('click',function(e){
e.preventDefault();
$('#myModal').modal('toggle');
});
$('#continuebtn').on('click',function(){
$('form').submit();
});
});
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<form method="post" action="/actions.php/" data-js-validate="true" data-js-highlight-state-msg="true" data-js-show-valid-msg="true">
<input type="text" name="amount[]" placeholder="Amount" class="inputChangeVal" data-js-input-type="number" />
<button class="btn" type="submit" name="confirm" id="payBtn">Pay Now</button>
</form>
<!-- Modal -->
<div class="modal fade" id="myModal" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Proccess Payment</h4>
</div>
<div class="modal-body">
"Your about to make a online payment. Click 'Edit' to review the data before proceeding or click 'Continue' to confirm the details for payment."
<button class="btn btn-default" data-dismiss="modal">Edit</button>
<button class="btn btn-primary" id="continuebtn">Continue</button>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
You could achieve your goal with using javascript alerts. Your php will not call the other php directly, but a javascript method, which then shows an alert with 2 buttons. Look into https://www.w3schools.com/js/js_popup.asp as it probably describes it better than me.
Best wishes,
Essi
Please check this its working now. You don't need document.ready just simply add to js file or in tag!
function foo()
{
if(confirm('You\'re about to make a online payment. Click "Cancel" to review the data before proceeding or click "Ok" to confirm the details for payment.'))
{
alert("confirm ok");
document.getElementById("form_id").submit();// Form submission
}
else {
return false;
}
}
<form method="post" id="form_id" action="/actions.php/" data-js-validate="true" data-js-highlight-state-msg="true" data-js-show-valid-msg="true">
<input type="text" name="amount[]" placeholder="Amount" class="inputChangeVal" data-js-input-type="number" />
<button class="btn" type="submit" name="confirm" onclick="foo();" >Pay Now</button>
</form>
Related
I have a sample code below which consists of a simple bootstrap modal for delete confirmation message. The code is working perfectly,while i give input type= button , but once i give type=submit it does not submit form and dialog modal dont open. Here is my code.
<?php
if(isset($_POST['submit'])){
echo $_POST['first_name'];
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet"/>
<script type="text/javasript">
$('.submit').click(function(e){
e.preventDefault();
});
</script>
<title>JS Bin</title>
</head>
<body>
<form action="" method="post">
<input type="text" name="first_name" id="first_name">
<!--<button type="button" class="btn btn-default" data-toggle="modal" data-target="#confirm-submit">Submit</button>-->
<button type="submit" name="submit" class="btn btn-default" data-toggle="modal" data-target="#confirm-submit">Submit</button>
<div class="modal fade" id="confirm-submit" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h2 class="modal-title">Confirm</h2>
</div>
<div class="modal-body">
<p>Are you sure you want to submit?</p>
</div>
<div class="modal-footer">
<button type="submit" class="btn btn-success">Yes, Submit</button>
<button type="submit" name="" class="btn btn-danger" data-dismiss="modal">Cancel</button>
</div>
</div>
</div>
</div>
</form>
</body>
</html>
Please help me..
In the modal footer [SOLVED]
<div class="modal-footer">
<button type="submit" class="btn btn-success">Yes, Submit</button>
<button type="submit" name="submit" class="btn btn-danger" data-dismiss="modal">Cancel</button>
</div>
As your first button on the form,
<button type="submit" name="submit" class="btn btn-default" data-toggle="modal" data-target="#confirm-submit">Submit</button>
opens the modal but doesn't submit the form as you have used e.preventDefault(); on that button click,
After modal opens once you click on 'Yes, Submit' it will submit the form again but this time isset($_POST['submit']) will be blank as the 'Yes, Submit' button doesn't have name.
Just add name to that button and it will work.
Final code will look like as above [SOLVED]
<script type="text/javascript">
$(document).on('submit', 'form', function(e){
e.preventDefault();
});
</script>
You (first) have a typo in the script tag (should be javascript).
Then you have to listen to the submit of the form to prevent it. You listen to a click of an element with the class submit which doesn't exist.
I am using modal window to post the the values to the controller .
<form action="<?php echo base_url();?>Users/sms/" id="form" method="post" class="form-horizontal" enctype="multipart/form-data">
buttons
<button type="button" id="custom" class="btn btn-warning" disabled="disabled">
Custom Msg
</button>
<button type="button" id="initial" class="btn btn-primary">
Initial
</button>
no response in my screen. i cannot able find the error. in popup window showing nothing. when i click the button no response. suggestion please
Type should be submit instead of button to post the data.
I am trying to send data on button on modal using jQuery, first time it is working well but when I click second time it execute twice and for third time it execute 3 times, I want to execute that button only once, what is wrong exactly?
my modal
`<div id="Modal" class="modal fade" role="dialog">
<div class="modal-dialog">
<div class="modal-content modal-sm">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">product</h4>
</div>
<div class="modal-body">
<label>Quantity</label>
<input type="text" class="form-control" id="qty" value="">
<label>Note:</label>
<input type="text" class="form-control" id="note" value="">
</div>
<div class="modal-footer">
<button id="" type="button" class="btn btn-primary mdismiss" data-dismiss="modal">Add</button>
</div>
</div>
</div>
</div>`
my jQuery :
`
$('#btnbtn').click(function(){
$('#Modal').modal('show');
$('#addbutton').click(function(){
alert();
});
});`
You are adding click handler multiple time whenever you are clicking on #btnbtn button. No need of attaching click event handler to #addbutton on each click. Change your code like below:
$('#btnbtn').click(function(){
$('#Modal').modal('show');
});
$('#addbutton').click(function(){
alert();
});
Instead of using .click() when binding the button you can use one(). It will only execute once.
$('#btnbtn').click(function(){
$('#Modal').modal('show');
$('#addbutton').one('click', function(){
alert();
});
});`
I want to call modal('show') event with php code. How can I do this? I tried the following:
if(isset($_POST['Edit'])){
echo "<script> $('#Modal').modal('show') </script>";}
I run this code, but echo "<script> $('#Modal').modal('show') </script>"; doesnt work. How can I show modal when image input is clicked? I don't want to call with image onlick.
Input:
<input type="image" src="image.png" name="Edit" value="Edit" alt="Edit" />
Modal:
<div class="modal hide fade" id="Modal" >
<form method="post">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" style="margin-top:-10px">×</button>
</div>
<div class="modal-body">
<textarea id="text" name="text">Test</textarea>
</div>
<div class="modal-footer">
</div>
</form>
</div>
Set the document.ready function as shown below:
echo "<script type='text/javascript'>
$(document).ready(function(){
$('#Modal').modal('show');
});
</script>";
On a side note, this work around is also great if you have a modal login form and need to alert the user on submit (or $_POST) for any submission errors in a seperate modal.
You can use jquery fadeIn function to show model
$('#Modal').modal('show');
Change to
$('#Modal').fadeIn('show');
Hope it will help you.
Please help me with this :
I have a form with a submit button . Now i want to open a modal window on click event of this button . In the modal i need to show a text box for inserting something in DB with 2 buttons : Cancel and Push . On click of push i want data to be inserted in the db and form to be submitted !!!
Somehow i am unable to achieve this
<form action="post_data.php" method="post">
<!-- some elements -->
<input type ="submit" value = "Push data">
</form>
I am using bootstrap-modal.js
But the problem i am facing is my form points to x.php and now if I need to open a bootstrap model then i need to provide attributes : href="mymodal_id" and data-toggle="modal" for my submit button . If i do that my page does absolutely nothing :( :(
Please Help
Any help wil be appreciated . Thanks in advance
Use an <a> to trigger your modal:
Launch demo modal
And then put your submit and cancel button inside that modal:
<div class="modal" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h3 id="myModalLabel">Pushing to DB</h3>
</div>
<div class="modal-body">
<p>You are going to push data</p>
</div>
<div class="modal-footer">
<button type="button" class="btn" data-dismiss="modal" aria-hidden="true">Cancel</button>
<button type="submit" class="btn btn-primary" value="Push data">Push data</button>
</div>
</div>