I am looking for a way to save the data collected by a form (this form is generated from the module i'm working on). I would like to save the data into a content type I also created. Is this possible? I have been looking for a way to do this and have not found any simple ways of doing it. I am currently working on drupal 7.
Here is my code so far :
function drupalform_menu() {
$items['drupalform/form1'] = array(
'type' => MENU_CALLBACK,
'access arguments' => array('access content'),
'page callback' => 'drupal_get_form',
'page arguments'=>array('drupalform_form1'));
return $items;
}
function drupalform_form1() {
$form = array();
$form['Civilite']=array(
'#type'=>'select',
'#title'=>t('Entrez votre civilite'),
'#options'=>array('M','Mr','Mme')
);
$form['nom']=array(
'#type'=>'textfield',
'#title'=>t('Entez votre nom'),
);
$form['email']=array(
'#type'=>'textfield',
'#title'=>t('Enter votre e-mail'),
);
$form['submit']=array(
'#type'=>'submit',
'#value'=>t('Submit')
);
return $form;
}
function drupalform_form1_validate($form, $form_state) {
if(empty($form_state['values']['nom']))
form_set_error('nom','Veuillez saisir votre nom');
else if(filter_var($form_state['values']['email'], FILTER_VALIDATE_EMAIL) == false)
form_set_error('email','Mail non valide');
}
function drupalform_form1_submit($form, $form_state) {
drupal_set_message("Le formulaire est envoyé");
drupal_goto();
}