Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author Devin Walker

    (@dlocc)

    Hi @deexperte – Sorry to hear it’s not populating! Would you mind providing me a link to your site and the code your using? You can paste the code and URL in your response below. That’ll help me troubleshoot and provide a fix 🙂

    Thread Starter deexperte

    (@deexperte)

    Hello Devin,
    The link to page with shortcode:
    http://braunenberg.srv-mars.de/spenden/?amount=111

    The page with embeddedcode:
    http://braunenberg.srv-mars.de/spenden/

    [give_form id=”1649″]

    Function:

    <?php
    /** Give Daten aus URL ind Felder des Spendenforms schreiben beim Aufruf durch URL-Link z.B. Button ————————————— **/
    /**
    * AUTO-POPULATE AMOUNT, NAME, and EMAIL FROM URL STRING
    * Daten aus URL-Aufruf in das Spendenform eintragen
    * This jQuery snippet will auto-populate the Give form amount,
    * first and last name, and email address from a URL you provide
    * EXAMPLE: https://example.com/donations/give-form/?amount=46.00&first=Peter&last=Joseph&email=testing@givewp.com
    *
    * CAVEATS:
    * — Your form must support custom amounts
    * — This snippet only supports one form per page as-is
    */
    add_action( ‘give_after_single_form’, ‘give_populate_amount_name_email’ );
    function give_populate_amount_name_email() { ?>

    <script>
    // Get variable from query string in URL
    function getQueryVariable(variable)
    {
    var query = window.location.search.substring(1);
    var vars = query.split(“&”);
    for (var i=0;i<vars.length;i++) {
    var pair = vars[i].split(“=”);
    if(pair[0] == variable){return pair[1];}
    }
    return(false);
    }
    jQuery(document).ready(function( $ ) {
    // Get the amount from the URL
    var getamount = getQueryVariable(“amount”);
    // Set fallback in case URL variable isn’t set
    if ( getamount != false ) {
    amount = getamount;
    } else {
    amount = ‘1.00’;
    }
    var firstname = ( getQueryVariable(“first”) != false ) ? decodeURI(getQueryVariable(“first”)) : ”;
    var lastname = ( getQueryVariable(“last”) != false ) ? decodeURI(getQueryVariable(“last”)) : ”;
    var email = ( getQueryVariable(“email”) != false ) ? decodeURI(getQueryVariable(“email”)) : ”;
    // Populate the amount field, then update the total
    if ( $(‘#give-amount’).length > 0 ) {
    $(‘#give-amount’)
    .val(amount)
    .focus()
    .trigger(‘blur’);
    }
    if ( firstname != false && $(‘#give-first-name-wrap input.give-input’).length > 0 ) {
    $(‘#give-first-name-wrap input.give-input’)
    .val(firstname);
    }
    if ( lastname != false && $(‘#give-last-name-wrap input.give-input’).length > 0 ) {
    $(‘#give-last-name-wrap input.give-input’)
    .val(lastname);
    }
    if ( email != false && $(‘#give-email-wrap input.give-input’).length > 0 ) {
    $(‘#give-email-wrap input.give-input’)
    .val(email);
    }
    });
    </script>
    <?php

    }

    Plugin Author Devin Walker

    (@dlocc)

    Thanks @deexperte – The issue is the snippet you’re using was assuming you’re using the form on it’s single post page. However, it looks like you’re embedding it within another page. I have just updated the snippet within the repo to account for this. What you need to do is change:

    add_action( 'give_after_single_form', 'give_populate_amount_name_email' );

    to

    add_action( 'give_post_form_output', 'give_populate_amount_name_email', 10, 2 );

    Once you change this within the code you pasted, reload the page and you should see it populating as expected. Example URL: http://braunenberg.srv-mars.de/spenden/?amount=200&first=Devin&last=Walker

    Thread Starter deexperte

    (@deexperte)

    Hi Devin!
    Excellent! It works!

    Thank you for professional supporting.

    Greetings

    Deexperte

    Plugin Author Devin Walker

    (@dlocc)

    Glad to hear it! If you’re liking our plugin and support please consider rating it: https://wordpress.org/support/plugin/give/reviews/#new-post

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Populate not working with shortcode’ is closed to new replies.