Hi !
I'm trying to add a newsletter subscription's popup on my website. I've managed to show the form in the modal frame but when i submit the form without fill in the fields, a white screen appears in the modal frame instead of the form with red warnings and highlighting.

Here is the code.


/**
* Implementation of hook_menu().
*/
function custom_newsletter_popup_menu() {  
  $items = array();
  $items['newsletter/%ctools_js/go'] = array(
    'page callback' => 'custom_newsletter_popup_modal_callback',
    'page arguments' => array(1),
    'access arguments' => array('access content'),
  );
  return $items;
}

function custom_newsletter_popup_form($form, &$form_state) {
  $form['email'] = array(
    '#type' => 'textfield',
    '#title' => "Email",
    '#title_display' => 'invisible',
    '#size' => 40,
  );
  $form['civilite'] = array(
    '#type' => 'radios',
    '#title' => "Civilité",
    '#options' => array(
      'mlle' => 'Mlle',
      'mme' => 'Mme',
      'mr' => 'Mr',
    ),
  );
  $form['nom'] = array(
    '#type' => 'textfield',
    '#title' => "Nom",
    '#title_display' => 'invisible',
    '#size' => 40,
  );
  $form['prenom'] = array(
    '#type' => 'textfield',
    '#title' => "Prénom",
    '#title_display' => 'invisible',
    '#size' => 40,
  );
  $form['proprietaire'] = array(
    '#type' => 'checkboxes',
    '#title' => "Prénom",
    '#title_display' => 'invisible',
    '#options' => array(
      'chien' => 'd\'un chien',
      'chat' => 'd\'un chat',
    ),
  );
  $form['partenaire'] = array(
    '#type' => 'checkbox',
    '#title' => "Je souhaite recevoir les offres des partenaires ***",
  );
  $form['commerciale'] = array(
    '#type' => 'checkbox',
    '#title' => "Je souhaite recevoir les actus, conseils et offres ***",
  );
  $form['annuler'] = array(
    '#type' => 'submit',
    '#value' => "Annuler",
  );
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => "S'inscrire",
  );
  return $form;
}

function custom_newsletter_popup_form_validate($form, &$form_state) {
  $values = $form_state['values'];
  if (isset($values['annuler']) && $values['op'] == $values['annuler']) {
    return;
  }
  if((! isset($values['email'])) || $values['email'] === "" || (! filter_var($values['email'], FILTER_VALIDATE_EMAIL))) {
    form_set_error('email', "Vous devez fournir une adresse email valide.");
  }
  if((! isset($values['civilite'])) || $values['civilite'] === "") {
    form_set_error('civilite', "Le champs Civilité est obligatoire.");
  }
  if((! isset($values['nom'])) || $values['nom'] === "") {
    form_set_error('nom', "Le champs Nom est obligatoire.");
  }
  return;
}

function custom_newsletter_popup_form_submit($form, &$form_state) {
  return true;
}

function custom_newsletter_popup_modal_callback($js = FALSE) {
  if ($js) {
    ctools_include('modal');
    ctools_include('ajax');

    $form_state = array(
      'id' => 'custom_newsletter_popup_form',
      'title' => t('Newsletter'),
      'ajax' => TRUE,
      'modal' => TRUE,
      'modal return' => TRUE,
      'no_redirect' => TRUE,
      'rerender' => TRUE,
    );
    
    $output = ctools_modal_form_wrapper('custom_newsletter_popup_form', $form_state);
    if (!isset($output[0])) {
      $output = array();
      $output[] = ctools_modal_command_loading();
      $output[] = ctools_ajax_command_redirect('user');
    }
    print ajax_render($output);
  }
  else {
    return drupal_get_form('custom_newsletter_popup_form');
  }
}

When I replace my 'custom_newsletter_popup_form' with 'user_login' this actually work ! The form shows error message.

Thanks for your help !

Comments

Flowster’s picture

No one can help me with this problem ?

merlinofchaos’s picture

Status: Active » Fixed

This is a very strange piece of code:

if (!isset($output[0])) {

I think what you want to be testing is $form_state['executed']

I also think in -beta1, the 'redirect' command might not have been working properly.

You can see an example of the redirect command in the ctools_ajax_sample module with the modal login.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.