• maltpress

    (@maltpress)


    Hi,

    Love the work you’re doing resurrecting/maintaining this plugin – thanks!

    I’ve got a possible improvement/feature request – would it be possible to do a couple of little things?

    • Add filter to submit button so we can change the onClick event, calling cforms_validate() in our own scripts? This way we can better add GA code
    • In addition to this, make cforms_validate return a value other than false on success so we can test that it’s worked?

    As an example (and I hate editing plugins because updates…):

    cforms.js: line 634 becomes:

    cforms_submitcomment(no);
    return 'done';

    I’ve also added a function which returns rather than echoes a form, so it can be filtered:

    function return_cform($no='',$custom='',$c='') {
    	$pid = cforms2_cfget_pid();
    
    	if( !is_numeric($no) )
                $no = cforms2_check_form_name( $no );
    
    	if ( !$pid )
                return cforms2($custom,$no.$c);
    	else
                return cforms2_check_for_taf($no,$pid)?cforms2($custom,$no.$c):'';
    
    }
    
    add_filter('name_formfilter', 'name_cforms_button_ga');
    
    function name_cforms_button_ga($output) {
        $output = str_replace('onclick="return cforms_validate(\'\', false)"', '', $output);
        return $output;
    }

    Then add a new function to theme’s JS (which depends on form ID being known) – I’m still testing this!:

    jQuery('#cformsform #sendbutton').on('click', function(){
        var validate = cforms_validate('', false);
        console.log(validate);
        // do stuff
        return validate;
    });

    That’s all working for me… but your next update will break things, so it would be good to have a more permanent solution

    https://www.ads-software.com/plugins/cforms2/

Viewing 1 replies (of 1 total)
  • Plugin Author bgermann

    (@bgermann)

    Why don’t you just manipulate via JavaScript? That should work as well.

Viewing 1 replies (of 1 total)
  • The topic ‘Adding Google analytics event code to submit button’ is closed to new replies.