Support » Plugin: Participants Database » Showing a Record Edit Form Based on a Value in the Record

  • Resolved pcgardner

    (@pcgardner)


    I have successfully set up multiple sign-up forms for three different types of people, and now want to set up the record edit page so that each type can edit the appropriate fields. This page (https://xnau.com/showing-a-record-edit-form-based-on-a-value-in-the-record/) deals with exactly this, but I can’t get it to work.

    I have saved the code for pdb-record-usertype.php and customized it for my fields and groups as follows:

    /*
     * first, check for the value that determines what kind of 
     * record edit form to show
     */
    $type = $this->participant_record['source_page'];
    
    /*
     * now, show the record edit form for that type
     */
    echo 'Source page: ' . $type;
    
    switch ( $type ) {
       case 'sign-our-letter-laity':
          echo do_shortcode('[pdb_record groups="main,church_of_england,laity"]');
          break;
       case 'sign-our-letter-clergy':
          echo do_shortcode('[pdb_record groups="main,church_of_england,clergy"]');
          break;
       case 'sign-our-letter-anglican-communion':
          echo do_shortcode('[pdb_record groups="main,anglican_communion"]');
          break;
    }

    I added the line echo 'Source page: ' . $type; for debugging purposes.

    I uploaded pdb-record-usertype.php to my theme’s templates folder, and put the shortcode [pdb_record template=usertype] in my record edit page, after some introductory text.

    Initially the record edit page output the php code literally, so I added the <?php tag at the top of the file – wondering why it wasn’t there in the code as given.

    But now something goes wrong with the page: it displays up to the page heading and the introductory text, and then shows ‘Source page:’ and nothing else. Clearly $type must be empty. I’ve double-checked that ‘source_page’ is the correct field name.

    Debug.log contains the following warning, which looks as if it could be significant:
    PHP Warning: session_start(): Cannot start session when headers already sent in /var/www/clients/client54/web203/dev/wp-content/plugins/participants-database/vendor/wp-session-manager/wp-session-manager.php on line 46

    I’d be grateful for any help to get this working!

    My system is as follows:
    Ubuntu 18.04 VPS running ISPConfig, fully updated
    Apache 2.4.29
    MySQL 15.1 (10.1.38-MariaDB)
    PHP 7.2
    WordPress 5.1.1
    Participants Database 1.9.3.2

    The page I need help with: [log in to see the link]

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

    (@xnau)

    Sorry about the missing php tag, it’s assumed, but should have been in there.

    The fact that you’re getting a partial display indicates there is an error that is stopping php execution. An error like that should show up in the error log. I suggest you clear your error log, attempt to load the page, then check the log. That way, you’ll know you have errors that are relevant to the script.

    The one message you do see is possibly a consequence of errors getting printed to the screen, at any rate it isn’t the cause the of the problem, but an effect of the actual problem.

    I don’t see anything wrong with the code you posted, so it’s nothing obvious there.

    You don’t mention how you are accessing the page…your URL must include the access code, in other words, you must use the private link for the record, the template won’t work without that.

    Thanks very much for your helpful response.

    This is a development site, so WP_DEBUG is on, but it is not outputting to the screen. The debug output goes to the debug.log file in wp-content.

    I am using the access code. In the admin ‘List Participants’ page I click on the access code for one of the records, which takes me directly to the Edit Record page for that record, with a URL like this: https://dev.cofe-equal-marriage.org.uk/support-the-campaign/sign-our-letter/open-letter-edit-your-record/?pid=W7K4K

    The relevant part of the HTML output of that pages looks like this:

    <div class="entry-content">
    		<p>If you have lost your private link to access your record, please <a href="https://dev.cofe-equal-marriage.org.uk/support-the-campaign/sign-our-letter/private-link-reminder-request/">click here</a> to request a reminder; your link will be emailed to you.</p>
    <!-- template: equal/templates/pdb-record-usertype.php -->Source page: <!-- end template: equal/templates/pdb-record-usertype.php -->
    	</div>

    That looks complete to me, not as if an error has truncated the output. And the rest of the page (the footer) is displayed correctly.

    It seems that $type is empty when it ought to contain (in the above example) the value sign-our-letter-laity, the slug of the source page, which displays correctly in List Participants. Because $type is empty, the echo do_shortcode commands are never called. So the output is as expected.

    The crucial question must be, why is $type empty?

    By emptying debug.log as you suggested, I have discovered that the error
    [19-Apr-2019 20:59:31 UTC] PHP Warning: session_start(): Cannot start session when headers already sent in /var/www/clients/client54/web203/dev/wp-content/plugins/participants-database/vendor/wp-session-manager/wp-session-manager.php on line 46
    occurs when I load the List Participants page. No further errors are added to debug.log when I access the Edit record page.

    Plugin Author xnau webdesign

    (@xnau)

    OK, well you will need to look at the records in the admin to see if that type value is set in the record. My guess is that it is empty in the record you are testing.

    No, it is correct in all the records – I’ve tried several.

    Plugin Author xnau webdesign

    (@xnau)

    Well, checking on this I see there is an error in the tutorial you based your code on. I’m sorry about that…looks like the property with the record values should be:

    $this->participant_values

    Oh! Yes, with that change it now works fine – thank you. Frustrating that I’ve spent hours struggling with it.

    I see the tutorial page has been corrected now. It didn’t occur to me that the original code might be wrong, as the comments suggested that at least some people had been able to use it successfully. Presumably the plugin coding has been updated since then.

    May I ask your help about something connected? I would like the Private Link, when clicked, to automatically change the corresponding record so that the Approved field is set to ‘yes’. This would make the Private Link verify the email address without the user or the admin needing to do anything else.

    Can this be done by adding some code to the beginning of pbd-record-usertype.php that would change the database record without the user submitting the form? If so, can you tell me how to do this?

    Thanks again for all your help and for such a wonderful plugin. I shall make a donation.

    Phil

    Plugin Author xnau webdesign

    (@xnau)

    The easiest way to have the record updated when someone uses the private link is to use a custom template for the [pdb_record] shortcode. In the custom template, after it checks for the $participant_id value, you can put code to mark the record as approved.

    For example:

    <?php
    Participants_Db::write_participant( array('approved' => 'yes'), $participant_id );
    ?>

    Thank you! That’s unbelievably straightforward. As I already had a custom template I just added two lines at the start:

    <?php
    /*
     * The email address has been verified, so
     * mark the participant as 'approved'
     */
    $participant_id = $this->participant_values['id'];
    Participants_Db::write_participant( array('approved' => 'yes'), $participant_id );
    
    /*
     * First, check for the value that determines what kind of 
     * record edit form to show
     */
    $type = $this->participant_values['source_page'];
    /*
     * Now, show the record edit form for that type
     */
    switch ( $type ) {
       case 'sign-our-letter-laity':
          echo do_shortcode('[pdb_record groups="main,church_of_england,laity"]');
          break;
       case 'sign-our-letter-clergy':
          echo do_shortcode('[pdb_record groups="main,church_of_england,clergy"]');
          break;
       case 'sign-our-letter-anglican-communion':
          echo do_shortcode('[pdb_record groups="main,anglican_communion"]');
          break;
    }
    

    And it just works!

    I couldn’t find a way to donate so I’ve bought a site licence for the Email Expansion add-on, which I shall find useful. Thank you again.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Showing a Record Edit Form Based on a Value in the Record’ is closed to new replies.