ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

[solved] Forcing EE Module forms to post to https://

May 12, 2010 2:45pm

Subscribe [2]
  • #1 / May 12, 2010 2:45pm

    Ryan Blaind

    168 posts

    Hey guys, I need a little hand here. I am not very good with this stuff, and I’ve been banging my head against a wall all morning trying to figure this out.

    Basically I am creating a website that uses the user module and cartthrob, and I would like to create a simple plugin to wrap around the modules template tags to force the forms to submit to an url with https:// rather than the standard http://.

    I got this idea from Brandon Kelly’s post about Pixel & Tonic, which you can reference from this blog post.

    Here is my plugin so far

    <?php
    
    $plugin_info = array(
        'pi_name'            => 'Use The Force',
        'pi_version'        => '1.0',
        'pi_author'            => 'Ryan Blaind',
        'pi_author_url'        => 'http://theyinspire.com',
        'pi_description'    => 'Convert all instances of http:// to https://',
        'pi_usage'            => Use_the_force::usage()
        );
    
    
    class Use_the_force
    {
    
        function Use_the_force()
        {
            global $TMPL;
            $tagdata = $TMPL->tagdata;
            return str_replace('http://', 'https://', $tagdata);
        }
    
        
       // ----------------------------------------
       //  Plugin Usage
       // ----------------------------------------
    
       function usage()
       {
       ob_start();
       ?>
    
       example: {exp:use_the_force}http://site.com/{/exp:use_the_force}
    
       <?php
       $buffer = ob_get_contents();
    
       ob_end_clean(); 
    
       return $buffer;
       }
    
    }
    
    /* End of file pi.use_the_force.php */
    /* Location: ./system/plugins/pi.use_the_force.php */

    (pastie link)

    and inside a simple template, I am using this code to test it, but nothing gets output. Here is the simple template code:

    {exp:use_the_force}http://site.com/{/exp:use_the_force}

    please help, I am stuck. Thanks in advance (:

    cheers
    -Ryan

  • #2 / May 12, 2010 5:08pm

    Ryan Blaind

    168 posts

    With a little help from a friend, I think I have it working correctly.

    <?php
    
    $plugin_info = array(
        'pi_name'            => 'Use The Force',
        'pi_version'        => '1.0',
        'pi_author'            => 'Ryan Blaind',
        'pi_author_url'        => 'http://theyinspire.com',
        'pi_description'    => 'Convert all instances of http:// to https://',
        'pi_usage'            => Use_the_force::usage()
        );
    
    
    class Use_the_force
    {
    
        function Use_the_force()
        {
            global $TMPL;
            $tagdata = $TMPL->tagdata;
            
            //Future Ryan and Lee. Please know past Lee did this under duress. Forgive him.
            $ee_is_not_my_father = str_replace('http://', 'https://', $tagdata);
            $may_the_force_be_with_you = str_replace('/', '/', $ee_is_not_my_father);
            echo $may_the_force_be_with_you;
        }
    
        
       // ----------------------------------------
       //  Plugin Usage
       // ----------------------------------------
    
       function usage()
       {
       ob_start();
       ?>
    
       example: {exp:use_the_force}http://site.com/{/exp:use_the_force}
    
       <?php
       $buffer = ob_get_contents();
    
       ob_end_clean(); 
    
       return $buffer;
       }
    
    }
    
    /* End of file pi.use_the_force.php */
    /* Location: ./system/plugins/pi.use_the_force.php */

    just in case anyone is interested. cheers

  • #3 / May 12, 2010 7:35pm

    Rob Sanchez

    335 posts

    Hey Ryan, you should check this out, too: http://cartthrob.com/docs/tags_detail/https_redirect/

    It redirects and also replaces {site_url}, {path=}, etc to use https.

  • #4 / May 13, 2010 10:33am

    Ryan Blaind

    168 posts

    well it turns out that this is in fact NOT working as expected. Once I wrap any of my User module forms with it, or even the EE login form, it breaks completely. Anyone have a second to help me out with this today?

  • #5 / May 13, 2010 4:07pm

    Ryan Blaind

    168 posts

    Ok so, I have figured out a couple work arounds instead of creating this ridiculous plugin. So my apologies! For anyone who is interested, for solspace USER / Freeform, I came across this parameter that you can use to force your forms to submit to https:// urls:

    secure_return="yes" secure_action="yes"

    And for the member:login_form tag, you can use this little module hack to add a parameter to your login form tag:

    If you need to set a custom action (for instance, if you want to force logins to use https while the rest of the site sticks to http), you can add an action parameter to this tag by adding the following code around line 1800 of the mod.member.php file (if there’s an update the line numbers change, it should immediately precede the $res = $FNS->form_declaration($data); line in the login_form function):

    if ($TMPL->fetch_param('action') !== FALSE)
    {
        $data['action'] = $TMPL->fetch_param('action');
    }

    After hacking that into the core file, you’ll be able to use the action parameter like this:

    {exp:member:login_form action="https://mydomain.com/" return="{segment_1}/{segment_2}/{segment_3}"}
.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases