0

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 ?


1 Answer 1

-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?

1
  • 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. Commented Jan 5, 2014 at 12:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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