Forums

Row count (also in email)

SPABO 20 Jun, 2010
In on submit after email I put a code in which tells the subscriber if he was the first, second etc subsciber

This works fine, but I also would like to have this in an email templates as well

Hope there is a way to do so

This is the code
<? 
$db =& JFactory::getDBO();
$sql = "SELECT * FROM jos_chronoforms_MYFORM"; 
$number = mysql_query($sql);
$number_rows = mysql_num_rows($number);
$total = $number_rows + 1;
?> 
<p> 
You are nr. <? echo $total; ?> who subitted the form. 
</p>
nml375 20 Jun, 2010
Hi,
That code should work just fine within the email templates, just keep in mind that you'll have to disable the html editor ("Use Template Editor" under "Setup Email") for the email template in question when using any kind of php-code.

/Fredrik
SPABO 21 Jun, 2010
That's the problem Frederic,
The emails MUST be in HTML, as I have put in a table where the data from the form is in
This table is used (by copy/paste) by others to create some new excel stuff

Maybe in the the Dynamic Subject ???
I have now in this

<?php
$Wedstrijddatum = JRequest::getString('Wedstrijddatum', date('Y-m-d'), 'post');
JRequest::setVar('subject', 'Nieuwe inschrijving CK P&P 2010 dd '.$Wedstrijddatum);
?>


If I only could see this in the subject:
'Nieuwe inschrijving nr. $total CK P&P 2010 dd '.$Wedstrijddatum);


However I'm getting parse errors !!!
So, I must be doing something wrong...
nml375 21 Jun, 2010
Hi,
What you could do, then, is something like this:

On Submit - before Email:
<?php
$db =& JFactory::getDBO();
$query = "SELECT COUNT(*) FROM " . $db->nameQuote("jos_chronoforms_MYFORM");
$db->setQuery($query);
$total = $db->loadResult() + 1;
JRequest::setVar('total', $total, 'post');

//Also update the email subject, as requested:
$datum = JRequest::getString('Wedstrijddatum', date('Y-m-d'), 'post');
JRequest::setVar('subject', 'Nieuwe inschrijving nr. ' . $total . ' CK P&P 2010 dd ' . $datum, 'post');

?>


Email Template:
...
You are nr. {total} who submitted the form.
...


Written for CF v3.1RC5.5


/Fredrik
SPABO 21 Jun, 2010
Fredrik, I'm impressed, just a small issue, the "subjects" don't show teh "Wedstrijddatum"


<?php
$db =& JFactory::getDBO();
$query = "SELECT COUNT(*) FROM " . $db->nameQuote("jos_chronoforms_CK_PITCHenPUTT");
$db->setQuery($query);
$total = $db->loadResult() + 1;
JRequest::setVar('total', $total, 'post');
//Also update the email subject, as requested:
$datum = JRequest::getString('Wedstrijddatum', date('Y-m-d'), 'post');
JRequest::setVar('subject', 'Nwe.inschrijving nr. ' . $total . ' CK P&P 2010 dd ' . $Wedstrijddatum, 'post');
?>
<?php
$db =& JFactory::getDBO();
$query = "SELECT COUNT(*) FROM " . $db->nameQuote("jos_chronoforms_CK_PITCHenPUTT");
$db->setQuery($query);
$total = $db->loadResult() + 1;
JRequest::setVar('total', $total, 'post');
//Also update the email subject, as requested:
$datum = JRequest::getString('Wedstrijddatum', date('Y-m-d'), 'post');
JRequest::setVar('subject_1', 'Uw inschrijving nr. ' . $total . ' CK P&P 2010 dd ' . $Wedstrijddatum, 'post');
?>
nml375 21 Jun, 2010
Hi,
Please notice that I used $datum as variable name, not $Wedstrijddatum (though the value is retrieve from the 'Wedstrijddatum' form field). If you'd prefer using $Wedstrijddatum, you'll have to alter this line accordingly as well:
$datum = JRequest::getString('Wedstrijddatum', date('Y-m-d'), 'post');


Also, I'm not sure why you've got the same code twice...
If you need to set the value to both 'subject' and 'subject_1' form field values, just add a second JRequest::setVar(), there's no point in re-fetching the other values...

/Fredrik
SPABO 22 Jun, 2010
Apologies Fredrik, it should have been $datum and not $Wedstrijddatum
I'm using this twice (subject end subject_1) as there is a small difference in the subject send to
Subscriber (confirmation mail) and Receiver(s) (Notification mail)

Now, and maybe I'm overasking, I would like to explore if it is possible to relate the "counter"to a selected "Wedstrijddatum"

If selected date 1, it starts counting from nbr. 1 onwards
But if selected date 2, it should again start counting from nbr 1..

The reason for asking:
In this way I can keep all the data in de table and make a full csv download for a whole competitionseason.

I tried to put this in, but this does not work at all


//obtain selected "Wedstrijddatum" from the db
$datum = $_POST["Wedstrijddatum"]; 

// Then add this date to teh query 
$query = "SELECT * FROM jos_chronoforms_CK_PITCHenPUTT WHERE Wedstrijddatum =".$datum.;  
This topic is locked and no more replies can be posted.