I have created a form (Gravity Form) which I want to be able to complete dynamically from several of my other websites. In such a case, one of the fields that I am trying to send to the form is the post title, which can - and does - includes ampersands from time to time (e.g. The Ins & Outs of Gravity Forms).
The trouble I'm having is figuring out how to encode the post title so that ampersands within the post title are not treated as separators for the next query var.
For example, the URL
mydomain.com/page-with-my-form-on-it/?title=The Ins & Outs of Gravity Forms&type=new should complete the 'title' field with 'The Ins & Outs of Gravity Forms' and the 'type' field with 'new', but instead it puts 'The Ins ' in the 'title' field and leaves the 'type' field (and any other subsequent fields) empty.
To create that URL, my current code is simply as follows, though I have tried using urlencode(), htmlentities(), and str_replace() with the_title() to try and overcome this issue:
<a href="http://www.mydomain.com/page-with-my-form-on-it/?title=<?php the_title(); ?>&type=new">Link</a>