Safari Doesn’t Care About Your JavaScript On Submit

Recently I was implementing some new code to show a user that an order was processing. Pretty standard stuff with overlays, hiding the submit button etc… While going through routine testing in various browsers I noticed that the implementation was not working in Safari. Oddly it turns out that when you submit a form via JavaScript in Safari it decides to pretty much not execute anything else. A stackoverflow thread touched up on this a bit, along with a potential solution.

Here we have a sample of the code that doesn’t work as expected in Safari:

The solution is to use setTimeout as a poor mans queue.

I can’t understand why Safari operates differently in this respect. All other major browsers work as expected including Internet Explorer. With some other odd behavior I’ve seen out of Safari lately, I think its quickly becoming the new IE6.

Reorder DOM Elements Without Removing and Replacing

I had an interesting problem recently that required I re-order some DOM elements without doing a remove and replace. The existing implementation had a bug involving some filtering based on html attributes and I wanted to avoid rewriting some legacy code. Typically you would do something like this:

The problem is you are replacing everything including any events you have binded to those elements. The solution comes courtesy of this blog post and utilizes the jQuery detach method. Per the jQuery manual:

The .detach() method is the same as .remove(), except that .detach() keeps all jQuery data associated with the removed elements. This method is useful when removed elements are to be reinserted into the DOM at a later time.

Our initial example becomes this:

This handy solution easily replaces what you might be more familiar with.

Sabre GDS SOAP Web Service with PHP Done Right

I recently had the opportunity to work with Sabre’s Global Distribution System SOAP web service. The Sabre GDS powers everything from hotel bookings, to flights and cruises. Most hotels and airlines add inventory into Sabre allowing booking agencies and travel websites to display this data to customers and book travel plans through the GDS. Sabre is old and some of its client systems look almost VAX like, so working with it can be difficult at times.

If you are reading this post you’ve probably concluded that PHPs native SOAP client cannot easily consume Sabre’s GDS web service. I gave up on it after about a day. I had gone this route to replace a pre-existing solution that resulted in socket timeout errors. The current solution for PHP developers floating around the internet is slow and unreliable. After digging deep into the PHP SOAP Client documentation I discovered a middle ground approach between consuming the WSDL (which doesn’t work) and writing raw socket connections (which barely works).

Customizing CakePHP 3 Form Helper

The Cake 3 form helper component’s default output isn’t super conducive to working with front-end frameworks like Bootstrap. Luckily the Cake 3 team provide us with a template system to change the default output. Here’s a quick example to get you going:

The above sample outputs the following HTML:

The Cake 3 template system is quite extensive, check it out.

Multiple Checkboxes and CakePHP3 CSRF Security Component

I’ve spent a bit of time over the last few months learning Cake 3 (currently RC-2). I’ve been having a heck of a time with the CSRF Component barking at me that my requests have been black holed. If you’ve used the CSRF at all you’ve no doubt received something like this:

The request has been black-holed Error: The requested address ‘/controller/action/1’ was not found on this server.

Well I finally figured it out. When dealing with multiple checkboxes to submit an array over HTTP POST, you will want to use the unlockField feature. The component clearly has problems with creating a hash from multiple checkbox elements with the same name. Here’s some example code to get you out of the black hole.