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

    (@xnau)

    It’s easier to do two different forms. If you’ve got some javascript skills, you can do it on one form.

    To make different forms, you can put your extra questions into their own group, then use the groups to control which fields are shown:

    [pdb_signup groups=”main,personal”]

    Then for underage users:
    [pdb_signup groups=”main,personal,under18″]

    Thread Starter gilesytheking

    (@gilesytheking)

    I have managed to create 2 forms with different fields using the groups and shortcode as you described.

    I have also created a hidden field so that I know which signup form / page was used (Over 18 or under 18).

    My next question is how can I apply the same logic to the edit page? A member who used the over 18 signup form, should only be able to view those groups relevant to the over 18 signup form, when editing their details.

    Plugin Author xnau webdesign

    (@xnau)

    The [pdb_record] shortcode works the same way, the problem is you’ll need to change the URL for the user depending on which form you want them to use. You’ll need to use a custom template for the list to do that. How are you with PHP?

    Another possibility is to set up a custom template on the record form that determines which fields are shown based on the user’s age. That way, you’re only using one page for the record edit.

    Thread Starter gilesytheking

    (@gilesytheking)

    I had a thought to create custom page template for the edit page and then some how query the hidden field (Over 18 or under 18).

    Something along the lines of;

    “IF over 18 do shortcode [pdb_edit groups=x,y,Z]”

    “else if under 18 do short code [pdb_edit groups=a,b,c]

    I know some php, but not sure how i would tackle this exactly

    Plugin Author xnau webdesign

    (@xnau)

    Well, the page template need to get the record values for the user. You can do that with something like this:

    <?php
    $participant = Participants_Db::get_participant( Participants_Db::get_participant_id( filter_input( INPUT_GET, 'pid', FILTER_SANITIZE_STRING ) ) );
    if ( $participant['age'] < 18  ) : ?>
    
    [pdb_record groups=main,personal,under_18 ]
    
    <?php else : ?>
    
    [pdb_record groups=main,personal,over_18 ]
    
    <?php endif ?>
    Thread Starter gilesytheking

    (@gilesytheking)

    Super I managed to get it working using the following code. I copied my default page template, renamed the file/template and added the code into the content section of the page.
    I had to create a hidden field, with a default value 18, that is only displayed on the over 18’s submit form.

    ?php
    $participant = Participants_Db::get_participant( Participants_Db::get_participant_id( filter_input( INPUT_GET, 'pid', FILTER_SANITIZE_STRING ) ) );
    if ( $participant['age'] < 18  ) :
    
    echo do_shortcode ('[pdb_record groups="terms_and_conditions,main,parent_or_guardian_details,personal,agreement"]')  ?>
    
    <?php else :
    
    echo do_shortcode ('[pdb_record groups="terms_and_conditions,main,contact_information,personal,agreement"]') ?>
    
    <?php endif ?>
    Thread Starter gilesytheking

    (@gilesytheking)

    1 more thing, how can I map the values of a field and save it in another.

    What I mean is;

    the over 18’s form has an email address and telephone number field,(email,phone) which I use to identify/search for my members when they visit my venue.

    On the under 18’s form, I also collect a telephone number and email address, but of the parents (parents_email, parents_phone).

    How can I save the parents email and phone into the email and phone fields without displaying them on the form, so that I can search them easily?

    Plugin Author xnau webdesign

    (@xnau)

    It’s possible, but somewhat complicated. You’ll need to a filter callback to copy the values and a custom template so you can add the fields you’re copying to as hidden fields.

    In the custom template for your under-18 signup form (works for the record edit form, too) add this to the top before any of the HTML:

    <?php $this->hidden_fields['email'] = '';
    $this->hidden_fields['phone'] = '' ?>

    That lets you add the fields without them being visible. Don’t add them in the shortcode too, or they will be visible.

    The filter callback has to be added to your theme functions file or to a simple plugin. To add the plugin, just upload this php script to the plugins directory, then activate it.

    <?php
    
    /**
     * Plugin Name: copy form submission values
     * Description: copies the under-18 email and phone into the main email and phone fields
     */
    
    add_filter('pdb-before_submit_signup', 'xnau_copy_field_values');
    
    function xnau_copy_field_values( $post ) {
      $post['email'] = $post['parents_email'];
      $post['phone'] = $post['parents_phone'];
      return $post;
    }
    Thread Starter gilesytheking

    (@gilesytheking)

    I will have to have a play around with the code for the email and phone fields, ill let you know how it goes.

    I have noticed that the hidden field I created for the over 18s form is not working properly. What i mean is;

    the hidden field is only included on the over 18’s form and has a default value of “18”. The database key is “age”.
    I use this field to display the correct field groups on the editing and single display pages as described above. If over 18…. else…..

    However the forms submitted from the under 18’s form, which doesn’t include this hidden field are being saved with the value “18” in the “age” field. Should the age field not be blank for forms submitted on the under 18’s form?

    Plugin Author xnau webdesign

    (@xnau)

    OK, don’t use the “default” value of the hidden field, that will save that value in all records as a default. To set the value of a hidden field dynamically, add that to your custom template the same way I showed you for adding hidden fields, only put the value you want to store in there…

    <?php $this->hidden_fields['age'] = '18'; ?>

    Thread Starter gilesytheking

    (@gilesytheking)

    when you say template, you do mean page template?

    I have created a page template for each of my form submission pages and included the pdb_signup shortcode, to display under and over 18’s forms.

    If I include the <?php $this->hidden_fields[‘age’] = ’18’; ?> within the page template I get the following error.

    Fatal error: Using $this when not in object context in…..

    Thread Starter gilesytheking

    (@gilesytheking)

    Perhaps its easier to use the “post->post_title” code in the default value, for the “age” field, so I know which page/form the the entry was submitted from.

    What would I need to change the “if participant” line to in order to check the value in the “age” field.

    ?php
    $participant = Participants_Db::get_participant( Participants_Db::get_participant_id( filter_input( INPUT_GET, 'pid', FILTER_SANITIZE_STRING ) ) );
    if ( $participant['age'] < 18  ) :
    
    echo do_shortcode ('[pdb_record groups="terms_and_conditions,main,parent_or_guardian_details,personal,agreement"]')  ?>
    
    <?php else :
    
    echo do_shortcode ('[pdb_record groups="terms_and_conditions,main,contact_information,personal,agreement"]') ?>
    
    <?php endif ?>
    Plugin Author xnau webdesign

    (@xnau)

    I see, I thought you were using a custom plugin template. The instructions I gave earlier were for that, so I figured…anyway, you have to use a custom plugin template to pre-set the hidden field value dynamically.

    …or you can use the “post->post_name” default and use that to determine the age group, as you suggest.

    Thread Starter gilesytheking

    (@gilesytheking)

    I don’t have an issue creating a plugin template. In the setup I have, i have 2 forms both use the default pdb signup template from the plugin and each have thier own page template which includes the shortcode.

    I will need to create 2 plugin templates, one for the over 18 and one for the under 18. How can I then apply the 2 separate templates to the shortcode for the specific form or page?

    If i were to use the post->post_name instead of the default value “18”, what line of code would I use to check the saved post name value?

    ?php
    $participant = Participants_Db::get_participant( Participants_Db::get_participant_id( filter_input( INPUT_GET, 'pid', FILTER_SANITIZE_STRING ) ) );
    if ( $participant['age'] = my page name  ) :
    Thread Starter gilesytheking

    (@gilesytheking)

    Managed all of this without any issues. Thanks again for your continued support.

Viewing 15 replies - 1 through 15 (of 27 total)
  • The topic ‘2 forms on the same site?’ is closed to new replies.