How to use signature field in custom forms?

Created on 9 October 2017, about 7 years ago
Updated 9 October 2024, 2 months ago

Hi!

Do we have any way for using signature field as element of custom form?

I'll put the solution here if I'll find how to do that.

πŸ’¬ Support request
Status

Fixed

Version

1.0

Component

Code

Created by

πŸ‡ΊπŸ‡¦Ukraine sun-fire

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡¬πŸ‡§United Kingdom tce

    I have installed and enabled this module, but when I put the below code into a custom form it does nothing - I also noticed the library assets are not loaded, so I feel like it's not doing anything. Is there anything else I need to do to make this work?

    <?php
        $form['signature_field'] = [
          '#type' => 'signature',
        ];
        $form['signature_data'] = [
          '#type' => 'hidden',
          '#attributes' => [
            'id' => ['signature_data'],
          ],
        ];
    ?>
    
  • πŸ‡¬πŸ‡§United Kingdom tce

    I finally got this working using the code below. It seems like the selector isn't there in the code example, so wrapping in a <div class="signature"> was needed. Also, the signature_data element selector is wrong in the example, the id is signature-data and not signature_data

    <?php
        $form['signature'] = [
          '#type' => 'container',
          '#prefix' => '<div class="signature">',
          '#suffix' => '</div>',
        ];
        $form['signature']['signature_field'] = [
          '#type' => 'signature',
        ];
        $form['signature']['signature_data'] = [
          '#type' => 'textarea',
          '#attributes' => [
            'id' => ['signature-data'],
            'class' => [
              'signature-data',
            ],
          ],
        ];
    ?>
Production build 0.71.5 2024