PHP & AJAX - Submit form doesn't work because of AJAX - php

I'm making this contact form. The site itself uses AJAX to load the content in the main window. The problem with my form is that when the user clicks on submit and the data passes validation, it loads the page to main instead to itself to reach the actual mailing script.
Is there any way to pass this??

take the action our of the form opening tag

If you're using the Prototype.js library, you could just call event.stop() on a passed event object, on form submit.

Related

With/Without Javascript form submission using ajax or normal form action

I am currently submitting a form using form action to a php script and i was going to implement ajax form submission also.
But a thought came to my mind that wouldn't it be nice to know if the client's browser has javascript enabled or disabled and submit the form accordingly as i don't want the no-javascript users to view a page that says "Enable Javascript or something"! as i have used both client and server side validations.
So, how should i know that a client has javascript and let him submit form by ajax and vice versa?
I found many QA's related to redirecting users to a page that says "Javascript disabled" and they mostly talked about tags.
I would appreciate hearing you guys and your suggestions. Thankyou :)
Use a form with a submit button.
In your javascript script put an handler on it, and call the preventDefault function to let your ajax code do the job.
So if javascript is enabled it will submit with ajax. If not it will submit it the default way .
EDIT:
Here is a jsfiddle to illustrate it: http://jsfiddle.net/CTwx2/
Basically the default behavior of a submit button is to send the data to the address indicated in the form tag.
With the handler defined in javascript & jquery, you stop this behavior and send the data by yourself through an ajax request (http://api.jquery.com/event.preventDefault/)
You will have to have 2 versions of your site and redirect accordingly using :
<noscript>
<meta http-equiv="refresh" content="0;url=noscript.html">
</noscript>
OR
Wrap your form in your <noscript> tags, and if javascript is enabled disable that form-

forms on lightboxes

I have made a simple home-made lightbox. The lightbox contains forms which allows the user to submit data. I placed a SIMPLE form on my SIMPLE lightbox, and I noticed that when I submit the form the lightbox closes automatically. Why is it doing this, and how can I keep this from happening? I'd like to submit a form on the lightbox and keep the lightbox unaffected.
this is not possible if you submit the form using php it will submit to another page so it will refresh if you want to stay on the page you will have to look into using AJAX to submit the form and get the server response
There are some good technology's out there to do this like jquery AJAX
http://api.jquery.com/jQuery.ajax/

Codeigniter submit form written in plain HTML

I'm playing for about 2 days now and can't make this out. I'm working in codeigniter 2.1.0. and I want to submit a form that is written in HTML. I don't want to use the CI form helper.
The reason is because I'm dynamically with JavaScript adding things in the form. When a user clicks an item then it's added to the form. Now when the user clicks the submit button all the items I added should be sent in a POST request, but my POST is totally empty.
Now I noticed that the POST only gets sent when I use form_input() from the CI form_helper.
Is it possible to just submit a normal plain HTML form without using the form helper?
Is it possible to just submit a normal plain HTML form without using the form helper?
Yes. The actual submit is totally independent to CI, just ensure you use the correct action URI of the form so that the correct controller action is called by the form submit post (I assume your form method is post) request.
You do not need to use the CI form_helper for the submit button. If you mock a form with these you will see that those just generate plain HTML and do nothing magically.

How to submit part of inputs from a form to another domain?

When user create a post, inside the post form, I want to provide a button. When user click the button, it will launch an iframe and submit some of the inputs of the post form. When nested form is not valid, how can I submit those inputs to the other website?
Two methods, Javascript, and PHP
Javascript:
You can use jQuery Post to do this by javascript.
Basic steps:
Use an "onsubmit" handler for the form
In the function for handling the submit, build a data array with data you want to submit and send to the second form.
Either return true (to allow the programmed submit to continue) or build a secondary submit if required.
This one allows you to build the validation you refer to client-side (i.e. in the submit handler).
PHP
Receive the data in the php form, then use CURL in the receiving PHP script to pass data as needed to the second form.

Error after form submission in JQuery Mobile

I am using JQuery Mobile and submitting a form in it. The form is submitted via post method and is sent to a php file. The form is getting submitted without any problem and submitted data is displayed in the php page. But once I refresh the page, I am getting Undefined index notice and the data is gone. The dialog window asking me for form re submission confirmation,like it normally does on refreshing is also not coming.
This is because jQuery mobile is sending the form via AJAX and not doing a normal POST request.
In jQuery Mobile, form submissions are automatically handled using
Ajax whenever possible, creating a smooth transition between the form
and the result page.
http://jquerymobile.com/demos/1.0/docs/forms/forms-sample.html

Categories