I have a form wich allow to create content, it's build like :
- get the owner part in a form
- if the user isn't connected show him a login form and registration form
- if the user is connected show him the user profile form to edit his informations
- get the content form
- include 1 by drupal get form
- add an ajax system to add/remove lines of content creation
But when i clic on add or remove button (before i commented the user form and it works perfectly) i get this ajax error : Error : Call to undefined function user_profile_form_validate() dans form_execute_handlers() (ligne 1519 dans /Applications/MAMP/htdocs/fritr/includes/form.inc).
I've seen this post wich may contain the solution : https://www.drupal.org/node/1229882 Maybe it's because i don't use a form_load_include() but i don't know what include...
Here is my code :
/*
THE USER FORM
*/
function fritr_register_friterie_owner_form($form, &$form_state) {
// GET THE USER ENTITY IN FORM
global $user;
global $language;
if(user_is_logged_in())
$user = user_load($user->uid);
form_load_include($form_state, 'inc', 'user', 'user.pages');
// MAIN
$form = array(
'#type' => 'fieldset',
'#tree' => TRUE,
'#collapsible' => FALSE,
'#collapsed' => FALSE,
'#attributes' => array(
'class' => array('clean-panel'),
),
);
// SHOW LOGIN FORM IF USER ISN'T CONNECTED
$form['connexion'] = array(
'#type' => 'fieldset',
'#title' => t('Se connecter'),
'#tree' => TRUE,
'#collapsible' => FALSE,
'#collapsed' => FALSE,
'#weight' => 1,
'#attributes' => array(
'class' => array('clean-panel titled'),
),
);
// USER FORM
$form['user'] = array(
'#type' => 'fieldset',
'#title' => t('Editer ses informations'),
'#tree' => TRUE,
'#collapsible' => FALSE,
'#collapsed' => FALSE,
'#weight' => 2,
'#attributes' => array(
'class' => array('clean-panel titled'),
),
);
if (user_is_logged_in()) {
unset($form['connexion']);
$form['user']['#title'] = t('Editer ses informations');
$form['user']['content'] = drupal_get_form('user_profile_form', $user);
$form['user']['content']['#validate'] = array();
} else {
$form['connexion']['content'] = drupal_get_form('user_login');
$form['user']['#title'] = t('Créer un compte');
$form['user']['content'] = drupal_get_form('user_register_form');
}
return $form;
}
function fritr_register_friterie_connexion_form_submit($form, &$form_state) {
$form_state['redirect'] = current_path();
}
/*
THE FRITERIE FORM WICH CONTAIN USER FORM
*/
/*
* Implements hook_form().
*/
function fritr_register_friterie_form($form, &$form_state) {
module_load_include('inc', 'fritr_register_friterie');
form_load_include($form_state, 'inc', 'user', 'user.pages');
// USER REGISTER FORM
$form['owner'] = drupal_get_form('fritr_register_friterie_owner_form');
$form['owner']['#weight'] = 2;
$form['friteries'] = array(
'#type' => 'fieldset',
'#title' => t('Créer des friteries'),
'#tree' => TRUE,
'#collapsible' => FALSE,
'#collapsed' => FALSE,
'#weight' => 3,
'#attributes' => array(
'class' => array('clean-panel titled'),
),
);
$form['friteries']['content'] = array(
'#type' => 'container',
'#weight' => 80,
'#tree' => TRUE,
'#prefix' => '<div id="wrapper-friterie">',
'#suffix' => '</div>',
);
$form_state['friterie_deltas'] = isset($form_state['friterie_deltas']) ? $form_state['friterie_deltas'] : range(0, 0);
$field_count = $form_state['friterie_deltas'];
foreach ($field_count as $delta) {
$form['friteries']['content'][$delta] = array(
'#type' => 'fieldset',
'#tree' => TRUE,
'#collapsible' => FALSE,
'#collapsed' => FALSE,
'#weight' => 1,
'#attributes' => array(
'class' => array('clean-panel'),
),
);
// FRITERIE FORM
$form['friteries']['content'][$delta]['remove_friterie'] = array(
'#type' => 'submit',
'#value' => t('-'),
'#submit' => ['fritr_register_friterie_remove'],
'#limit_validation_errors' => array(),
'#weight' => 1,
'#ajax' => array(
'callback' => 'fritr_register_friterie_remove_callback',
'wrapper' => 'wrapper-friterie',
),
'#attributes' => array(
'class' => ['button-small'],
),
'#name' => 'remove_name_' . $delta,
);
$form['friteries']['content'][$delta]['friterie_fields'] = array(
'#type' => 'fieldset',
'#title' => t('Informations friterie (cliquez pour basculer l\'affichage)'),
'#tree' => TRUE,
'#collapsible' => TRUE,
'#collapsed' => FALSE,
'#weight' => 2,
'#attributes' => array(
'class' => array('clean-panel titled underline collapsible'),
),
);
if (!isset($form['friteries']['content'][$delta]['#node'])) {
global $language;
$form['friteries']['content'][$delta]['#node'] = entity_create('node', array('type' => 'friterie', 'language' => $language->language));
}
field_attach_form('node', $form['friteries']['content'][$delta]['#node'], $form['friteries']['content'][$delta]['friterie_fields'], $form_state);
}
$form['friteries']['content']['add_friterie'] = array(
'#type' => 'submit',
'#value' => t('Ajouter une friterie'),
'#submit' => ['fritr_register_friterie_add'],
'#limit_validation_errors' => array(),
'#ajax' => array(
'callback' => 'fritr_register_friterie_add_callback',
'wrapper' => 'wrapper-friterie',
),
'#weight' => 100,
);
$form['#submit'][] = 'fritr_register_friterie_form_submit';
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Enregistrer la friterie'),
'#weight' => 100,
);
dsm($form);
dsm($form_state);
return $form;
}
/*
THE AJAX AND SUBMIT CALLBACK OF BUTTONS WICH ADD OR REMOVE A FRITERIE NODE FORM CREATION
*/
function fritr_register_friterie_remove($form, &$form_state) {
$delta_remove = $form_state['triggering_element']['#parents'][1];
$k = array_search($delta_remove, $form_state['friterie_deltas']);
unset($form_state['friterie_deltas'][$k]);
$form_state['rebuild'] = TRUE;
drupal_get_messages();
}
function fritr_register_friterie_remove_callback($form, &$form_state) {
return $form['friteries']['content'];
}
function fritr_register_friterie_add($form, &$form_state) {
$form_state['friterie_deltas'][] = count($form_state['friterie_deltas']) > 0 ? max($form_state['friterie_deltas']) + 1 : 0;
$form_state['rebuild'] = TRUE;
drupal_get_messages();
}
function fritr_register_friterie_add_callback($form, $form_state) {
return $form['friteries']['content'];
}