• Resolved UTHZEN

    (@uthzen)


    i created the form below that i wish to check a voucher field i created in the participants database to see if the voucher field being submitted exists in the participants database.

    <form id=”voucherForm” method=”post” action=”/checkout/”>
    <input name=”voucher” type=”text” maxlength=”255″ value=””/>
    <input id=”saveForm” type=”submit” name=”submit” value=”Submit” />
    </form>

    using the code below that will be on /checkout/ i would like the php code to check if the voucher being submitted exists. and if so i would like it to show free registration form. and if not i would like it to show payment form.

    is there any way your plugin can help me do this by looking at the voucher field i created in participants database to see if its exists or not?

    <?php if (isset($_GET[‘voucher’]) && $_GET[‘voucher’] == ‘free’) { ?>
    Show the free registration form.
    <?php } else { ?>
    Show the payment form.
    <?php } ?>

    https://www.ads-software.com/plugins/participants-database/

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author xnau webdesign

    (@xnau)

    You need to know which record to look at, and I don’t see anything in your code that selects the record. The usual way to do this is to determine which record you want to check, the see if the field value matches.

    If you don’t know which record it is, you can try searching the whole column to see if you get a match…might be something like this:

    <?php
    global $wpdb;
    $voucher = $wpdb->get_var($wpdb->prepare('SELECT p.voucher FROM ' . Participants_Db::$participants_table . ' p WHERE p.voucher = "%s"'), $_GET['voucher']);
    ?>

    That will give you the matching voucher value or null of not found.

    Check this page for more on using the $wpdb object in WordPress: https://codex.www.ads-software.com/Class_Reference/wpdb

    Thread Starter UTHZEN

    (@uthzen)

    Last Two Questions:

    1. is searching the whole voucher column easier using the get_col instead of get_var code?
    2. lastly my php is no good, so how would “best” insert the code above?

    Is it better to make it a separate php file & link to it using the action= on the form i have above.

    For example: making php file called “vouchervalidation.php” that holds the php code you have created and placing it within the template directory. And then linking to it using the example below.

    action=<?php bloginfo('template_url'); ?>/vouchervalidation.php within the form itself.

    PS. If this works you would have saved me pulling my hair out. please send me the info to donate to this innovative plug-in, because you have saved me so much time.

    thanks in advance

    ~UZ

    Plugin Author xnau webdesign

    (@xnau)

    UZ,

    I’m sorry I can’t advise you with specifics, I just don’t have enough information, and I’d probably want to bill you for the time to go in and figure this out for you.

    I will say that there is no need to include a php script, just create a custom template and put your verification code in at the top. I have a page on how to create custom templates here: https://xnau.com/work-2/wordpress-plugins/participants-database/pdb-templates/ Perhaps this is your chance to learn more about PHP?

    Thread Starter UTHZEN

    (@uthzen)

    Ok i see what your saying xnau. I’m going to tell you what i’m trying to do with your plugin and you tell me if its possible and if it is possible, how i can do it using your plugin.

    using your plugin i went to “manage fields database” and created a field called “Vouchers”. i clicked the Signup check box to the right, so it can be seen using your shortcode [pdb_signup] on a signup page i created in wordpress.

    i want people to go to the my “signup page” and use the [pdb_signup] form to input there first name, last name, email and there voucher, that i will create for them using “add participant” in your plugin using wordpress.

    next i would like people to go to the signup page that i created in wordpress, that has the shortcode [pdb_signup] within it. Example: https://mysite.com/signup

    then i want that person on the signup page to put in there first name, last name, email and voucher and click sign up when there done.

    i want the [pdb_signup] to check to see if the information is valid by checking to see if the first name, last name, email and voucher exists and if it does exist i want it to show a free-form i created and if it does not exist or the info input wrongly by fields not matching up, then i want it to show a pay-form i have created.

    if my new field voucher is a problem then is it possible to make a input box using [pdb_signup] shortcode that will check the private id field instead?

    im not sure if the [pdb_signup] can do this because its made to create an account rather then to check a database to see if those fields exist. so thats my dilemma.

    thanks for your time and patients.

    UZ

    Plugin Author xnau webdesign

    (@xnau)

    UZ,

    The signup form can be set up to check if a record with a matching field exists in the database and prints an error message if it does exist. If I understand what you’re trying to do, this is kindof the opposite of what you want because you want it to only accept the submission if it matches an existing record’s voucher number.

    It may be fairly easy to modify the plugin to do this, but I can’t look at the code at this moment…I will tell you that the logic for this happens in the process_form() function in participants-database.php

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Validating Voucher Field’ is closed to new replies.