Forums

Dynamic subject fields with custom text

Mgringo 11 Jan, 2013
Hi,

Is it possible to combine a dynamic subjectfield with custom text?

example "Your car will be picked up on {date}"

Thanks!
Marcel
Mgringo 11 Jan, 2013
Found it๐Ÿ™‚
<?php
$form->data['subject'] = "Some text {$form->data['input_name']} some more text";
?>

Than type 'subject' in dynamic field
rodsdesign 04 Sep, 2013
Hi guys,

Loving 4.0 but pretty frustrated with this part of it... I know its going to be something really easy...

Form Fields:
First Name (first_name)
Last Name (last_name)

Trying to combine those two fields into full_name (which is a hidden field in the form)

the code I'm using is:
$form->data['full_name']="{$form->data['first_name']  $form->data['last_name']}";


then i'm putting full_name in the dynamic from name field (no curly brackets).

no joy๐Ÿ˜Ÿ I'm trying this with several fields - so if I can get one working - I can get them all๐Ÿ™‚

thanks
GreyHead 05 Sep, 2013
Hi rodsdesign,

I think that this is a PHP syntax question. Apologies for the slightly long answer.

There are several ways of mixing PHP and HTML; and here the space in the middle is HTML:

You can use quotes to go into and out of PHP:
$form->data['full_name'] = $form->data['first_name'].' '.$form->data['last_name'];
which is fine for a short clause like this.

Or you can use double quotes round the whole clause and use {} to mark out each PHP variable (they must begin with a $ for this to work, and each variable has it's own set of brackets:
$form->data['full_name'] = "{$form->data['first_name']} {$form->data['last_name']};
This makes for much easier reading when you have moderately complex clauses. This is my preferred format.

Note that the clause must be in double quotes - if you use single quotes then PHP will not parse the clause to find the variables and will treat the whole thing as a literal string.

Bob

PS There's also a HEREDOC syntax and there is a style where you duck in and out of ?> <?php echo tags which I find messy and hard to read.
This topic is locked and no more replies can be posted.