Upload Images Using JS

I recently needed to update a form to update through AJAX so the page didn’t reload when submitted. The issue was that we had some images on this form. In the past I have used things like plupload, but that didn’t seem like the right approach in this instance.

At first I looked into the “fetch” api and saw a good post from Tania Rascia, but unfortunately the fetch API still isn’t fully adopted…DAMN YOU MICROSOFT!

Thankfully I was able to find a jQuery version of this same idea over on Makeitweb.com by Yogesh Singh.

I also needed to make sure I sent along post data with the FormData to update the rest of the form. Here is an example of the JS code I ended up using:

On the server script you can access this data just like any other form submission.

PHP

There we go! Now we can submit our form, including images, to our server script!

NOTE: We are using a custom function to serialize our form data. You can find that function here.

Cross Browser HTML5 Date Input

I have been waiting for the day when using <input type=”date” /> would be common…alas, 3 years after the standards were written it is still not supported in IE or Safari.

UNFORTUNATELY we still have to support these browsers…

Traditionally I have been using a third party datepicker (jQuery UI, Bootstrap Datepicker, etc) but I REALLY wanted to just use the default type=”date” this time.

I found a great solution over on Stack Overflow from Kashif Latif.

BAM! We have a polyfill. As far as I can tell this does the trick.

A Better GForms Repeater Example

The Gravity Forms repeater field example is helpful, but has multiple issues that don’t make themselves apparent until you try to implement it.

Thankfully Giorgos Sarigiannidis has a better repeater example that solves some of the most troubling issues of the repeater field.

Here is my example of the same idea, but using a different form as the fields in the repeater. This allows the client to update the fields in the repeater themselves.

 

Gforms doesn’t have a counter system built in yet so if you want to use a counter with your repeater ( ex: Attendee #1, Attendee #2, etc… ) here is some SCSS code you can use to accomplish that.

This will look something like this:

Helpful Javascript Prototype Functions

Sometimes the built in functionality for various Javascript primitives is not enough. Here is an assortment of useful Prototype functions. Enjoy!

 

Multiple Custom Query with paginate_links

Sometimes I need pagination for multiple queries on a single page. Whenever possible I use the built in WordPress functions for this purpose. However, WordPress’ pageinate_links() is really meant for WP custom queries…and preferably one query per page.

Here is an example of how you can use this built in function for your own queries! We are using an example which involves three different email lists we need to display.

First, setup your queries:

Second, display your results: Note, I am leaving out a lot of the display code, but all the relevant pagination code should be here.

Notice at the bottom of this loop we are calling our pagination function for each list. The important thing to note here is that we are using a separate ‘type’ variable so we know which list we are paginating.

Lastly, here is the actual pagination function:

 

ACF Gallery Saved to Specific Folder

Recently we had a client that wanted to make sure all of the files in one of their galleries was in a specific directory instead of the default upload/year/month directory.

Here is a simple function to make sure that happens, including updating all previous files uploaded to that gallery.