Modifying forms field value before saving to DB

How to modify a form field value before saving to the database.

Overview

The issue occurs when a textarea field containing carriage returns needs to be saved without them.
Use a Custom Code action before the Save Data action to replace the newline characters in the field value.

Answered
Hi,

In a form I have a textarea that the user can write using also carriage return but I need to save thew textarea in the DB without CR.

In the action panel of the form I have prepared a "Custom Code" action before the "Save data" action with the following code:

<?php
$str = $_POST['lc_field1'];
$str = str_replace(array("\n","\r"), "§", $str);
// following string is just to verify if the carriage return is changed in something else and it is.
document.print($str);
// here I need to use something like {'lc_field1'} = $str but I was unable to find in Internet a PHP statement that can do what I need.
?>

Please note that lc_field1 is the name of the textarea field in the form and also the name of the column in MySqli DB.

Is there someone that can help me? Thanks
Andrea
Max_admin Max_admin 15 Jan, 2021
Answer
Hi Andrea,

Which Chronoforms version is this ? try to use:
$this->data["lc_field1"] = $str;
for v6 & v7
but for v5 you will need to replace $this by $form
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
This topic is locked and no more replies can be posted.