Forums

combine 2 fields and use a dynamic mail name

chuanse 29 May, 2014
Hello,

so I have a form where {firstname} and {lastname} are among the variables.
They appear fine in the html mail body and the thank you page.

Since the dynamic from field in the email action is not accepting "firstname lastname" I am trying to combine the both.

I added custom code in the onsubmit event as first action, it is set to controller mode.

I tried different aproaches, but I don't get it to work.... I also made a hidden field in the form with the variable "name".


<?php
$_POST['name'] = $_POST['firstname'] & ." ". & $_POST['lastname'];
?>


<?php
$_POST['firstname'] = $firstname;
$_POST['lastname'] = $lastname;
$name = $firstname .' '. $lastname
$_POST['name'] = $name
?>


<?php
$_POST['firstname'] = $firstname;
$_POST['lastname'] = $lastname;
$name = $firstname .' '. $lastname
$form->data['name'] = $name
?>


Any suggestions?

Thanks in advance
GreyHead 30 May, 2014
Hi chaunse,

Your last example should work if you then put name in the Dynamic From box. Please see this FAQ

Bob

PS I strongly recommend that you do *not* use the Dynamic From Email element in your Email Setups. Using this often results in your emails being marked as spam and dropped into a spam filter. Instead use the static From Email with an address that matches the site domain name and use Dynamic ReplyTo Email for the user email. The result is the same but with a much better chance of good delivery.
chuanse 30 May, 2014
Hello Greyhead,

thank you for your response.

Going with the last example


<?php
$_POST['voornaam'] = $firstname;
$_POST['familienaam'] = $lastname;
$name = $firstname .' '. $lastname;
$form->data['naam'] = $name;
?>


=> does not seem to work.

I have a second piece of code in a separate action which should combine de mailsubject with the combined name

<?php
$mailonderwerp = "Aanvraag overmacht examen ";
$_POST['naam'] = $naam;
$mailonderwerpmetnaam = $mailonderwerp .' '. $naam;
$form->data['mailonderwerp_naam'] = $mailonderwerpmetnaam
?>


For diagnostic purpose I configured the thank you page to show the variables output.


naam= {naam} <br>
name= {name} <br>
firstname= {firstname} <br>
lastname= {lastname} <br>
mailonderwerp_naam= {mailonderwerp_naam} <br>
mailonderwerpmetnaam= {mailonderwerpmetnaam} 


The only output i get is:

naam=
name=
firstname=
lastname=
mailonderwerp_naam= Aanvraag overmacht examen
mailonderwerpmetnaam=



... which makes me think that the data from my custom code events are placed into the session, but I am NOT receiving the $_POST data :/
And I just do not onderstand why...

I added session-to-data event before the custom code actions and data-to-session action after the custom code events.. Makes no difference at all :/
chuanse 30 May, 2014
ps: should i have a hidden field 'naam' & a hidden field 'mailonderwerp_naam'...
I have those as last 2 fields after the submit button in the formfields page (preview)
GreyHead 30 May, 2014
Answer
1 Likes
Hi chuanse,

I'm really not clear what you re trying to do here . . .

This code won't work because it's the wrong way round
$_POST['firstname'] = $firstname;
I think you meant
$firstname = $_POST['firstname'];


But you don't need to use $_POST as ChronoForms puts those values into the $form->data array for you.

I suggest that you check the FAQ again.

Bob
chuanse 30 May, 2014
1 Likes
Sjees, i made it way to complicated.... Just read the faq you made Greyhead... it is golden😉

<?php
$form->data['naam'] = "{$form->data['voornaam']} {$form->data['familienaam']}";
?>


and for the mail subject
<?php
$form->data['mailonderwerp_naam'] = "Aanvraag overmacht examen  {$form->data['naam']}";
?>


Thank you!!
This topic is locked and no more replies can be posted.