hook_form_alter for a Webform – Drupal Answers

I have another post here:

Retrieve Webform submission data from database

I got some guidance but some of it wasn’t feasible for our application and the edited assistance was a bit general. Based on the person’s suggestions I am trying to use a hook_form_alter on a Webform module webform. Here’s the files and code I have.


name: 'CC Processing Get SubmissionData'
description: 'Provides a custom webform handler for retrieving the previous forms submission data'
core_version_requirement: ^8.8
Core: 8.x
package: Custom
type: module



 * Implementation of hook_form_alter
 use DrupalCoreFormFormStateInterface;
 function CCProcessingGetSubmissionData_webform_submission_form_alter(array &$form, FormStateInterface $form_state, $form_id) {
    echo "form alter hook triggered";
    if($form('#webform_id') == 'credit_card_billing_information') {
        echo "form alter form id found";
        $myValue = 'Jared';
        $form('elements')('credit_card_name')('#default_value') = $myValue;

I am not new to programming but am new to Drupal programming. I have some other code in the module that’s not in the answer suggestion on my previous post like the echos I found on other posts in an attempt to try to get something to happen that lets me know the the hook is being called. Both files are in modules/custom/cc_processing_getsubmissiondata. The folder structure I got off of a YouTube video on building hooks but it was just a short 8 minute basic hook video. From all the posts I’ve seen out there, everything I have looks correct but nothing happens. Any assistance in helping me getting this hook to work would be awesome. 🙂