Tell me more ×
WordPress Answers is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have a custom form coded in a page template, data is being sent properly.

Part of the code is this

$.ajax({
            type: "POST",
            url: "<?php bloginfo("template_directory"); ?>/saveme.php",
            data: $(form).serialize(),
            timeout: 3000,
            success: function() { alert('Success');},
            error: function() {alert('Some errors occured, please try again.');}

And in saveme.php file which is inside my theme folder, I kept this code with some static data to check if it saves or not.

   <?php
global $wpdb;

$wpdb->insert( 'mycontact', array( 'name' => 'testname', 'lastname' => 'testlastname', 'email' => 'test@test.com', 'phone' => '343434343'));
?>

The data does not save, I don't think i am doing it the right way, any help?

share|improve this question
2  
Please take a look on how to handle AJAX requests: ajax. – kaiser Apr 25 '12 at 16:43
Thanks for the link... – dips Apr 25 '12 at 17:46

closed as too localized by toscho Jul 5 '12 at 22:47

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, see the FAQ.

1 Answer

You are going about this the complete wrong way. As kaiser said, you need to read up on how to manage ajax requests. If you're interested in doing it the right way, this is pretty much the standard to which you will be held.

The reason the method you're using doesn't work is because you're trying to use a wordpress class without loading wordpress. If you are deadset on using the incorrect method, you can call wp-load.php with a require, thus loading wordpress and all of it's functions.

share|improve this answer
Yeah I knew i was doing it wrong, didn't know there was things like admin-ajax.php. Read the link given above and my code is working perfectly now.... TY – dips Apr 25 '12 at 17:49
@m0r7if3r When I started with AJAX, the post you linked was highly confusing to me. I think we got more good Q/As here that help far more. – kaiser Apr 25 '12 at 18:11
1  
@kaiser I figured I would add to what you had with that. That was the tutorial that I learned AJAX from...different strokes for different folks, right? – m0r7if3r Apr 25 '12 at 19:21

Not the answer you're looking for? Browse other questions tagged or ask your own question.