83 Posts
squareweb
5 years ago
Topic

Hi,


I do have an issue with using a pre-filled form-field in the email-field.


Short version: 

Is it possible to use a form-field with storage-type "none", pre-fill it with before-render-code, and use this in the e-mail-field as content like #fieldname#???


Explanation:

I wonder if it is possible to use the content of a pre-filled form-field (Textarea, storage: none) in an e-mail-field e.i. I'd like to compose an e-mail with form-fields.

When I pre-fill the form-field before sending the pre-filled text is visible in the form But is not visible in the e-mail received.


If I do not pre-fill the field (remove the before-render field/code)  but type in some text in it, it works fine, the content is visible in the email received...

All other "regular" form fields are visible in the e-mail.

I've used all different ways to show the content of the pre-filled field in the email like: #fieldname#, $cck->getValue('fieldname') and $cck->getText('fieldname')....

I do fill the field with beforeRender-field-type (code-pack).


See my before-render code below which pre-fills the form-field (I've excluded the DB-retreival part) :

$fields['frm_mail_aanmeld_kop']->form = $row['0']->tr_mail_aanmeld_kop; 

$fields['frm_mail_aanmeld_kop']->value = frm_mail_aanmeld_kop; 

$config['storages']['frm_mail_aanmeld_kop']['frm_mail_aanmeld_kop'] = frm_mail_aanmeld_kop;

Get a Book for SEBLOD
1283 Posts
Bucklash
5 years ago
2
Level 1

Hi

Not sure if heloful but

1

is the br field before the email field?

2

your version does mot seek to reference any db table i.e.

$config[‘storages’][‘#__cck_store_form_contenttype’][‘some_field’]

I imagine is a typo but might confuse others reading this

4229 Posts
Kadministrator
5 years ago
1
Level 2

this

$fields['frm_mail_aanmeld_kop']->value = frm_mail_aanmeld_kop; 
$config['storages']['frm_mail_aanmeld_kop']['frm_mail_aanmeld_kop'] = frm_mail_aanmeld_kop;

is not valid in php unless you have a constant with name frm_mail_aanmeld_kop. Probably you need to set both to the same value as ->form. ALso see what Bucklash has written.

83 Posts
squareweb
5 years ago
0
Level 3

Hi,

I've explored this case further by "fooling" the system and "rebuild" the textarea in the before-render-assignment by providing the html-tags.... see the bold static text I've added in the assignment below, like:

$fields['frm_mail_aanmeld_kop']->form = '<textarea id="frm_mail_aanmeld_kop" name="frm_mail_aanmeld_kop" cols="25" rows="3">' . $myVal . "</textarea>";

AND Yes the email is sent and received with the proper content of the field above... hurray.......

This is a kind of work-around which leaves us with the question:

How to pre-fill text-area fields without destroying the html-part?



83 Posts
squareweb
5 years ago
3
Level 1

Sorry guys for messing up my code my bad.... below I've posted the new version. Anyway what is strange that if I pre-fill my textarea, the data is visible in the form but I cannot add/modify the field-contents.... since I cannot put my cursor into the text-area... After inspecting the page I do see that the html-input-tag for the text-area is missing.... probably that is the problem... I guess my code below isn't the right syntax to pre-populate my textarea?

Still the textarea content is not appearing in my e-mail....

See the screenshot please.

Current code to pre-fill the form field:

$fields['frm_mail_aanmeld_kop']->form = $row['0']->tr_mail_aanmeld_kop; 

$fields['frm_mail_aanmeld_kop']->value = $row['0']->tr_mail_aanmeld_kop; 

$config['storages']['cck_store_form_formulieroi']['frm_mail_aanmeld_kop'] = $row['0']->tr_mail_aanmeld_kop;

83 Posts
squareweb
5 years ago
2
Level 2

To support my question I've debugged my beforerender-code and added a screen print showing that following assignment is messing up the text-area....

$fields['frm_mail_aanmeld_kop']->form = $myVal;

Any idea how to overcome this i.e. how to fill the textarea-content without destroying the html-tag...

bigger image at: http://squareweb.nl/tmp/sebdat2.jpg

4229 Posts
Kadministrator
5 years ago
1
Level 3

Form property holds rendered html, so you are correct to recreate it. Another way would be to set some default value e.g. REPLACE_ME, that do search&replace of this string with the real value in beforerender.

83 Posts
squareweb
5 years ago
0
Level 4

Hi Klas,

Thanks for this solution (:- Thats a rather simple and effective way to manage this. Also efficient (less php-code).

Many thanks for hanging in here.

For the record my PHP-code below:

// DB-stuff - create query

$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query->select('tr_mail_aanmeld_header, tr_mail_aanmeld_body, tr_mail_aanmeld_footer');
$query->from($db->quoteName('#__cck_store_form_traject'));
$query->where($db->quoteName('tr_id')." = ". $fields['frm_tr_key']->value);

// DB-stuff - get the db-record into the $row

$db->setQuery($query);
$row = $db->loadObjectList();

// put values into variables to use below for replacement

$myVal_header = $row['0']->tr_mail_aanmeld_header;
$myVal_body = $row['0']->tr_mail_aanmeld_body;
$myVal_footer = $row['0']->tr_mail_aanmeld_footer;

// replace header-content

$fields['frm_mail_aanmeld_header']->value = $myVal_header;
$fields['frm_mail_aanmeld_header']->form = str_replace("##HEADER##",$myVal_header,$fields['frm_mail_aanmeld_header']->form);

// replace body-content

$fields['frm_mail_aanmeld_body']->value = $myVal_body;
$fields['frm_mail_aanmeld_body']->form = str_replace("##BODY##",$myVal_body,$fields['frm_mail_aanmeld_body']->form);

// replace footer-content

$fields['frm_mail_aanmeld_footer']->value = $myVal_footer;
$fields['frm_mail_aanmeld_footer']->form = str_replace("##FOOTER##",$myVal_footer,$fields['frm_mail_aanmeld_footer']->form);

Get a VIP membership