Why my captcha bot works in local but doesn’t work on heroku?

I added a captcha bot to my registration form.

My captcha bot works perfectly fine on local (on dev and prod mode)
but when I deployed the code to Heroku the /register page doesn’t work anymore.
I get this error :

ERROR: BotDetect requires the GD library and its support library:
libpng, libjpeg and FreeType 2. You can read more about
installing/enabling them at http://php.net/manual/en/book.image.php.

You can see the error here : website link

I dont think the problem is from my code, but here is it:
Controlleur code :

/**
 * @Route("/register", name="user_register", methods={"GET","POST"})
 */
public function register(Request $request,UserPasswordEncoderInterface $encoder): Response
{
    $user = new User();
    $form = $this->createForm(RegisterType::class, $user, ['validation_groups' => ['register'], ]);
    $form->handleRequest($request);
    if ($form->isSubmitted() && $form->isValid()) {

        $hash = $encoder->encodePassword($user,$user->getPassword());
        $user->setPassword($hash);

        $this->addFlash('success', 'You succesfully registered, Now Login!');

        $entityManager = $this->getDoctrine()->getManager();
        $entityManager->persist($user);
        $entityManager->flush();
        

        return $this->redirectToRoute('user_login');
}
    return $this->render('authentication/register.html.twig', [
        'user' => $user,
        'form' => $form->createView(),
    ]);
}

My form :

class RegisterType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder
            ->add('username')
            ->add('password',PasswordType::class)
            ->add('password2',PasswordType::class)
            ->add('email')
            ->add('name')
            ->add('captchaCode', CaptchaType::class, [
                'captchaConfig' => 'ExampleCaptchaUserRegistration',
                'constraints' => [
                    new ValidCaptcha([
                        'message' => 'Invalid captcha, please try again',
                    ]),
                ],]);
    }

    public function configureOptions(OptionsResolver $resolver)
    {
        $resolver->setDefaults([
            'data_class' => User::class,
        ]);
    }
}

The captchaCode on User.php

/**
 * @CaptchaAssertValidCaptcha(
 *     message = "Invalid captcha, please try again",
 *     groups={"register"}
 * )
 */

protected $captchaCode;

public function getCaptchaCode()
{
  return $this->captchaCode;
}

public function setCaptchaCode($captchaCode)
{
  $this->captchaCode = $captchaCode;
}

Source: Symfony Questions

Was this helpful?

0 / 0

Leave a Reply 0

Your email address will not be published. Required fields are marked *