How to force the form action URL to be SSL

Posted by on Aug 23, 2013 in How To

How to force the form action URL to be SSL

Add the following code to your theme’s functions.php file or to a custom plugin.
Be sure to set the setting in the function to control which forms you want this on.
These filters only work with versions 4.xx and up, not the 3.xx versions or lower.

Note: you must already have a SSL certificate installed for your domain. If you do not already have the SSL certificate, please contact your web host to acquire one.

function my_action_url_ssl($form_action_url, $form_id_num) {

##################################
 // control which forms you want this on
 $all_forms = false; // set to true for process on all forms, or false to use settings below
 $forms = array('1','2');  // one or more individual forms
 ##################################
 if ( !in_array($form_id_num, $forms) && $all_forms != true)
 return $form_action_url;

  // force form action URL to be SSL
  $form_action_url = preg_replace( '|http://|', 'https://', $form_action_url );

   return $form_action_url;

}
//filter hook for form action URL
add_filter('si_contact_form_action_url', 'my_action_url_ssl', 1, 2);

See related post: What is “secure” about Fast Secure Contact Form?

Do you need help?

Send us a Donation:

Donate to Mike Challis