[SOLVED] How to replace a checkbox value by another one

shemzone 14 Feb, 2009
Hi there and out there.
Here is why I pull my hair:
I run J!1.5.9 and CF 3.0 stable
CF is set to:
[list]Saving Data/Emails order: Before Email
ChronoForms handle my posted arrays: Yes [/list]

I have a form wich contains a checkbox sending "Yes" if checked (to ask a user if he agrees to receive a newsletter). This checkbox is unchecked by default.
I want to have this information (unchecked) in the email sent to the customer care. But if the checkbox is not checked, the value is empty (normal)
So my idea was to add the following to the "On Submit code - before sending email":
if (JRequest::getVar('ReceiptActuForHom')==NULL){
JRequest::setVar('ReceiptActuForHom','Non','post');
}

But, if the value "no" is well recorded to the db, it's never sent in the email.
I tried also with $rows[0]->ReceiptActuForHom= 'Non', same result.

In debug mode, when the checkbox is checked (actually filled by "yes"), it appears correctly in the debug array list and sent in the email. If not checked, the field is not display as its value is NULL and not sent in the email, even as "NULL" or "undefined".
Any idea (excepting Javascript) to force to set the field to "No" if the checkbox "Yes" remains unchecked?

Thanks a lot for any hints.
Cheers
Fred
Max_admin 16 Feb, 2009
Hi Fred,

try this code :

    if (!JRequest::getVar('ReceiptActuForHom')){
    JRequest::setVar('ReceiptActuForHom','Non');
    }


Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
shemzone 16 Feb, 2009
Hi Max,
thanks for the reply. :-)
I inserted your code in "On Submit code - before sending email" box but still the same:
The result is well recorded ("Oui" or "Non") in the db but is not sent in the email. If the checkbox is not checked, the var {ReceiptActuForHom} remains empty

If you can get a clue, here is what I wrote in the "before..." box:
<?php
//Pour enregistrer la liste des checkbox selectionnées dans la base
JRequest::setVar('InterestName', implode(", ", JRequest::getVar('InterestName')));
// From Max from Chronoengine - 2009-02-16:
 if (!JRequest::getVar('ReceiptActuForHom')){
    JRequest::setVar('ReceiptActuForHom','Non');
 }
?>


And the guilty field in my html form:
<input name="ReceiptActuForHom" id="ReceiptActuForHom" type="checkbox" value="Oui" /> <strong>Oui</strong>, je veux bien


Do you notice something wrong in this?
Max_admin 16 Feb, 2009
Nothing looks wrong, show me the source code of the "email template" ? there is a small "html" button to show your the source!

if its not a big problem for you then you may try to upgrade to V3.1 and let me know!

Regards
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
shemzone 17 Feb, 2009
Hi Max.
Here is the HTML source of the email tmpl:

<p><img src="templates/shemzone/images/logo01.png" border="0" width="175" height="66" /></p>
<p>Bonjour {RegCivility} {RegFirstName} {RegLastName},</p>
<p>Vous avez envoyé une demande de contact le {submitDate} à For'Hom Coiffeur-Barbier et nous vous en remercions.</p>
<p>Nous avons noté que vous êtes intéressé par : {InterestName}</p>
<p>Vous avez connu For'Hom par : {RegPopularity}</p>
<p>Vous avez écrit le message suivant : {Extrainfo}</p>
<p>A notre proposition de recevoir des actualités de notre part, vous avez répondu : {ReceiptActuForHom}</p>
<p>Votre adresse email {RegEmail} ne sera utilisée que pour vous répondre et pour vous envoyer nos actualités si vous avez choisi "Oui" pour cette option.</p>
<p>A bientôt et ne manquez pas de visiter notre site www.mysite.com</p>


Anyway, it's should not a big deal to upgrade to 3.1 as the website is not yet open and I could also use 2 radio buttons (yes/no) instead of one checkbox, but I think this is more elegant.
Merci
Fred
GreyHead 17 Feb, 2009
Hi shemzone, Max,

I think that this is the sequence problem with v3.0. The email substitution has already been done before the OnSubmit code runs so changing values with setVar only affects the databse save.

We've worked round this before by using a place-holder like ##var_name## in the email template and then doing a replace with php.

Bob
shemzone 17 Feb, 2009
Hi Bob and Max
I upgraded to 3.1 with same results. By the way, I noticed you changed the way the arrays are handled as the implode function is useless and gives back an eval() error when it's used in "before box".

We've worked round this before by using a place-holder like ##var_name## in the email template and then doing a replace with php.
Bob


Bob, could you be more explicit please. Do you have an example that I could use to modify my email tmpl?
Thanks
Fred
shemzone 17 Feb, 2009
:D Solved then!
Thanks Bob and Max for your great support!

To anyone who could be in my case:

On Submit code - before sending email code:
<?php
if (!JRequest::getVar('ReceiptActuForHom')){
    JRequest::setVar('ReceiptActuForHom','Non');
 }
$emails[0]->template = str_replace('##ReceiptActuForHom##',JRequest::getVar('ReceiptActuForHom'),$emails[0]->template);
?>

Somewhere in the email template:
##ReceiptActuForHom##

Done

Fred
Max_admin 18 Feb, 2009
Hi Bob, Fred,

I have made a fix for this so it works without placeholders, it will be available in the next update!

Thanks!
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
This topic is locked and no more replies can be posted.