Dynamic Subject in J1.7 (V4)

SPABO 22 Jan, 2012
I have put this code in Custom code Before sending emails
<?
$db =& JFactory::getDBO();
$pst = "SELECT COUNT(*) AS %s FROM %s
  WHERE %s = %s";
$query = sprintf(
  $pst,
  $db->nameQuote('items'),
  $db->nameQuote('j17_chronoforms_data_Test2'),
  $db->nameQuote('Wedstrijddatum'),
  $db->Quote(JRequest::getString('Wedstrijddatum')));
$db->setQuery($query);
$result = $db->loadObject();
$total = $result->items+1;
JRequest::setVar('total', $total, 'post');

?>
<?php
$Wedstrijddatum = JRequest::getString('Wedstrijddatum');
JRequest::setVar('subject', 'Nr. ' . $total . ' Nieuwe inschrijving Pitch en Puttwedstrijd dd '.$Wedstrijddatum);
?>

<?php
$Wedstrijddatum = JRequest::getString('Wedstrijddatum');
JRequest::setVar('subject_1', 'Nr.'. $total . ' Uw inschrijving Pitch en Putt wedstrijd dd ' . $Wedstrijddatum);
?>


And resp "subject" abd "subject_1" in teh email tabs DYNAMIC

However, it does not work
GreyHead 22 Jan, 2012
Hi SPABO,

It won't work because you have an error in your code. What value do you expect in $result->items ??? And why isn't it there?

Bob
SPABO 22 Jan, 2012
Hmmm Bob, it's your own code you supplied me some time ago
Max_admin 22 Jan, 2012
Hi SPABO,

What are you trying to do here exactly ?

Regards,
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
SPABO 22 Jan, 2012
This code works perfectly in V3 (Joomla 1.5)

It should count the number of rows in the table, and it should be in teh subject of the emails
SPABO 23 Jan, 2012
Hi Max,

To put it in a better way:

This code should count from a table called j17_chronoforms_data_Test2:

Nbr of Records, which hold the selected(posted) "Wedstrijddatum"

(The form contains a fielname "Wedstrijddatum", this is a selectbox)
GreyHead 23 Jan, 2012
Hi SPABO,

From the style used that's Frederik's code maybe, not mine.

Try replacing
JRequest::setVar('total', $total, 'post');
with
$form->data['total'] = $total;
as ChronoForms v4 only reads the posted variables once, after that it uses it's own internal $form->data array.

Bob
SPABO 23 Jan, 2012
Hi Bob, I belief you are correct, it was Frederic's !

Tried the following:
<?
$db =& JFactory::getDBO();
$pst = "SELECT COUNT(*) AS %s FROM %s
  WHERE %s = %s";
$query = sprintf(
  $pst,
  $db->nameQuote('items'),
  $db->nameQuote('j17_chronoforms_data_Test2'),
  $db->nameQuote('Wedstrijddatum'),
  $db->Quote(JRequest::getString('Wedstrijddatum')));
$db->setQuery($query);
$result = $db->loadObject();
$total = $result->items+1;
$form->data['total'] = $total;
?>


However, no success. Hope it will work again as I have quite some forms with this code
Max_admin 23 Jan, 2012
Hi,

Try to replace:


$result = $db->loadObject();
$total = $result->items+1;
$form->data['total'] = $total;


with:


$result = $db->loadResult();
//$total = $result->items+1;
$form->data['total'] = $result + 1;


does that work ? how do you check it ? do you have {total} in your email template ? or do you use the debugger ?
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
SPABO 24 Jan, 2012
Hi Bob,
I belief the problem could also be to get the (dynamic) subject in the email
This is the Custom code on teh event : On Submit

<?php
$Wedstrijddatum = JRequest::getString('Wedstrijddatum');
JRequest::setVar('subject', 'Nr. ' . $total . ' Nieuwe inschrijving Pitch en Puttwedstrijd dd '.$Wedstrijddatum);
?>


If I fill in subject in the dynamic part of the email event, it replies "DEFAULT SUBJECT"
GreyHead 24 Jan, 2012
Hi SPABO,

Please see this post from earlier in this thread. You need to make the same change here.

Bob
SPABO 24 Jan, 2012
I don't have a clou..

Like this??


<?php
$Wedstrijddatum = JRequest::getString('Wedstrijddatum');
$form->data('subject', 'Nr. ' . $total . ' Nieuwe inschrijving Pitch en Puttwedstrijd dd '.$Wedstrijddatum);
?>
GreyHead 24 Jan, 2012
Hi SPABO,

Time to get a clue . . .

Does that look like the code I posted earlier? (No) More importantly, does it work?? (No)

Bob
SPABO 24 Jan, 2012
Okay, a small step further
This is the code to get de subject in the dynamic part

<?php
$form->data['subject'] = '`Dear etc etc - '.$form->data['datum'].' '.$form->data['total'];
?>


It shows the text, the "datum" , but not "total"
GreyHead 24 Jan, 2012
Hi SPABO,

You don't need to be an expert, just apply a little logic.

Bob
SPABO 24 Jan, 2012
:D 😀 😀 😀 😀

Hey Bob,

Problem is now tackled, pls find the complete code

<?
$db =& JFactory::getDBO();
$pst = "SELECT COUNT(*) AS %s FROM %s
  WHERE %s = %s";
$query = sprintf(
  $pst,
  $db->nameQuote('items'),
  $db->nameQuote('j17_chronoforms_TEST3'),
  $db->nameQuote('datum'),
  $db->Quote(JRequest::getString('datum')));
$db->setQuery($query);
$result = $db->loadObject();
$total = $result->items+1;
$form->data['total'] = $total;
?>

<?php
$form->data['subject'] = 'Uw inschrijving P&P wedstrijd dd - '.$form->data['datum'].' U bent nr. '.$form->data['total'];
?>
<?php
$form->data['subject_1'] = 'Nwe.inschrijving P&P wedstrijd dd - '.$form->data['datum'].' Nr. '.$form->data['total'];
?>


This isssue is now tackled Bob,

Thanks for letting me thinklightbulb lightbulb
This topic is locked and no more replies can be posted.