Forums

On Submit code - before sending email

blue 14 Oct, 2009
Hi, I'm need to modify a value of a field before sending the email,
and I tried to modify the value on the $_POST var but when I recieve
the email the value is the original one (empty) and not the new one (a sum of values).

The new value is a sum from the values inserted in the form and
in the form is a hidden input field (final_value).

On Submit code - before sending email:

<?php
$_POST['final_value'] = $_POST['value_1'] + $_POST['value_2'];


Any one can help me on this?
Is this the way to do this modification?

thanks
GreyHead 14 Oct, 2009
Hi blue,

That looks OK but I think that there is a sequencing problem* in using this substitution in the email code. The workaround is to put a placeholder like ##final_value## in the email template and then search and replace this value in the OnSubmit Before Box.
<?php
$final_value = JRequest::getVar('value_1', 0, 'post) + JRequest::getVar('value_2', 0, 'post);
  $emails[0]->template = str_replace('##final_value##', $final_value, $emails[0]->template);
?>


Bob

* The variable substitution in the email text is done before the OnSubmit Before code executes.
blue 19 Oct, 2009
Hi Bob,
thanks for the tip, it results fine🙂
blue 25 Nov, 2009
Hi,

I was using the $email variable to replace some text in the template in the "On Submit code - before sending email:" like this:


for($i=0;$i<count($emails);$i++){
	$emails[$i]->template = str_replace('{_tipo}', $tvalues['tipo'], $emails[$i]->template);
	$emails[$i]->template = str_replace('{_grupo}', $tvalues['grupo'], $emails[$i]->template);
	$emails[$i]->template = str_replace('{_valor_sem_iva}', number_format($tvalues['valor_sem_iva'], 2, ',', ' '), $emails[$i]->template);
	$emails[$i]->template = str_replace('{_taxa_adene_sem_iva}', number_format($tvalues['taxa_adene_sem_iva'], 2, ',', ' '), $emails[$i]->template);
	$emails[$i]->template = str_replace('{_valor_final_com_iva}', number_format($tvalues['valor_final_com_iva'], 2, ',', ' '), $emails[$i]->template);

	$emails[$i]->template = str_replace('{_tipo_de_imovel}', $tmvalue, $emails[$i]->template);
	$emails[$i]->template = str_replace('{_resposta}', $rvalue, $emails[$i]->template);
}


but now with the ChronoForms_V3.1_RC5 the $email variable seems to be NULL or empty,
this variable has change?
is there any other way to do this?

many thanks in advance
This topic is locked and no more replies can be posted.