Forums

replace characters in forms entry

kraadde 24 Apr, 2017
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
Max_admin 24 Apr, 2017
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
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
kraadde 28 Apr, 2017
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 28 Apr, 2017
Hi Kradde,

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

Bob
Max_admin 28 Apr, 2017
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
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
GreyHead 29 Apr, 2017
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
kraadde 29 Apr, 2017
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
kraadde 29 Apr, 2017
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 30 Apr, 2017
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
kraadde 30 Apr, 2017
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 01 May, 2017
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
kraadde 06 Jun, 2017
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
Max_admin 07 Jun, 2017
Hi Adriano,

Please try this:

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


Best regards,
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
GreyHead 07 Jun, 2017
Hi Adriano,

What do you need this mask to do exactly?

Bob
kraadde 07 Jun, 2017
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 08 Jun, 2017
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
Max_admin 09 Jun, 2017
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
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
kraadde 11 Jun, 2017
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>
Max_admin 12 Jun, 2017
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
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
kraadde 12 Jun, 2017
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
Max_admin 13 Jun, 2017
Hi Adriano,

Ok, did you try with the "greedy = false" option ?

Best regards,
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
kraadde 14 Jun, 2017
Yes, I tried as follows:

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

as you proposed, and

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

but both did not work or hamper any masking at all. Have you seen any mistake in the above?

Adriano


Adriano
Max_admin 14 Jun, 2017
Hi Adriano,

This is v6 ? if yes then you should be using data-inputmask: but not "=", so it should be:
data-inputmask:'mask' : '(*| |-|.|,){1,35}', 'greedy': false


Best regards,
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
GreyHead 16 Jun, 2017
Hi Adriano,

I experimented with this yesterday but couldn't find a way to get the un-used placeholders to be removed in the mask. The easiest solution may be to use a custom code action after the form submits and use trim() to remove them.

Bob
This topic is locked and no more replies can be posted.