Submitting a Form using PHP and AJAX via jQuery - php

So I am using "load" functions of jQuery to use ajax on my pages.
Can anyone write a small snippet of code using jquery load (or any ajax function which you think is the best) ? What I do is make a form, onsubmit pass to js, further using GET pass values into the load function and return false; though this works I am sure this is not the best way. Also this does NOT work in Opera.

It sounds like what you're trying to do is submit a form to an existing server-side script using AJAX. If so, consider using the jQuery form plugin. It will let you very easily make an existing form submit via AJAX.
If that's not your goal, we'll need a lot more detail about what — specifically — you're trying to accomplish.

Related

Simple Ajax Update Form with $_POST and $_GET

So I'm trying to understand jQuery's .ajax function so that when I create my sites CMS I can update content on the backend asynchronously. I'm creating a simple form to start out. I pass the id of the database using php in the action href of the form. I pull the data from the form and convert it to json using the .serialize() jQuery function and then pass the action and the data into the .ajax function. On my the backend I use php to pull the $_POST and $_GET items and update the database accordingly. Everything works except that the site actually links to my backend php site... I just figure this out actually but I can post the answer for future references for people. Let me know if my answer is incorrect.
It looks like I was using type="submit" for the update input for the form. Because I was using action = "mybackendhref" in the form This caused it to link to the actually page that I wanted to use .ajax to push the data to instead. Changing to input type="button" caused everything to work smoothly.
*By "mybackendhref" I mean the actual site I want to push the data to using .ajax.

Is it possible to have a contact form on a pop up box without using ajax?

I am sorry for the stupid question, I realize that what I want to do must be extremely simple, but I can't find my way to do it.
I learned basic programing, mostly front end, and enough php to interact with databases and other basics. I can use jquery, javascrip, ajax, no problem in normal situations. But I am not fluent at all in using object-oriented php and I work on a Yii environment.
I have a contact form on the website I'm working on and it works perfectly sending the data to the database. Now I have to re-create the same form, and use it on a pop up box, but I have no idea how to do the php validation and saving to the database in that situation. I've always used Ajax and I tried it, but apparently you need special synthax with ajax on Yii that I am not familiar with.
So is there any way to have the php validation and saving being performed without ajax, (and without the form submitting that refreshes the page and closes the lightbox)?
"Popups": http://jqueryui.com/dialog/
ClientSide validation: http://jqueryvalidation.org/
PHP-Validation: Easiest Form validation library for PHP?
After everything I tried, because I don't know the Yii framework enough to use ajax in their synthax, I found a way to make my form work with simple jQ.
I have an empty onsubmit attribute on my form, that will change to "return false" if there are errors in the js validation, keeping the page from refresh and showing the errors. And if there aren't errors the form will submit the info to php validation then save to the database and all the php will be executed and the lightbox will re-open with the success message.

jquery mobile form: pass data in a form

I read on the web many things about creating form in jquery mobile and I didn't understand one thing. When I create a form and I would pass data through php, I hear jquery mobile serialize them and automatically pass over and if the form has been created using post method I can use them in an other page only using _POST array and nothing all. But I read also some people like it form with ajax use ajax to pass variable. So I didn't understand why use ajax?
The default for the jQuery Mobile framework is to submit forms via HTTP POST. Why? because then your web application has greater control over the UI when animating through pages, creating a smooth transition. Well, a better description can be found in the jqm docs here.
If you are looking to disable the default Ajax functionality, just append this to your form element:
data-ajax="false"
Hope this helps!

JSPX form submits to PHP

Is it possible to have a JSP/JSPX form to submit to a PHP file?
The PHP file will then be in charge of validation and database update. After that it will send a sort of response to the same JSP/JSPX form. Also this should be done in AJAX using jQuery.
How can I do that and what are the underlying concepts needed?
Thanks!
You don't need anything specific in your case. Just submit the form via Ajax using jQuery to the PHP page and process the result in JavaScript as well. All the code necessary for that will be client side in JavaScript and operate on the plain HTML generated by the JSP page. The only restriction/problem might be if these two pages run on different domains.

Form submission with Ajax and jquery

I have a PHP file that has an HTML form that submits via AJAX to the database. When I hit the form submit button, every PHP query updates itself. Is this how Ajax normally operates? or if I switch the parent file from PHP to HTML, will it eliminate the unwanted updating of all the PHP on the page?
jQuery ajax submits the request to a seperate php file to load data. You can choose to load only poritions of pages. $.load does this easier. Look here: http://api.jquery.com/load/
You said it submits via AJAX to the database - but have you actually programmed it to do that?
Post a sample of the AJAX code and we can check it for you.
I have a feeling you don't really understand the technology you are using. What is a 'PHP query'? You want to switch the page from PHP to HTML? Well, can you? Does the page have PHP in it or not? It wouldn't make any difference to AJAX code, but I have a feeling you don't actually have AJAX code.

Categories