• Resolved DaveMaison

    (@davemaison)


    Hi,

    There seems to be a lack of explanation of how to do this. Maybe I’m not looking in the correct place.

    I want to have a form field called “Your name” (type: text, required: yes, validate: text) and tie it to the %USER_NAME% replacement token. Or even simply, referencing the value entered into the “Your Name” field in the results.

    Thanks,
    Dave

    https://www.ads-software.com/plugins/wp-survey-and-quiz-tool/

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter DaveMaison

    (@davemaison)

    Was this plugin abandoned?

    Thread Starter DaveMaison

    (@davemaison)

    Had to figure it out on my own because I’m on a time crunch. Here is how you add custom replacement tokens.

    Open wp-content/wp-survey-and-quiz-tool/lib/wpsqt/Tokens.php:

    in the getTokenObject() function, add the following line:
    self::$instance->addToken(“YOUR_CUSTOM_TOKEN“, “Description of your token that appears in the plugin.“)

    in the setDefaultValues() function, add the following line:
    $this->setTokenValue(‘YOUR_CUSTOM_TOKEN‘, ( isset($_SESSION[‘wpsqt’][$quizName][‘Custom_YourName‘]) ) ? $_SESSION[‘wpsqt’][$quizName][‘Custom_YourName‘] : ‘Anonymous User’);

    Open wp-content/wp-survey-and-quiz-tool/pages/site/quiz/section.php:

    At the top of the page add the following
    <?php
    if( !isset( $_SESSION[‘wpsqt’][$quizName][‘Custom_YourName‘] ) && $_REQUEST[ ‘Custom_YourName‘ ] != ” ){
    $_SESSION[‘wpsqt’][$quizName][‘Custom_YourName‘] = $_REQUEST[ ‘Custom_YourName‘ ];
    }
    ?>

    Note: Replace the italicized values with whatever your want. Names of request objects of the custom form fields will have spaces removed and prefixed by “Custom_”.

    Example: Your Name becomes Custom_YourName

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Tying Form fields to Replacement Tokens’ is closed to new replies.