Wednesday 1 March 2017

WordPress AJAX forms with Symfony Components


← Back to All Posts Today I was making a controller in WordPress to process a form which is submitted as an AJAX request.
When it comes to making forms and handling them, WordPress is pretty open – you can do pretty much anything you like. This is great, but there is no standard way of doing things, and it can get a little messy – particularly when using the default admin_ajax features in WordPress. I wanted to make this more consistent, and reduce the amount of code I was writing.
I love Symfony, and one of the best things about Symfony is that most of it’s components are portable, which means I can use them within my WordPress install, for all of my forms (whether they are AJAX or not).
To make this process even easier, I’m using Composer to manage my dependancies in my WordPress install, so I installed these using Composer.
If you’d like to find out more about using Composer with WordPress, check out my talk at WordPress Bournemouth.
The components I used were HttpFoundation – for handing requests and responses, and Validator – for validating input.
composer require symfony/http-foundation
compose require symfony/validator
Source: https://managewp.org/articles/14488/wordpress-ajax-forms-with-symfony-components




source https://williechiu40.wordpress.com/2017/03/01/wordpress-ajax-forms-with-symfony-components/

No comments:

Post a Comment