Results 1 to 5 of 5

Thread: Encrypt data when saving into database.

  1. #1
    New user
    Join Date
    09-20-15.
    Posts
    19

    Default Encrypt data when saving into database.

    Hello All,

    I have a tabel with data in it.
    i have created a form that store's the data, its working fine.

    now i want to encrypt the saved data only on 1 textfield.
    is this possible and how can i do it?

  2. #2
    User Andreas's Avatar
    Join Date
    07-11-09.
    Location
    Mönchengladbach
    Posts
    499

    Default

    Use a HOOK before values are saved and use the class Encryption in
    system/modules/core/library/Contao/Encryption.php
    e.g.
    PHP Code:
    \Encryption::encrypt($myVar
    Web-Development, Freelancer, Burgtech, XHTML, HTML5, CSS, PHP, Javascript, MooTools, MySQL and more
    Amazon wishlist

  3. #3
    New user
    Join Date
    09-20-15.
    Posts
    19

    Default

    Thanks for the replay,

    I have made a hook and add it to my config file,
    When i create a autoload (backend autoload creator) the class is not be saved in my autoload.

    The hook in config/config.php :
    Code:
    $GLOBALS['TL_HOOKS']['prepareFormData'][] = array('encrypt_form_data', 'MyEncryptFormData');
    and the class in classes/encrypt_form_data.php is :
    Code:
    <?php if (!defined('TL_ROOT')) die('You can not access this file directly!');
    
    
    class MyEncryptFormData 
    {
    
    	public function EncryptFormData($arrSubmitted, $arrLabels, $objForm)
    	{
    		if (isset($arrSubmitted['dossier'])){
    			$arrSubmitted['dossier'] = Encryption::encrypt($arrSubmitted['dossier']);
    		}
    
    	}
    
    }
    When i add it in autoload.php See code below i get a error Cannot redeclare class

    Code:
    'encrypt_form_data'        		   => 'system/modules/inbalans/classes/encrypt_form_data.php',
    Last edited by Notify; 10/28/2015 at 12:21.

  4. #4
    User Andreas's Avatar
    Join Date
    07-11-09.
    Location
    Mönchengladbach
    Posts
    499

    Default

    First build an extension with the extension creator from within back end. Then take a look at the config files. It should be self-explanatory.
    Web-Development, Freelancer, Burgtech, XHTML, HTML5, CSS, PHP, Javascript, MooTools, MySQL and more
    Amazon wishlist

  5. #5
    New user
    Join Date
    09-20-15.
    Posts
    19

    Default

    Thanks, The problem is solved.

    My class was a different name then the file so it wassend loading.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •