Forums

Replacing in formatted text with php

jimmyt 02 Mar, 2016
Hi,

I have a form with some input elements and some formatted text elements. I am able to tweak the input elements with php code in a custom handler for the on load event (using $form->data['...']). I would also like to tweak some formatted text elements (based on the logged in user, so it has to be done at run time). Is there a way to modify formatted text elements using php in a custom handler for the on load event?

Thanks
Jimmy
jimmyt 02 Mar, 2016
(I chose Chronoforms v3, but should have chosen Chronoforms v4; no way to change that?)
GreyHead 02 Mar, 2016
1 Likes
Hi Jimmy,

ChronoForms v3 doesn't run on Joomla 3 as far as I know so I'm not sure what you are using. You should probably download and install CFv5

You can use PHP in a Custom Code element to alter the values, just make sure that you save the final value back to an entry in the $form->data[''] array so that you can use it in the email template.

Bob
jimmyt 02 Mar, 2016
Thank you for the reply. I am indeed using Chronoforms v4 (I wanted to change the produce I selected in the original message but could not figure out why. Anyway, minor detail).

formatted text elements don't seem to show up in $form->data[''], as far as I can tell? I did a print_r on $form, and it's rather large, so perhaps I am missing something. I tried (all I need is to replace a value with something else)

$form->form_details['content'] = str_ireplace($replace, $with,  $form->form_details['content']); 


but that did not work.
jimmyt 02 Mar, 2016
The following did work:


$form->form_details->content = str_ireplace($replace, $with,  $form->form_details->content);


However, it looks like I would also need to modify the email's text. Is there a better way to do this so that I only have to replace once?
jimmyt 03 Mar, 2016
Hmm, I have been able to explicitely replace the content of the email template with

$form->form_actions[2]->content1 = str_ireplace($replace, $with,  $form->form_actions[2]->content1);


I would assume that the index in form_actions[2] is dependent on the number/ordering of the events of the form.

I do this in an On Submit event handler. It works fine. Is this the best way to do this?
GreyHead 04 Mar, 2016
Hi Jtalbot,

if you have {other} in the email template then you can use a Custom Code action before that with code like this:
<?php
if ( $form->data['xxx'] == 'aaa' ) {
  $form->data['other'] = 'This';
} else {
  $form->data['other'] = 'That';
}
?>

Bob
This topic is locked and no more replies can be posted.