Buy Now
Sign in

Modifying forms field value before saving to DB

abiglietti@gmail.com , January 09 2021, 23:39
A
abiglietti@gmail.com 1
January 09 2021, 23:39 #395628
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
admin 32
January 15 2021, 03:46 #395669
 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