Working with incrementCounterField

10 posts by 3 authors in: Forums > CMS Builder
Last Post: February 15, 2012   (RSS)

Hi All,

I thought this would be pretty easy, but I’ve run into a snag.

I have an RSVP form attached to the detail viewer for the meeting records in a table called e_blast_meeting_notice,

At present, the form triggers the sending of an email to the meeting planner including all the information entered. That's working fine.

To give my client a automatic tally of how many attendees there might be for each meeting, I was thinking of using the incrementCounterField function to increment a field called “attending” in the meeting record:
1) if the responder said that they were attending, and
2) to reflect any additional guests that they were bringing to the meeting.

The fields in the form are:
<tr>
<td<label>Will you be able to attend this month's meeting?</label></td>
<td><select name="attend">
<OPTION SELECTED VALUE="">...Select...</OPTION>
<option >Yes, I will be attending the <?php echo date("F jS", strtotime($e_blast_meeting_noticeRecord['meeting_date'])) ?> meeting.</option>
<option >Sorry, I won't be able to make it to the <?php echo date("F jS", strtotime($e_blast_meeting_noticeRecord['meeting_date'])) ?> meeting.</option>
</select></td>
</tr>

<tr>
<td><label>If you'll be bringing guests, enter the number joining you.</label></td>
<td><input type="text" name="guests" id="guests" value="" /></td>
</tr>

So far I’ve defined variables called $meeting and $attending as:
<?php $meeting = date("F jS", strtotime($e_blast_meeting_noticeRecord['meeting_date']));
$attending = @$_POST['attend']; ?>

I thought that using the following would increment the “attending” field, if the responder was attending (I was wrong):
<?php if ($attending == 'Yes, I will be attending the $meeting meeting.') { incrementCounterField('e_blast_meeting_notice', 'attending', $e_blast_meeting_noticeRecord['num']);
} ?>


I'm not sure how to approach the additional guests part.

Any ideas?

Thanks,

Jerry Kornbluth
The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php

Re: [gkornbluth] Working with incrementCounterField

By (Deleted User) - February 9, 2012

Hi Jerry,

In order to detect when a value has been selected, you need to set a value for each option (normally something straightforward like '1' or '0', or 'yes' and 'no').

If you try this:
<tr>
<td>
<label>Will you be able to attend this month's meeting?</label>
</td>
<td>
<select name="attend">
<option value="">...Select...</OPTION>
<option value="yes">Yes, I will be attending the <?php echo date("F jS", strtotime($e_blast_meeting_noticeRecord['meeting_date'])) ?> meeting.</option>
<option value="no" >Sorry, I won't be able to make it to the <?php echo date("F jS", strtotime($e_blast_meeting_noticeRecord['meeting_date'])) ?> meeting.</option>
</select>
</td>
</tr>

<tr>
<td>
<label>If you'll be bringing guests, enter the number joining you.</label>
</td>
<td>
<input type="text" name="guests" id="guests" value="" />
</td>
</tr>



<?php if ( @$_REQUEST['attend'] == "yes" ) { incrementCounterField('e_blast_meeting_notice', 'attending', $e_blast_meeting_noticeRecord['num']); } ?>


By adding values to the options in the select field, we can look for a value when the form is submitted (in this case we don't use another variable to get the value, we just check directly).

If you want to have people submit a number of additional guests, simply add a form field (called 'guests', for example) which allows people to type in (or select) the number of guests that they will be bringing and whose value is an integer.

On form submission, you can check the number and then run the incrementCounterField like this:
<?php
if ( @$_REQUEST['guests'] ) {

for ( $i = 0; $i < $_REQUEST['guests']; $i++ ) {
incrementCounterField('e_blast_meeting_notice', 'attending', $e_blast_meeting_noticeRecord['num']); }
}

}
?>


The above will run incrementCounterField once for each guest.

This is just an example, there are other solutions that are more elegant.

Let me know if this helps,

Tom

Re: [Tom P] Working with incrementCounterField

Sorry Tom,

Thanks for the detailed reply, but the code you suggested didn’t work.

I don’t know how to see what’s actually going on, but here’s what I was able to find:

1) The function increments the count in the “attending” field without the if statement as in: <?incrementCounterField('e_blast_meeting_notice', 'attending', $e_blast_meeting_noticeRecord['num']); ?>

2) it doesn’t increment with: <?php if ( @$_REQUEST['attend'] == "yes" ) { incrementCounterField('e_blast_meeting_notice', 'attending', $e_blast_meeting_noticeRecord['num']); } ?>

Or with this code ( with the extra closing brace removed):
<?php
if ( @$_REQUEST['guests'] ) {

for ( $i = 0; $i < $_REQUEST['guests']; $i++ ) {
incrementCounterField('e_blast_meeting_notice', 'attending', $e_blast_meeting_noticeRecord['num']); }
}

?>

3) The value in the email is now either “yes” or “no”instead of the verbose,
“Yes, I will be attending the <?php echo date("F jS", strtotime($e_blast_meeting_noticeRecord['meeting_date'])) ?> meeting.”, or
“Sorry, I won't be able to make it to the <?php echo date("F jS", strtotime($e_blast_meeting_noticeRecord['meeting_date'])) ?> meeting.”

I hope it's something really simple,

Jerry Kornbluth
The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php

Re: [Tom P] Working with incrementCounterField

Hi Tom,

Duh, I forgot about showme...

I think I see what the problem is now. (just don't know how to fix it )

The form action is normally <form action="http://www.artistsofpalmbeachcounty.org/meeting-RSVPphp.php"> which is the page that checks a captcha entry in the form and sends emails to the submitter and the program person.

I changed the form action to "?" so that the form would remain in the browser after submission and the number in the "attending" field was incremented as you said it would be. However, since the form data never gets to the other page, there's no email and no captcha check.

Any ideas?

I've attached both pages.

Jerry Kornbluth
The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php
Attachments:

meeting-rsvpphp.php 14K

rsvp4.php 10K

Re: [Tom P] Working with incrementCounterField

By gkornbluth - February 10, 2012 - edited: February 13, 2012

Hi Tom,

OK, I thought I had cobbled together some JavaScript functions that would work, but again knowledge trumps cobbling, and it didn't.

First, I defined 2 functions:
<script type="text/javascript">
function function1() {
action ="?";
}
function function2() {
action ="http://www.artistsofpalmbeachcounty.org/meeting-RSVPphp.php";
}
</script>

and then in the opening form tag used:
<form method="post" onSubmit="function1();function2()" >

I hope I'm getting closer...

Thanks,

Jerry Kornbluth
The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php

Re: [gkornbluth] Working with incrementCounterField

By Jason - February 14, 2012

Hi Jerry,

Probably the easiest solution would be to:

- keep the action of the form to still submit the form to meeting_RSVPphp.php
- In the form, have a hidden field that stores the record number of the meeting record being viewed ie
<input type = "hidden" name = "recordNum" value = "<?php echo $e_blast_meeting_noticeRecord['num'];?>" />

- on meeting_RSVPphp.php, put in the incrementCounterField code, using the $_REQUEST['recordNum'] coming from the previous form.

Hope this helps
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

Re: [Jason] Working with incrementCounterField

Hi Jason,

Thanks for the direction.

It worked perfectly. And a much simpler approach for this implementation.

Just curious...

What was I doing wrong in the JavaScript idea that kept it from working?

Jerry
The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php

Re: [gkornbluth] Working with incrementCounterField

By Jason - February 15, 2012

Hi Jerry,

If I'm reading your javascript correctly, you were trying to have the form first submit to it's current page, and then submit to a second page. This can't work, since once the form submits, execution on the client side stops. The result you were probably seeing is that you were always kept on the same page. function2 was never being executed.

Hope this helps
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

Re: [Jason] Working with incrementCounterField

Hi Jason,

Thanks for taking the time to pass on the explanation.

Jerry
The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php