PHP code example of makeitfly / cleantalk-symfony

1. Go to this page and download the library: Download makeitfly/cleantalk-symfony library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

makeitfly / cleantalk-symfony example snippets


// config/bundles.php

return [
    // ...
    MakeItFly\CleanTalkBundle\MakeItFlyCleanTalkBundle::class => ['all' => true],
];

public function buildForm(
    FormBuilderInterface $builder,
    array $options
): void {
    $builder
        ->add('message', TextareaType::class, [
            'label' => 'form.contact.message.label'
        ])
        ->add('email', EmailType::class, [
            'label' => 'form.contact.email.label'
        ])
        ->add('cleantalk', CleanTalkType::class, [
            'sender_email_field' => 'email',
            'message_field' => 'message'
        ]);
}

// Minimal configuration:
$builder->add('cleantalk', CleanTalkType::class, [
    'sender_email_field' => 'email', // Required
]);

// Full configuration:
$builder->add('cleantalk', CleanTalkType::class, [
    // One of CleanTalkCheck::MESSAGE or CleanTalkCheck::USER. This defines
    // which CleanTalk API endpoint is used:
    // @see https://cleantalk.org/help/api-check-message
    // @see https://cleantalk.org/help/api-check-newuser
    'check_type' => CleanTalkCheck::MESSAGE,
    // The email address of the person who submits the form. This will be
    // fetched from the 'someProperty' property of the form data.
    'sender_email_field' => 'someProperty',
    // Alternatively, for this and the following properties you can use a
    // callable instead, which will get passed the form data.
    'sender_email_field' => function ($formData) {
        // Use the form data directly here, or for example fetch the current
        // logged in account and get the email that way.
        return $formData->getEmail();
    },
    'sender_nickname_field' => 'senderNickname',
    'phone_field' => 'phone',
    'message_field' => 'message'
]);