I've previously written about using PHP to auto populate a form with URL query string values. In this post I'm going to describe how you can auto-submit that form so that the user doesn't even need to click the submit button.
This script will auto-submit the form once the page has loaded provided that 'autosubmit=1' is present in the URL's query string, eg. http://ww.example.com/testform?autosubmit=1
<?php if ($_REQUEST['autosubmit']) { ?> <script> (function ($) { $(document).ready(function(){ $('form#theFormId').submit(); }); })(jQuery); </script> <? } ?>
The above script uses a combination of PHP and jQuery, but it could be done using only jQuery - see this post about using jQuery to populate a form with URL values. Personally I prefer the PHP version as the jQuery code is only rendered if the 'autosubmit=1' value is present in the URL.
Drupal version:

Justin Chevallier
Avid Drupal site builder & user for +10 years.
Comments
Just what I was looking for.
Just what I was looking for. Thanks a lot!
Add new comment