Buy Now
Sign in

replace characters in forms entry

kraadde , April 24 2017, 15:51
K
kraadde 23
April 24 2017, 15:51 #367385
Is it possible to replace characters from a form entry before submitting it ?
In php I would use preg_replace function, but ist is possible to use it in an element setting or somewhere else?
Thanks for a hint
Adriano
admin 29
April 24 2017, 16:51 #367389
 Answer
Hi Adriano,

No, using PHP, you need to place the PHP code inside a PHP action, use $this->data["field_name"] to get and set the value.

Best regards,
Max
K
kraadde 23
April 28 2017, 15:18 #367557
Hi Max,

i used the following in a custom code before DB save:

<? $this->data["beschreibung"]=preg_replace('/[^\pL\d\s]+/u','',$this->data["beschreibung"]) ?>

However without the expected result. Where do I make a mistake?

I also tried to use the data-inputmask='mask' : '*{1,35}' in the Extra Param of a text field. It works, but it prevents also spaces. Any solutions, please.

Thanks
GreyHead 64
April 28 2017, 17:27 #367566
Hi Kradde,

I think that in CFv6 you need to leave out the <?php ?> tags.

Bob
ChronoForms technical support
If you'd like to buy me a coffee or two, thank you very much
admin 29
April 28 2017, 21:26 #367576
Hi,

For the inputmask try the following, but I'm not sure if its going to work:

data-inputmask:'mask' : '(*| ){1,35}'


Best regards,
Max
GreyHead 64
April 29 2017, 07:26 #367580
Hi Kradde,

Max's mask appears to work OK when I test and this version allows dashes as well
data-inputmask:'mask' : '(*| |-){1,35}'

Bob
ChronoForms technical support
If you'd like to buy me a coffee or two, thank you very much
K
kraadde 23
April 29 2017, 13:33 #367588
Bob,

yes Max's mask works (but does mask also dashes) , but yours does not.
I test it, and all special characters remain unmasked. Sorry...

Unfortunately, the documentation Robin Herbots is to me not really comprehensive and I am still searching for a solution...

And BTW, leaving out the <?php and ?> tags in the custom code does also not work, but appears as a string in the subsequent Display Message.

Regards

Adriano
K
kraadde 23
April 29 2017, 13:44 #367589
OK now I found the error !

the correct version is:

data-inputmask='mask' : '(*| |-){1,35}' 


i.e. the first colon must be a equal sign!

Hope that this info is also useful for some future users.

Thanks a lot to you

Adriano
GreyHead 64
April 30 2017, 09:57 #367611
Hi Adriano,

Weird - I have a test form using : (and not = ) and that is working correctly. If I change to use = it no longer works.

I have CFv6.0.1 installed - maybe that has changed for 6.0.3 . . . No, I upgraded to 6.0.3 and the colon is still required in my test.

Bob
ChronoForms technical support
If you'd like to buy me a coffee or two, thank you very much
K
kraadde 23
April 30 2017, 14:05 #367614
Bob,

I checked my version and it is version 5.0.14 and not V. 6.
Sorry for the confusion.
Is it possible to update to V6 with same validation key and is it working OK with PHP 5 (my provider does not support PHP 7 yet)?

Regards

Adriano
GreyHead 64
May 01 2017, 08:23 #367626
Hi Adriano,

The thread is tagged CFv6 so I assumed that was what you are using. You are correct. the = is needed in CFv5.

You can run both CFv5 and CFv6 on the same site, CFv6 requires PHP 5.6 iirc. There is no automatic upgrade for your forms though so they have to be manually transferred if you want them in v6.

Bob
ChronoForms technical support
If you'd like to buy me a coffee or two, thank you very much
K
kraadde 23
June 06 2017, 19:09 #369042
Bob,

since a while I have used the following mask in the Extra Param of a text field which works quite OK:

data-inputmask='mask' : '(*| |-|.|,){1,35}'

It prevents users from entering unwanted characters that disrupt further actions.

What disturbs me is that the placeholder of the empty lagging characters (up to the 35 max length) are filled with (unwanted) underlines, see below:

kkk________________________________


Is there a way to avoid this to happen?

Regards
Adriano
admin 29
June 07 2017, 07:56 #369056
Hi Adriano,

Please try this:

data-inputmask='mask' : '(*| |-|.|,){1,35}', 'greedy': false


Best regards,
Max
GreyHead 64
June 07 2017, 09:30 #369058
Hi Adriano,

What do you need this mask to do exactly?

Bob
ChronoForms technical support
If you'd like to buy me a coffee or two, thank you very much
K
kraadde 23
June 07 2017, 19:10 #369080
Bob,

the mask is needed because special characters ( like & % ' #, etc.) and dash signs are correctly stored in the dB, but further string operations in the PHP code used in my webside are incorrect, i.e. all characters after such special character are stripped.

The mask works perfectly sofar, except for the underline space filling.

Regards

Adriano
GreyHead 64
June 08 2017, 10:54 #369091
Hi Adriano,

You can try a variant on Max's suggestion
data-inputmask='mask' : '(*| |-|.|,){1}, 'repeat': 35, 'greedy': false
I'm not sure if the {1} there is needed or not.

It sounds more as though there may be a string-encoding problem with the DB Save??

Bob
ChronoForms technical support
If you'd like to buy me a coffee or two, thank you very much
admin 29
June 09 2017, 07:19 #369138
Hi Adriano,

but further string operations in the PHP code used in my webside are incorrect, i.e. all characters after such special character are stripped.


What happens exactly ? what is the PHP code you are using ?

Best regards,
Max
K
kraadde 23
June 11 2017, 11:20 #369241
Max,


What happen ist the following:
I have a CF where a group of users are entering a description string of the tour they are planning
The data are stored correctly (including special characters) in the MySQL dB.
A list of the next tours will then be selected, sorted and published inside Joomla docs.
What now happen is, that if the users enters special characters, the description shown in the Joomla page, is corrupted or cut.
Again, the data are stored correctly in the data base, but PHP will probably not allow certain characters to be used for reason of security (code injection).

I want to prevent the users to enter special characters in the first place, because filtering out inside my code may give meaningless results.
Masking is the best solution, i guess, since the user has full control of the string entry.

Bob's proposed alternative (dd. 9. 6. 2017) does not work.

The mask I use
data-inputmask='mask' : '(*| |-|.|,){1,35}'
does the trick.

The only thing that disturbs is that the lagging spaces up to the max. string length (35 char. in my case) are filled with underlines. It does not look very nice!

I use following code inside a few webpages:


{source}
<span style="font-size: 14pt;font-family:Dosis">
<?php $db=JFactory::getDBO(); $db->
setQuery("SELECT * FROM cf_EingabeVeranstaltungen where veranstaltung_art !='Interessenmeldung' and (durchfuehrungsdatum1 >=CURDATE() or durchfuehrungsdatum2 >=CURDATE()) order by durchfuehrungsdatum1 asc"); $cf_id = $db->loadObjectList();
include_once "Auswerteroutine.php";
?>
{/source}


The variable "veranstaltungs_art" changes from page to page.

The following code "Auswerteroutine.php" is the same for all my pages:

<?php
/**
* @author Adriano Devide
* @copyright Copyright (C) 2016 Adriano Devide, Windisch
* Erzeugt ein Liste der in der Datenbanktabelle gespeicherten Daten
* formatiert diese und ergänzt es mit Meldungen über Anmeldung und eventuelle Teilnehmerliste
*/

if (count($cf_id)> 0) { ?>
<div style="text-align: left; color: #ff0006; font-family: Dosis; font-size: 14pt;">
<table class="tg" style="margin-right: auto; margin-left: auto;">
<tbody>
<?php $cnt=1;
foreach ($cf_id as $item) {
if($cnt==11) break; ?>
<tr class="ms_row<?php echo ($cnt%2); ?>">
<td class="tg-6wtj">
<span style="color: #000000; font-family: Dosis; font-size: 14pt; text-align:center;">
<?php echo $item->durchfuehrungstag1." ";
$newDate=date( "d-m-Y", strtotime($item->durchfuehrungsdatum1 ));
echo $newDate;?>
<br />
<?php if ($item->veranstaltung_art == '4 TR'){
?> bis
<br />
<?php } ?>
<?php if ($item->durchfuehrungsdatum2 >0) {
echo $item->durchfuehrungstag2." ";
$newDate = date("d-m-Y", strtotime($item->durchfuehrungsdatum2));
echo $newDate; ?>
<br />
<?php } ?>
<?php if ($item->durchfuehrungsdatum3 >0) {
echo $item->durchfuehrungstag3." ";
$newDate = date("d-m-Y", strtotime($item->durchfuehrungsdatum3));
echo $newDate; ?>
<br />
<?php } ?>
</span>
</td>
<td class="tg-6wtj">
<?php if (($item->veranstaltung_art == 'Montagstreff')|| ($item->veranstaltung_art == 'Interessenmeldung')||($item->veranstaltung_art == 'VortragComputeria')) { ?>
<div style="text-align: left; color: #ff0006; font-family: Dosis; font-size: 14pt;">
<a href="components/com_chronoforms5/chronoforms/uploads/<?php echo $item->datei_flyer?> " target="_blank">
<strong>
<?php echo str_replace(".pdf","",$item->beschreibung)?>
</strong>
</div>
</td>
<td>
<div style="text-align: left; color: #ff0006; font-family: Dosis; font-size: 12pt;">
Anmeldung nicht notwendig.
</div>
</td>
<td>
</td>
<?php }
else if (($item->datei_flyer =='')|| ($item->freigabe_anmeldung == '')){ ?>
<div style="text-align: left; color: #ff0006; font-family: Dosis; font-size: 14pt;">
<a href="components/com_chronoforms5/chronoforms/uploads/<?php echo $item->datei_flyer?> " target="_blank">
<strong>
<?php
/* header('Content-type: text/html; charset=utf-8'); */
echo str_replace(".pdf","",$item->beschreibung)?>
</strong>
</div>
</td>
<td>
<div style="text-align: left; color: #ff0006; font-family: Dosis; font-size: 12pt;">
Anmeldung noch nicht möglich.
</div>
</td>
<td>
</td> <?php
}
else { ?>
<div style="text-align: left; color: #ff0006; font-family: Dosis; font-size: 14pt;">
<a href="components/com_chronoforms5/chronoforms/uploads/<?php echo $item->datei_flyer?> " target="_blank">
<strong>
<?php echo str_replace(".pdf","",$item->beschreibung)?>
</strong>
</div>
</td>
<td>
<div style="text-align: left; color: #ff0006; font-family: Dosis; font-size: 12pt;">
<?php if ($item->freigabe_anmeldung == '1'){?>
Hier anmelden:
<?php
/* header('Content-type: text/html; charset=utf-8'); */
if ($item->veranstaltung_art=='Exkursion'){ ?> <a href="index.php/2-uncategorised/103-anmeldeform_Exkursion?&$form_typ=<?php echo str_replace(".pdf","",$item->beschreibung)?>" target="_blank"> <img src="images/pfeil_links.png" alt="pfeil links" width="24" height="24" /> <?php }
else if ($item->veranstaltung_art=='4 TR'){ ?> <a href="index.php/2-uncategorised/102-anmeldeform_4TR?&$form_typ=<?php echo str_replace(".pdf","",$item->beschreibung)?>" target="_blank"> <img src="images/pfeil_links.png" alt="pfeil links" width="24" height="24" /> <?php }
else if ($item->veranstaltung_art=='KulturAnlass'){ ?> <a href="index.php/2-uncategorised/66-anmeldeform_einfach?&$form_typ=<?php echo str_replace(".pdf","",$item->beschreibung)?>" target="_blank"> <img src="images/pfeil_links.png" alt="pfeil links" width="24" height="24" /> <?php }
else if ($item->veranstaltung_art=='Vortrag'){ ?> <a href="index.php/2-uncategorised/66-anmeldeform_einfach?&$form_typ=<?php echo str_replace(".pdf","",$item->beschreibung)?>" target="_blank"> <img src="images/pfeil_links.png" alt="pfeil links" width="24" height="24" /> <?php }
else if ($item->veranstaltung_art=='Wanderung'){ ?> <a href="index.php/2-uncategorised/109-anmeldeform_wanderung?&$form_typ=<?php echo str_replace(".pdf","",$item->beschreibung)?>" target="_blank"> <img src="images/pfeil_links.png" alt="pfeil links" width="24" height="24" /> <?php }
else if ($item->veranstaltung_art=='Baldegghock'){ ?> <a href="index.php/2-uncategorised/66-anmeldeform_einfach?&$form_typ=<?php echo str_replace(".pdf","",$item->beschreibung)?>" target="_blank"> <img src="images/pfeil_links.png" alt="pfeil links" width="24" height="24" /> <?php }
else if ($item->veranstaltung_art=='8090100'){ ?> <a href="index.php/2-uncategorised/66-anmeldeform_einfach?&$form_typ=<?php echo str_replace(".pdf","",$item->beschreibung)?>" target="_blank"> <img src="images/pfeil_links.png" alt="pfeil links" width="24" height="24" /> <?php }
else if ($item->veranstaltung_art=='JA'){ ?> <a href="index.php/2-uncategorised/66-anmeldeform_einfach?&$form_typ=<?php echo str_replace(".pdf","",$item->beschreibung)?>" target="_blank"> <img src="images/pfeil_links.png" alt="pfeil links" width="24" height="24" /> <?php }
else if ($item->veranstaltung_art=='JV'){ ?> <a href="index.php/2-uncategorised/100-anmeldeform_JV?&$form_typ=<?php echo str_replace(".pdf","",$item->beschreibung)?>" target="_blank"> <img src="images/pfeil_links.png" alt="pfeil links" width="24" height="24" /> <?php }
else if ($item->veranstaltung_art=='WorkshopComputeria'){ ?> <a href="index.php/2-uncategorised/99-anmeldeform_WSC?&$form_typ=<?php echo str_replace(".pdf","",$item->beschreibung)?>" target="_blank"> <img src="images/pfeil_links.png" alt="pfeil links" width="24" height="24" /> <?php }
else if ($item->veranstaltung_art=='KKL'){ ?> <a href="index.php/2-uncategorised/101-anmeldeform_KKL?&$form_typ=<?php echo str_replace(".pdf","",$item->beschreibung)?>" target="_blank"> <img src="images/pfeil_links.png" alt="pfeil links" width="24" height="24" /> <?php }
else if ($item->veranstaltung_art=='KurzW'){ ?> <a href="index.php/2-uncategorised/108-anmeldeform_KurzW?&$form_typ=<?php echo str_replace(".pdf","",$item->beschreibung)?>" target="_blank"> <img src="images/pfeil_links.png" alt="pfeil links" width="24" height="24" /> <?php }
else{
echo "Keine Anmeldung möglich!";}
}
?>
</div>
</td>
<td>
<?php
$user=JFactory::getUser();
jimport( 'joomla.user.helper' );
$userID=$user->id; $userProfile = JUserHelper::getProfile($userId);
if ($userProfile->profile['uservor']=='')
{$usr=gast;}
if(( $item->teilnehmerliste !=='')&&($usr!='gast')){ ?>
<div style="text-align: left; color: #ff0006; font-family: Dosis; font-size: 12pt;">
Stand der Anmeldungen:
<a href="components/com_chronoforms5/chronoforms/uploads/<?php echo $item->teilnehmerliste?> " target="_blank">
<img src="images/pfeil_rechts.png" alt="" width="25" height="24" />
</div>
<?php }?>
</td> <?php } ?>
</tr>
<? $cnt++;} ?>
</tbody>
</table>
</div> <? }
else { ?>
<div style="border:none; font-family: Dosis; font-size: 14pt;color: #ff0006;">
Informationen folgen sobald bekannt.
</div> <? } ?>
</span>
admin 29
June 12 2017, 21:28 #369316
Hi kraadde,

Then the code used to display the data should be revised and updated to make sure that the data is displayed correctly with the special characters, the mask is not the best way to solve this issue in my opinion.

Best regards,
Max
K
kraadde 23
June 12 2017, 23:20 #369325
Max,

I am not able to change the PHP security settings, therefore changing the PHP code would not help.
It must be a solution that prevent the users to enter "unwanted" characters in the first place.

If the form entry does not show what the actual display will be, than there is no control of the resulting display.

That is why masking seems to me the only solution and it works OK except the underlines that replaces the lagging spaces.

Regards

Adriano