I'm submitting a form in JavaScript inside the onclick event of an image, the problem is how to know in PHP that i'm coming from the image submission?
if(isset(??))
{
//submission code
}
Note: the form action is $PHP_MYSELF
You could perhaps place a hidden field in your form and test on that.
Since you're submitting a form, why not check for a form submit in PHP using:
if(isset($_POST))
{
//do code
}
Related
i made a plugin to upload a image file which is already exist in database.image of plugin given below.
This modal have one <form> tag.
Now i wants to implement this code to my form.so Form Have Already one form So how can i manage Both Form.
if user upload file than above form will skip and this form is submitted and above data will be lost.
My Form is like this
remember you should provide your work
$("#html_form_id").submit(function() {
$( "#modelForm_id" ).submit();
return false;
});
Description is ambiguous not clear if you want to submit first form, second form or both.
I have an onclick event on all forms on the page:
$('form[method="post"]').click(function() {
if($('textarea[name="serialized_data"]').length > 0) {
alert("serialize_data already exists in this form!");
return false;
}
var data=$(this).serialize();
$(this).append('<textarea name="serialized_data">'+(data)+'</textarea>');
});
If you press a submitbutton and then on the target page press back in the browser, then this alert comes up.
But this solution stops on all forms.
How can I apply the alert only on the form that submitbutton was already pressed?
If you wonder why I input all data in that textarea, that is another question: compact all form-data with javascript
You're selecting all textareas anywhere, instead of those within the clicked form. Try this:
$('textarea[name="serialized_data"]', this)
That restricts the selector to the context of this, which is the form.
I currently have a form which users can traditionally click on a submit button to save. The form action goes to a page called formProcess.php, which contains a meta-redirect that will save everything then redirect the user back to the form.
I have been requested to add a new feature to a hyperlink on the form page which will automatically save the form before following the hyperlink to a different page. I've currently got some simple jQuery connected to the hyperlink which submits the form like so:
$('#hyperlink').click(function() {
$(this).closest("#save_form").submit();
});
This works and submits the form, but of course formProcess.php has a meta-redirect in it which will take the user back to the form page which I don't want.
I figure if I could pass some extra parameter in the Javascript form submission, like submit('redirect=link'); then I could add something like this to formProcess.php:
if ($_POST['redirect'] == 'link') {
// Redirect 1
} else {
// Redirect 2
}
Is this possible? I can't seem to find any information on being able to pass any extra parameters using submit(); If not, what would you suggest is the best way to tackle my problem?
You can append a temporary field to your form.
$('#hyperlink').click(function() {
$(this).closest("#save_form").append('<input type="hidden" name="redirect" value="link" />');
$(this).closest("#save_form").submit();
});
In your form you can use hidden input type.
Ex.
<input type="hidden" name="redirect" value="link"/>
so when form is submit your hidden field value also to be submit with other parameter.
in your php you can simply do as below:
if ($_POST['redirect'] == "link") {
// Redirect 1
} else {
// Redirect 2
}
You can either use ajax to submit your form and upon success then redirect to the url you want.Without using ajax you could add a hidden field in your form and change it's value.Then server side you ll be able to check the value of you hidden field and act accordingly.
I know that it probably isn't possible to submit a form from one button to 2 various locations so I was wondering if someone knew of a solution.
When I click submit on a form I have the following form tag:
<FORM ACTION="http:site.com/servlets/RequestServlet" method="post">
But I want the form to have 2 action parameters. This way as soon as a user fills this form out, submits the form, the form is submitted to a SERVER AND a PHP script that will pull out the parameters submitted by the the form and email the user details about their form submission such as request ID etc.
Over here the Servlet is submitted to so that a record can be made in the network but an email is required to be sent to a user after form submission in-case they need to reference later on to a rep about their request id for further assistance.
How can I achieve the submission to a PHP script in addition to the submission to the Servlet that's already occurring?
NOTE: I cannot modify the Servlet in any way as it does not belong to me. All I want to do as add the email function for a user to later reference their ticket id.
Set a javascript onclick parameter for the submit button. So it will post to the action you set, but also run a function such as:
function secondSubmit() {
url = "myphpscript.php";
data = { someData: "data", someOtherData: 2 };
$.post(url, data, function(returnedData) {
// can do something on return if you'd like here
});
}
someData and someOtherData will show up in PHP as $_POST["someData"] and $_POST["someOtherData"]. So basically, you will have the form submit to the first URL via the HTML form, and have the second form submitted via jQuery with this function. Alternatively, you can do both submissions in this function and have the form have no action.
For more info, see here: http://api.jquery.com/jQuery.post/
I have a form that is shown inside a Colorbox. When users click submit there is some validation done (checking if an entered field already exists in my database) if it does a message is shown and user is prompted to enter a new value. However when this happens the form is not shown the second time inside the Colorbox window, instead it appears on a blank page.
the form is posted to PHP_SELF, how can i change this to show in PHP_SELF (in the current Colorbox)?
cheers
I know this is aside from what you are asking, but
What if you used jquery's submit() and post() instead of PHP_SELF to pass form data to an external php class and handle displaying the return data? If the data is acceptable, you can call $.colorbox.close() manually. If data is unacceptable you can display a message to the user describing the problem.
$('myform').submit(function(){
//validate the data with javascript
//send the data to your function with post
$.post('http://url/to/your/function',{a:first_input,b:second_input},
function(return_data){
if(return_data == 'success'){
$.colorbox.close();
}else{
//display your error message here
}
,html
);
});