Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Trying to use jQuery form plugin in wordpress site to upload files.

HTML markup:

<form id="myForm" action="process.php" method="POST" enctype="multipart/form-data">


<input type="file" value="" name="file_upload"  class="file_upload"/> <br></br>

<input type="submit" value="Submit" class="btn_submit" name="btn_submit" />


</form>

and the JS snippet :

<script type="text/javascript"> 

        $(document).ready(function() { 

            $('#myForm').ajaxForm(function() { 
                alert("Thank you for your comment!"); 
            }); 
        }); 
    </script> 

The form processes its element values in process.php which is a non-template file. As a result Wordpress codex functions are not available in that page . So what I need to do is to use the jQuery form plugin's ajax submission in the wordpressian way.

How to implement that ?


share|improve this question
add comment

1 Answer 1

If you want to use the WordPress functions in your process.php file then there is a way for you.

simply put these two lines of code at the top of your process.php file

$blogheader = explode("wp-content",$_SERVER["SCRIPT_FILENAME"]);
include $blogheader[0]."wp-blog-header.php";

Now you can use the WordPress functions in your file and do what you want. Will that work for you?

share|improve this answer
    
I also need to add these lines include_once ABSPATH . 'wp-admin/includes/media.php'; include_once ABSPATH . 'wp-admin/includes/file.php'; include_once ABSPATH . 'wp-admin/includes/image.php'; to get other functions such as wp_handle_upload() to work. And this not the recommended wordpressian way However, I think. –  Istiaque Ahmed Jan 5 at 12:11
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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