Home Forums Weaver Xtreme Theme Child Theme Help

This topic contains 9 replies, has 3 voices, and was last updated by  scrambler 1 week, 5 days ago.

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #57470

    GR8FL
    Participant

    I need to make changes to the PHP file because of Gravity Forms. In the past, under old Weaver, it was an involved process to make a child theme. Can you walk me through doing child theme with Weaver Xtreme?

    Below is an example of what I want to insert (to turn off auto-fill). Can this be added to the PHP area through Admin under Actions & Filters?

    Site: https://hattiesgarden.com/

    add_filter( ‘gform_form_tag’, ‘form_tag’, 10, 2 );
    function form_tag( $form_tag, $form ) {
    // Turn off autocompletion as described here https://developer.mozilla.org/en-US/docs/Web/Security/Securing_your_site/Turning_off_form_autocompletion
    $form_tag = preg_replace( “|action=’|”, “autocomplete=’off’ action='”, $form_tag );
    return $form_tag;
    }

    #57471

    scrambler
    Moderator

    Have you tried to just put it in there and see if it works?

    #57472

    GR8FL
    Participant

    I did. Not sure if it worked.

    I’m trying to eliminate autofill since it populates one of the product fields with the zip code. Does this only one mobile – well at least with an iPhone.

    It did disable on desktop, where there isn’t a problem, but not on my phone.

    #57473

    GR8FL
    Participant

    Tried to put some other code, and Xtreme did not like it at all.

    I think I need to get the function.php child going.

    https://gist.githubusercontent.com/spivurno/ee1d3c157738e22e2cb44bf239eeffd2/raw/2965d5d769fb99bc425874ad1bb3ce48f9a1b099/gw-gravity-forms-first-error-focus.php

    #57474

    scrambler
    Moderator

    It may not be that you need a child theme, but just the PHP syntax, but @weaver is the only one who may be able to confirm that.

    #57475

    Weaver
    Keymaster

    I don’t know how well you know PHP, but it does take some knowledge.

    About the PHP included in your last post, please note that it starts with a <?php line. You need to understand what that means, If you tried to put that directly into a child theme, it would break the same way as it does when you add it to the Actions and Filters section.

    That code, and any other simple add_filter type code should work fine using that technique – assuming you have correct code.

    So if you read the description/instructions for Actions and Filters, you should note that it says:

    Do NOT bracket the code with <?php and ?> at the beginning and end.

    And that would most likely be the source of your problems with your second example.

    I can’t say whether or not the actual PHP code in the filter (boils down to the preg_replace statement) is correct or not. But as part of your copy/pasting, be sure you have ONLY simple single quotation marks (‘) or simple double quotation marks (“). Anything else will not work – and depending on how you copy/past the code, we’ve found that it is not unknown to have the double quotation marks replaced by “smart” quotes, which are completely different characters and not recognized by PHP.

    #57510

    GR8FL
    Participant

    Should I just drop everything in beginning with the comment line all the way through:

    </script>
    }

    What about at the end after the <?php where it says:

    return $form;
    }
    #57512

    scrambler
    Moderator

    the code you linked to is confusing to me as it mixes PHP (yellow) with HTML (blue), and the last PHP segment is not terminated, missing ?>

     

    <?php
    /**
    * Gravity Wiz // Gravity Forms // Give First Validation Error Focus
    * http://gravitywiz.com/
    */
    add_filter( 'gform_pre_render', 'gw_first_error_focus' );
    function gw_first_error_focus( $form ) { 
        add_filter( 'gform_confirmation_anchor_' . $form['id'], '__return_false' );
        ?>
        <script type="text/javascript">
            if( window['jQuery'] ) {
                ( function( $ ) {
                    $( document ).bind( 'gform_post_render', function() {  
                        var $firstError = $( 'li.gfield.gfield_error:first' );
                        if( $firstError.length > 0 ) {
                            $firstError.find( 'input, select, textarea' ).eq( 0 ).focus();
                            document.body.scrollTop = $firstError.offset().top;
                        }
                    } );
                } )( jQuery );
            }
        </script>
        <?php 
        return $form;
    }

     

    #57518

    Weaver
    Keymaster

    That code is 100% .php file compatible. In fact, PHP almost always mixes real PHP code between <?php … php code … ?> brackets and HTML in between. The filters and actions Weaver section really does not allow the outside <?php and ?>  (usually first and last lines of the file, but as a “convenience”, you don’t need the ?> for the end of the file – which is what was done in the above example). That means that the first bit of code in a Weaver Filter/Action section must be a line of PHP. But you can still embed HTML normally, just as in any PHP program.

    As a habit, I always bracket all of my PHP files with <?php … ?>. I think it is lazy/sloppy not to, but a LOT of PHP never use the trailing ?>.

    #57521

    scrambler
    Moderator

    If I understand weaver, this is the code you should try

    /**
    * Gravity Wiz // Gravity Forms // Give First Validation Error Focus
    * http://gravitywiz.com/
    */
    add_filter( 'gform_pre_render', 'gw_first_error_focus' );
    function gw_first_error_focus( $form ) { 
        add_filter( 'gform_confirmation_anchor_' . $form['id'], '__return_false' );
        
        <script type="text/javascript">
            if( window['jQuery'] ) {
                ( function( $ ) {
                    $( document ).bind( 'gform_post_render', function() {  
                        var $firstError = $( 'li.gfield.gfield_error:first' );
                        if( $firstError.length > 0 ) {
                            $firstError.find( 'input, select, textarea' ).eq( 0 ).focus();
                            document.body.scrollTop = $firstError.offset().top;
                        }
                    } );
                } )( jQuery );
            }
        </script>
       
        return $form;
    }
Viewing 10 posts - 1 through 10 (of 10 total)

You must be logged in to reply to this topic.