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 939059
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T21:43:44+00:00 2026-05-15T21:43:44+00:00

In a custom module, I have the following (to add javascript to a particular

  • 0

In a custom module, I have the following (to add javascript to a particular form):

function mymodule_form_mynode_node_form_alter(&$form, $form_state) {
  drupal_add_js(drupal_get_path('module', 'mymodule') . '/js/mymodule.js', 'module');
}

This function does get called the form is first loaded (i.e. browse to http://myserver.com/node/add/mynode) however this php function does not get called when the same form is reloaded after the form has been invalidated (i.e. missed a required field after clicking ‘Submit’ or ‘Preview’).

What do I need to do to have the javascript file added after ‘Submit’ or ‘Preview’ is clicked?

Thanks,

John

  • 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-15T21:43:45+00:00Added an answer on May 15, 2026 at 9:43 pm

    You form alter is only called when the form is build. As forms are cached between request, the same and already build form is used on submit and preview.

    You need to unsure that your code is called each time the form is rendered. As pointed out by googletorp, one way to do it is to use a custom form rendering function. You can also do it by attaching a post or pre-rendering function to your form. Actually, the custom, pre or post rendering function doesn’t need to be for the form itself and can be used on any form element. Preferably the one which behavior is altered by the JavaScript.

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

Sidebar

Related Questions

I have made up the custom module as : YUI.add('util', function(Y) { Y.namespace('com.myCompany'); var
So I have a module in flex in which I add a custom component.
I have the following code in a custom module to save a session_id for
I have the following code in a custom module as well as I have
I have extended the Mage_Adminhtml_Block_Sales_Order_Grid class with a custom module to add several customer
i have created a custom form in my custom drupal6 module and the form
I have a custom module in a D7 installation. In the submit function I'm
I created a custom module for Orchard following this wonderful guide . I have
I have a custom module I made for Magento. From the admin, there is
I have a custom module I made to show featured products on the homepage.

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.