1

I am writing a module which includes a form which collects timestamp data. Part of the submit process is to test if there is already data recorded and if there is then I want then module to create a modal form to check of the user wants the data overwritten.

I have the user input form with various text fields and a submit button. As part of the form I have included a link to allow me to trigger the modal from within the module code. The code for the bottom of the form is:

  // submit buttons
  $form['progress_continuing_save'] = array(
    '#type' => 'submit',
    '#value' => 'Save then close',
    '#name' => 'progress_continuing_save',
    '#validate' => array('progress_continuing_save_validation'),
    '#submit' => array('progress_continuing_save_submit'),
  );

  // Hidden links for modal form used to query the user if about to overwrite pre-existing data
  $form['markup_cp_link'] = array(
    '#type' => 'markup',
    '#name' => 'markup_cp_link',
    '#markup' => '<div id="magical-modal-link">' . l('cp_ajax_link', 'e80progress_cp/nojs', array('attributes' => array('class' => 'ctools-cp-modal'))) . '</div>',
  );

(I will use css to hide this link). The form works but the link does not create a modal popup, just redirects to another page. A problem for later.)

The submit function looks like this:

function progress_continuing_save_submit($form, &$form_state) {
  ctools_include('modal');
  ctools_include('ajax');
  ctools_modal_add_js();

// some data manipulation follows to create the prospective field name and content, and recover the nids of the nodes to modified.  This works so I have omitted it.

  //load each node, update it and save it
  foreach ($nids as $key => $nid) {
    $node = node_load ($nid);

  // check if there is already a timestamp.  If there is, then query the user is this should be overwritten.
    if(isset($node->{$cp_field})) {
      jQuery('#markup_cp_link').trigger('click');
    }

When I test this by entering data that will trigger the if statement and clicking the submit button I get a php fatal error: "Fatal error: Call to undefined function jQuery()"

Which surprises me, especially as I cannot find this specific error on the drupal web.

Any thoughts?

2
  • 1
    jQuery() isn't a PHP function.
    – Kevin
    Aug 23 '16 at 20:27
  • Welcome to Drupal Answers! Questions about PHP errors are off-topic for us. You are mixing up JavaScript with PHP. That is the reason why PHP says there isn't any jQuery() function.
    – apaderno
    Aug 23 '16 at 21:41

Browse other questions tagged or ask your own question.