WordPress.org

Make WordPress Core

Changeset 38587


Ignore:
Timestamp:
09/11/2016 05:04:39 AM (21 months ago)
Author:
westonruter
Message:

Customize: Implement previewing of form submissions which use the GET method.

This finally allows the search results template to navigated to in the customizer preview.

Fixes #20714.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/js/customize-preview.js

    r37700 r38587  
    6868
    6969            // You cannot submit forms.
    70             // @todo: Allow form submissions by mixing $_POST data with the customize setting $_POST data.
    7170            this.body.on( 'submit.preview', 'form', function( event ) {
     71                var urlParser;
     72
     73                /*
     74                 * If the default wasn't prevented already (in which case the form
     75                 * submission is already being handled by JS), and if it has a GET
     76                 * request method, then take the serialized form data and add it as
     77                 * a query string to the action URL and send this in a url message
     78                 * to the Customizer pane so that it will be loaded. If the form's
     79                 * action points to a non-previewable URL, the the Customizer pane's
     80                 * previewUrl setter will reject it so that the form submission is
     81                 * a no-op, which is the same behavior as when clicking a link to an
     82                 * external site in the preview.
     83                 */
     84                if ( ! event.isDefaultPrevented() && 'GET' === this.method.toUpperCase() ) {
     85                    urlParser = document.createElement( 'a' );
     86                    urlParser.href = this.action;
     87                    if ( urlParser.search.substr( 1 ).length > 1 ) {
     88                        urlParser.search += '&';
     89                    }
     90                    urlParser.search += $( this ).serialize();
     91                    api.preview.send( 'url', urlParser.href );
     92                }
     93
    7294                event.preventDefault();
    7395            });
Note: See TracChangeset for help on using the changeset viewer.