I am using jquery ajax form library.... i want to change action url when i submit form
html
<div class="modal-body form"><?php echo form_open_multipart("#",array('id'=>'mng_form', 'name'=>'mng_form','class'=>'form-horizontal','role'=>'form')); ?>
javascript
var options = {replaceTarget:true, beforeSubmit: showRequest, success: showResponse};
how can i change action url using jquery form ?
use jQuery submit(). This happens prior to the actual submission, so you can change the action url.
<form id="fromID" action="action_page01.php" method="post" target="_blank" accept-charset="UTF-8" enctype="application/x-www-form-urlencoded" autocomplete="off" novalidate>
<input type="submit" value="Submit">
</form>
// jQuery
$( "#fromID" ).submit(function( event ) {
$('#fromID').attr('action', 'action_page02.php');
});
Related
I want to send this query (EA452401760IN) to https://track.aftership.com/india-post/.
After a successful submission by Form the URL will be
https://track.aftership.com/india-post/EA452401760IN
Form
<form method="POST" action="https://track.aftership.com/india-post/" target="_blank"> <input type="text" value="EA452401760IN"></input><button type="submit"> submitc</button></form>
Do I need a PHP file for this?
If yes, how do I write a php file for this problem.
Pure Javascript approach with Jquery
<input type="text" id="trackingNumber" value="EA452401760IN"></input>
<button onclick="go()">Track</button>
<script src="https://code.jquery.com/jquery-2.2.4.js"></script>
<script>
$( "button" ).on( "click", function( event ) {
window.location.href = "https://track.aftership.com/india-post/" + $('#trackingNumber').val();
});
</script>
JSBIN: https://jsbin.com/fuqovocoza/edit?html,console,output
<?php if(($_SERVER["REQUEST_METHOD"] == "POST")){
//Check that the form has been posted if it has been then redirect to the correct page
header ('Location: https://track.aftership.com/india-post/' . $_POST['query']);
}
else
{
if the form has not been submitted display the form
<form method="POST" action="https://track.aftership.com/india-post/" target="_blank"> <input type="text" name="query" value="EA452401760IN"></input><button type="submit"> submitc</button></form>
Note that I have changed the name of the input field to query.
I am trying to submit a form and open a modal with the forms post data on it.
Modal works fine but the form post is not passed through.
I have tried jquery/ajax but no luck.
<form id="frmTractors" method="post" action='process.php'>
<select id="tractor" name="tractor_number">
<options...>
</select>
<input type="submit" value="Submit" data-reveal-id="myModal" data-reveal-ajax="process.php" />
</form>
<!-- ### MODAL ### -->
<div id="myModal" class="reveal-modal" data-reveal></div>
I am running something similar on a site:
HTML
<input type="hidden" id="processURL" value="process.php">
<select id="tractor" name="tractor_number">
<options...>
</select>
JQUERY
$(function() {
$( "#tractor" ).change(function(){
var url = $('#processURL').val();
var tractor_number = $(this).val();
var postit = $.post( url, {tractor_number:tractor_number});
postit.done(function( data ) {
$('#myModal').foundation('reveal', 'open');
});
});
});
You don't need a form, just a hidden input to hold your process file URL.
My Requirement
Form Submission in New Window & Redirect Existing Page to a new page
on same click.
When I tried only Form submission is happening. Javascript function to redirect is not working.
Html
<form id="feedback.php" name="form1" method="post" action="feedback.php" target="_blank">
<input type="submit" class="button" value="SUMBIT" onclick="btntest_onclick();"/>
</form>
Javascript
<script>
function btntest_onclick()
{
window.location.href("mainpage.php");
}
</script>
Actual
But Only Form Submission is Happening in New Window. Existing Page is
not redirected.
Please tell me how to do this ?
Your HTML :
<form id="feedback.php" name="form1" method="post" action="feedback.php" target="_blank">
<input type="submit" class="button" value="SUMBIT" onClick="btntest_onclick()"/>
</form>
See onClick
Your Javascript :
function btntest_onclick()
{
setTimeout(function(){
window.location.href = "mainpage.php";
},0);
}
window.location.href is not a function.
And apparently it needs to be async to work.
JsFiddle
add onsubmit to your form.
and inside function do something like that:
function btntest_onclick() {
window.open("http:// your url");
window.location.href="/mainpage.php";
}
I have a form, which take name from form and it sends to javascript codes and show in php by Ajax. these actions are done with clicking by submit button, I need to have another button, as review in my main page. how can I address to ajax that in process.php page have "if isset(submit)" or "if isset(review)"?
I need to do different sql action when each of buttons are clicked.
how can I add another button and be able to do different action on php part in process.php page?
<script type="text/javascript">
$(document).ready(function(){
$("#myform").validate({
debug: false,
submitHandler: function(form) {
$.post('process.php', $("#myform").serialize(), function(data) {
$('#results').html(data);
});
}
});
});
</script>
<body>
<form name="myform" id="myform" action="" method="POST">
<label for="name" id="name_label">Name</label>
<input type="text" name="name" id="name" size="30" value=""/>
<br>
<input type="submit" name="submit" value="Submit">
</form>
<div id="results"><div>
</body>
process.php:
<?php
print "<br>Your name is <b>".$_POST['name']."</b> ";
?>
You just need to add a button and an onclick handler for it.
Html:
<input type="button" id="review" value="Review"/>
Js:
$("#review").click(function(){
var myData = $("#myform").serialize() + "&review=review";
$.post('process.php', myData , function(data) {
$('#results').html(data);
});
}
);
Since you have set a variable review here, you can use it to know that is call has come by clicking the review button.
Bind the event handlers to the buttons' click events instead of the form's submit event.
Use the different event handler functions to add different pieces of extra data to the data object you pass to the ajax method.
I have a form:
<form style="display: inline;" action="/player.php" method="post">
<input type="hidden" name="recname" value="'.$row['name'].'">
<input type="hidden" name="recordingdesc" value="'.$row['description'].'">
<input type="hidden" name="reclink" value="$_SESSION['customerid'].'-'.$row['timestamp'].'.wav">
<button type="submit" class="tooltip table-button ui-state-default ui-corner-all" title=" rec"><span class="ui-icon ui-icon-volume-on"></span></button>
</form>
and i want player.php to open in a modal dialog and be able to display the post information how can this be done.
Ajax is the answer. Post the form via ajax and in the callback function, (if the post was successful) you can create your dialog and load the data returned from the post. Check out Jquery's documentation on Jquery.post
First create a dialog using jquery-ui. You then need to ajax submit the form:
$("form button").click(function() {
$.post({url: '/player.php', data: $("form").serialize(),
success: function (data) {
$(div in dialog).html(data);
$("#MyDialog").dialog('open');
}
});
return false;
});