Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7073569
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T05:56:43+00:00 2026-05-28T05:56:43+00:00

I have a module in my Drupal 7 application called Feedback. It includes a

  • 0

I have a module in my Drupal 7 application called Feedback. It includes a form for submitting simple feedback. This form is submitted via AJAX, and I’ve already tested and verified the submission handling. In my feedback module, I had originally, via hook_menu, hard-coded the location of this form. I then decided that I wanted it to be more flexible – on a different content-type I have called Landing Page, a user may check a box to include the feedback form. When they do, I simply do a <?= render(drupal_get_form('feedback_form')); ?>, which pulls it in. The feedback form definition lives in a file called feedback.admin.inc, so I had to also put a <?php module_load_include('inc', 'feedback', 'feedback.admin'); ?> to get it to appear.

The form appears, but its AJAX handler is no longer working. Checking outgoing network traffic via Chrome, it appears that the AJAX request is being sent to the generic Drupal AJAX handler. So, when my function feedback_form is called within the feedback module, the form works correctly. When it’s called outside that module, it does not. All of the functions related to this form are in the file feedback.admin.inc, which is being included, so I’m not sure what I’m missing.

For completeness, I’ve included the contents of feedback.admin.inc below, along with how it’s being used in my Landing Page module. Any thoughts? Thanks.

feedback.admin.inc

<?php

function feedback_form($form, &$form_state) {

    $form = NULL;

    $form['first_name'] = array(
        '#type' => 'textfield',
        '#title' => 'First Name',
        '#required' => TRUE
    );

    $form['last_name'] = array(
        '#type' => 'textfield',
        '#title' => 'Last Name',
        '#required' => TRUE
    );

    $form['organization'] = array(
        '#type' => 'textfield',
        '#title' => 'Organization'
    );

    $form['email'] = array(
        '#type' => 'textfield',
        '#title' => 'Email',
        '#required' => TRUE
    );

    $form['telephone'] = array(
        '#type' => 'textfield',
        '#title' => 'Telephone',
        '#required' => TRUE
    );

    $form['comments'] = array(
        '#type' => 'textarea',
        '#title' => 'Comments',
        '#required' => TRUE
    );

    $form['submit'] = array(
        '#type' => 'submit',
        '#value' => 'Submit Feedback',
        '#ajax' => array(
            'callback' => 'ajax_feedback_form_submit'
        )
    );

    return $form;
}

function ajax_feedback_form_submit($form, &$form_state) {

    if (count(form_get_errors())) {
        $response_text = '<ul>';

        ##
        ## Add each validation error to response text
        foreach(form_get_errors() as $element => $error) {
            $response_text .= "<li>$error</li>";            
        }

        $response_text .= '</ul>';
        $header_text = 'There are errors with your feedback.';
        $error_state = TRUE;

        ##
        ## Remove message data from session so user is not reminded a second time
        unset($_SESSION['messages']['error']);
        if (!count($_SESSION['messages'])) {
            unset($_SESSION['messages']);
        }

    } else {
        ##
        ## Prepare feedback data for insertion
        $data = array(
            'first_name' => $form_state['values']['first_name'],
            'last_name' => $form_state['values']['last_name'],
            'organization' => $form_state['values']['organization'],
            'email' => $form_state['values']['email'],
            'telephone' => $form_state['values']['telephone'],
            'comments' => $form_state['values']['comments'],
            'created' => time()
        );

        ##
        ## Insert feedback record
        drupal_write_record('feedback', $data);

        $response_text = "Your feedback has been received.";
        $header_text = 'Feedback Received';
        $error_state = FALSE;
    }

    ##
    ## Return AJAX response for interpretation by Drupal.ajax JavaScript object
    return array(
        '#type' => 'ajax', 
        '#commands' => array(
            array(
                'command' => 'modal',
                'text' => $response_text,
                'headerText' => $header_text,
                'errorState' => $error_state
            )
        )
    );
}

landing page

<?php module_load_include('inc', 'feedback', 'feedback.admin'); ?>

<div class="column">
    <?= render(drupal_get_form('feedback_form')) ?> 
</div>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T05:56:43+00:00Added an answer on May 28, 2026 at 5:56 am

    Form submissions happen quite a bit before the theme layer is invoked so calling module_load_include in a template file is too late. Also I’m pretty sure in a lot of AJAX callbacks the theme layer isn’t invoked at all so the include would never run.

    Your form function needs to be somewhere Drupal can find it in a normal bootstrap, i.e. in a .module file, or a file explicitly included from a .module file. I normally do this by putting module_load_include functions at the beginning of the .module file itself.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Drupal module page where I am populating a form with a
I have a Drupal module creating a page via hook_menu(). I am trying to
Drupal 6.x I have this module that manages four different content types. For that
I have embedded a youtube video into a website via a drupal module (I'm
I am using a popular module called Computed Field in Drupal. I have used
I'm using Drupal . I have a module which loads a form onto a
I'm developing a custom module for Drupal 6, that creates a simple form. My
I am currently working on a custom form module in Drupal 6. In this
iam developing a module in Drupal, which needs to have a locking machanism, When
I have module application. When I run it, the main window of that app

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.