Need serious help with php template

I’m using a Participant Database template (a plugin for WordPress) to write out a record for people signing up for the Earth Day Challenge. The basic template works fine, except I want to get it to add up points based on whether people check off a one-time action, and indicate the no. of days they do a daily action during the Challenge. There are about 50 possible actions, so doing it manually is a bit time consuming.

I can’t seem to get it to work, i.e. syntax errors. I have no access to the parent code. Here’s what I have. Anything that mentions Points is my addition. Thanks!

<div class="wrap <?php echo $this->wrap_class ?>">

  <?php
  /*
   * as of version 1.6 this template can handle the display when no record is found
   * 
   * 
   */
  if ( !empty( $this->participant_id ) ) :
    ?>

    <?php // output any validation errors
    $this->print_errors();
    ?>

    <?php
    // print the form header
    $this->print_form_head()
    ?>
    
    <?php 
    // initialize the points 
    $calc_points_one_time_actions=0; ?>
    <?php $calc_points_daily_actions=0; ?>
   
    
    <?php while ( $this->have_groups() ) : $this->the_group(); ?>
      <?php $this->group->print_title() ?>
    <?php $this->group->print_description() ?>

      <table  class="form-table">

        <tbody class="field-group field-group-<?php echo $this->group->name ?>">

          <?php
          // step through the fields in the current group

  while ( $this->have_fields() ) : $this->the_field();
            ?>

            <tr class="<?php $this->field->print_element_class() ?>">
                
            <?php if ( $this->group()==$points && $this->field()==$this->field->points_for_one_time_actions) : ?> {
                <tr>
                    <th for="<?php $this->field->print_element_id() ?>"><?php $this->field->print_label() ?></th>
                    
                    <td>
                    <?php> $this->field->points_for_one_time_actions = $calc_points_one_time_actions; ?>    
                    <?php> $this->field->print_points_for_one_time_actions() ?>
                    </td>
                </tr>
                }

                <?php elseif ($this->group()==$points && $this->field()==$this->field->points_for_daily_actions) : ?> {
                <tr>
                    <th for="<?php $this->field->print_element_id() ?>"><?php $this->field->print_label() ?></th>
                    
                    <td>
                    <?php> $this->field->points_for_daily_actions = points_for_daily_actions; ?> 
                    <?php> $this->field->print_points_for_daily_actions() ?>
                    </td>
                </tr>
                }

                <?php elseif ($this->group()==$points && $this->field()==$this->field->total_points) : ?> {
           
                <tr>
                     <th for="<?php $this->field->print_element_id() ?>"><?php $this->field->print_label() ?></th>
                    
                    <td>
                    <?php> $this->field->total_points = $this->field->points_for_one_time_actions + $this->field->points_for_daily_actions; ?> 
                    <?php> $this->field->print_total_points() ?>
                    </td>
                </tr>
                }
            <?php else : ?>
            <tr>
              <th for="<?php $this->field->print_element_id() ?>"><?php $this->field->print_label() ?></th>
              <td>

                <?php $this->field->print_element_with_id(); ?>

                <?php if ( $this->field->has_help_text() ) : ?>
                  <span class="helptext"><?php $this->field->print_help_text() ?></span>
                <?php endif ?>
               </td>   
            </tr>
            <?php endif ?>   
           
            <tr>
                <td>
                <?php if( $this->group()==$one_time_activities && $this->field->value()==("Completed")) {
                $calc_points_one_time_actions = $calc_points_one_time_actions + 25; }
                ?> 

                <?php if( $this->group()==$daily_activities)
                $calc_points_daily_actions = $calc_points_daily_actions + ($this->field->value() * 10);
                ?> 

                </td>
              
            </tr>

    <?php endwhile; // field loop  ?>
   
        </tbody>

      </table>

  <?php endwhile; // group loop  ?>
    <table class="form-table">

      <tbody class="field-group field-group-submit">

    <tr>  
        <th><h3>
          <?php $this->print_save_changes_label() ?>
        </h3></th>
          <td class="submit-buttons">
  <?php $this->print_submit_button( 'button-primary' ); // you can specify a class for the button, second parameter sets button text  ?>
          </td>
        </tr>

      </tbody>

    </table><!-- end group -->

    <?php $this->print_form_close() ?>

  <?php else : ?>

    <?php $error_message = Participants_Db::plugin_setting( 'no_record_error_message', '' );

    if ( !empty( $error_message ) ) :
      ?>
      <p class="alert alert-error"><?php echo $error_message ?></p>

    <?php endif ?>

<?php endif ?>

</div>

Well, you are having issues, but, what are they? What can’t you get to work? We can’t help you if you if you don’t tell us what does not work…

I get a critical error message, but I can’t tell you which part of the program is bad. The whole record is not printing. I imagine it’s some kind of syntax error. It prints fine without all the Points stuff I added, so you can just look at the sections with Points in it. I just included the whole template file for a bigger picture view.

Well, you get an error message! What is it???

We can’t help you without more info…

I can try adding in a section of the code at a time, and see if I can narrow it down.

Just tell us what the “critical error message” was…

Hi, The last couple of days I learned to add one line of code at a time, and test it out first.
That’s how I figured out which variable is which. Here’s what I added to the existing template. I tried adding endif but it has major objection to my adding that. My problem here is it’s not recognizing the if statement.

            <php if ( $this->group->title()=="Daily Actions")  {
            <?php $this->group->print_title(); ?>
            <?php print "Test 5"; ?>
            <?php $this->field->print_value(); ?> 
            } ?>

Here’s what the output looks like.

The question is how to get it to recognize the if condition.

Well, I will guess, without seeing your code, that you are creating the “$this->group-title()” from a class or another object. In this case, it is an OBJECT and not a text field. And, could be an indexed value.
Also, the four lines you showed us use functions for printing. To be able to know how to help you,
we would need to know the layout of these or how the data is created in the first place.

Sponsor our Newsletter | Privacy Policy | Terms of Service