Forums

Modifying forms field value before saving to DB

abiglietti@gmail.com 09 Jan, 2021
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 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.
You need to login to be able to post a reply.