How do I use an image CAPTCHA? I am trying to show a CAPTCHA image in the form of my custom form, but it doesn't appear.



Why doesn't this code show the CAPTCHA as expected?

/**
 * Created by PhpStorm.
 * User: sony
 * Date: 28/02/2016
 * Time: 23:23
 */

/**
 * @file
 * Contains \Drupal\contact_form\Form\ContributeForm.
 */

namespace Drupal\contact_form\Form;
use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Component\Utility\UrlHelper;

/**
 * Contribute form.
 */
class ContributeForm extends FormBase {
    /**
     * {@inheritdoc}
     */
    public function getFormId() {
        return 'contact_form_contribute_form';
    }

    /**
     * {@inheritdoc}
     */
    public function buildForm(array $form, FormStateInterface $form_state) {
        $form['Full Name'] = array(
            '#type' =&gt; 'textfield',
            '#title' =&gt; t('Full Name'),
            '#required' =&gt; TRUE,
        );
        $form['E-mail'] = array(
            '#type' =&gt; 'email',
            '#title' =&gt; t('E-mail'),
        );

        $form['Type of feedback'] = array(
            '#type' =&gt; 'radios',
            '#title' =&gt; t('Feedback'),
            '#description' =&gt; t('Type of feedback'),
            '#options' =&gt; array(
                t('Comments or suggestions'),
                t('Questions'),
                t('Report a problem(s)'),
                t('Other'),
            )
        );
        $form['Subject'] = array(
            '#type' =&gt; 'textfield',
            '#title' =&gt; t('Subject'),
        );
        $form['Your Message'] = array(
            '#type' =&gt; 'textarea',
            '#title' =&gt; t('Your Message'),
        );
        $form['my_captcha_element'] = array(
            '#type' =&gt; 'captcha',
            '#captcha_type' =&gt; 'Image',
        );

        $form['sendt'] = array(
            '#type' =&gt; 'submit',
            '#value' =&gt; t('Send'),
        );
        return $form;

    }

    /**
     * {@inheritdoc}
     */
    public function validateForm(array &amp;$form, FormStateInterface $form_state) {
        if (!UrlHelper::isValid($form_state-&gt;getValue('video'), TRUE)) {
            $form_state-&gt;setErrorByName('video', $this-&gt;t("The video url '%url' is invalid.", array('%url' =&gt; $form_state-&gt;getValue('video'))));
        }
    }

    /**
     * {@inheritdoc}
     */
    public function submitForm(array &amp;$form, FormStateInterface $form_state) {
        foreach ($form_state-&gt;getValues() as $key =&gt; $value) {
            drupal_set_message($key . ': ' . $value);
        }
    }
Captcha is not a valid form element in Drupal 8. Since you haven't listed if you are using any other contributed modules, I am not sure what or where #type =&gt; captcha comes from.

I advise using Mollom to do captcha handling for forms.

https://www.drupal.org/project/mollom