Submitted by Looping89 on
Bonjour à tous,
je me retrouve devant un problème que je n'arrive pas à résoudre.
J'ai créé un type champ avec une plusieurs champs dedans ! Le tout marche correctement sauf que quand je sauvegarde la page. Bien, rien n'est sauvegardé dans la table associé à ce type de champs.
Si vous voyez de quoi je parle ^^
Enfin voilà tout monde code dans le .module ! je sais pas quel fonction permet de commité les données dans la table dans la DB et quel fonction est utile pour extraire ces données.
/
* Implements of hook_field_info().
*/
function transfert_field_info(){
return array(
'transfert_customer' => array(
'label' => t('Customer - Society Information'),
'description' => t('Customer - Society Information'),
'default_widget' => 'custom_form',
'default_formatter' => 'custom_default',
)
);
}
/
* Implements of hook_field_is_empty().
* Define what constitutes an empty item for a field type.
*
* @param item: An item that may or may not be empty.
*
* @param field: The field to which $item belongs.
*
* @return value TRUE if $field's type considers $item not to contain any data; FALSE otherwise.
*/
function transfert_field_is_empty($item,$field){
if(empty($item['nameSociety']) &&
empty($item['labelSociety']) &&
empty($item['typeSociety'])){
return TRUE;
}
return FALSE;
}
/
* Implements hook_field_validate().
*
*
* @see field_example_field_widget_error()
*/
function transfert_field_validate($entity_type, $entity, $field, $instance, $langcode, $items, &$errors) {
}
/
* Implements hook_field_widget_info().
* Expose Field API widget types.
*/
function transfert_field_widget_info(){
return array(
'custom_form' => array(
'label' => t('Customer - Society Information Formulaire'),
'field types' => array('transfert_customer'),
'behaviors' => array(
'multiple values' => FIELD_BEHAVIOR_DEFAULT,
)
)
);
}
function transfert_field_widget_form(&$form, &$form_state, $field, $instance, $langcode, $items, $delta, $element){
$base = $element;
if($instance['widget']['type'] == 'custom_form'){
$widget = $instance['widget'];
$settings = $widget['settings'];
dpm($items);
dpm($delta);
//DEBUT FORMULAIRE - SOCIETE - CLIENT
$element['labelSociety'] = array(
'#description' => t('max. 10 characters'),
'#type' => 'textfield',
'#title' => t('Label of Society'),
'#size' => 15,
'#maxlength' => 10,
'#required' => TRUE,
'#default_value' => isset($items[$delta]['labelSociety']) ? $items[$delta]['labelSociety'] : '...',
);
$element['nameSociety'] = array(
'#type' => 'textfield',
'#description' => t('max. 40 characters'),
'#title' => t('Name of Society'),
'#size' => 45,
'#maxlength' => 40,
'#required' => TRUE,
'#default_value' => isset($items[$delta]['nameSociety']) ? $items[$delta]['nameSociety'] : '...',
);
$element['codeSociety'] = array(
'#type' => 'select',
'#title' => t('Code of Society'),
'#options' => array( //option contenu dans le select box clé => valeur
'ASBL' => t('ASBL'),
'AVO' => t('AVO'),
'BVBA' => t('BVBA'),
'DHR' => t('DHR'),
'ETS' => t('ETS'),
'M' => t('M'),
'ME' => t('ME'),
'MEVR' => t('MEVR'),
'MME' => t('MME'),
'MR' => t('MR'),
'NV' => t('NV'),
'ONDERNEMING' => t('ONDERNEMING'),
'SA' => t('SA'),
'SPRL' => t('SPRL'),
'VZW' => t('VZW'),
),
'#default_value' => isset($items[$delta]['codeSociety']) ? $items[$delta]['codeSociety'] : 'ABSL',
);
$element['addressSociety'] = array(
'#type' => 'textfield',
'#description' => t('max. 40 characters'),
'#title' => t('address of Society'),
'#size' => 45,
'#maxlength' => 40,
'#required' => TRUE,
'#default_value' => isset($items[$delta]['addressSociety']) ? $items[$delta]['addressSociety'] : '...',
);
$element['typeSociety'] = array(
'#type' => 'select',
'#title' => t('type of Society'),
'#options' => array(
'1' => t('Customer (1)'),
'2' => t('Supplier (2)')
),
'#required' => TRUE,
'#default_value' => isset($items[$delta]['typeSociety']) ? $items[$delta]['typeSociety'] : 1,
);
//FORMULAIRE SUITE - CONTACT
$element['nameContact'] = array(
'#type' => 'textfield',
'#title' => t('Name of Contact'),
'#description' => t('max. 40 characters'),
'#size' => 45,
'#maxlength' => 40,
'#default_value' => isset($items[$delta]['nameContact']) ? $items[$delta]['nameContact'] : NULL
);
$element['codeContact'] = array(
'#type' => 'select',
'#title' => t('Code of Contact'),
'#options' => array( //option contenu dans le select box clé => valeur
'ASBL' => t('ASBL'),
'AVO' => t('AVO'),
'BVBA' => t('BVBA'),
'DHR' => t('DHR'),
'ETS' => t('ETS'),
'M' => t('M'),
'ME' => t('ME'),
'MEVR' => t('MEVR'),
'MME' => t('MME'),
'MR' => t('MR'),
'NV' => t('NV'),
'ONDERNEMING' => t('ONDERNEMING'),
'SA' => t('SA'),
'SPRL' => t('SPRL'),
'VZW' => t('VZW'),
),
'#default_value' => isset($items[$delta]['codeContact']) ? $items[$delta]['codeContact'] : 'ABSL',
);
$element['addressContact'] = array(
'#type' => 'textfield',
'#title' => t('address of Contact'),
'#description' => t('max. 40 characters'),
'#size' => 45,
'#maxlength' => 40,
'#default_value' => isset($items[$delta]['addressContact']) ? $items[$delta]['addressContact'] : NULL
);
$element['emailContact'] = array(
'#type' => 'textfield',
'#title' => t('Email of Contact'),
'#description' => t('max. 60 characters'),
'#size' => 45,
'#maxlength' => 40,
'#default_value' => isset($items[$delta]['addressContact']) ? $items[$delta]['addressContact'] : NULL
);
}
//FIN FORMULAIRE COMMUN - LOCALISATION TELECOM
//...
return $element;
}
function transfert_field_formatter_info(){
return array(
'custom_default' => array(
'label' => t('Default'),
'field types' => array('transfert_customer')
)
);
}
Bien à vous
essaye sa $nid =
Permalien Soumis par adrien37000 le 14 Mars, 2013 - 18:33
essaye sa
$nid = db_insert('/ta table/') // Table name no longer needs {}
->fields(array(
'nom'=>$_POST['nom'],
'prenom'=>$_POST['prenom'],
'course'=>$_POST['course'],
'millesime'=>$_POST['millesime'],
'categorie'=>$_POST['categorie'],
'nationalite'=>$_POST['nationalite'],
'numLicence'=>$_POST['numLicence'],
'dossard'=>$_POST['dossard'],
'club'=>$_POST['club'],
'etatInscription'=>$_POST['etatInscription'],
))
->execute();
drupal_set_message(t('Le contenu à bien été ajouté'));
et pour extraire
exemple:
$course = array();
$millesime = array();
$str = db_query('SELECT course_name,millesime FROM {/ta table/}');
while ($recupe = $str->fetchAssoc()){
$course[]= $recupe['course_name'];
millesime[] = $recupe['millesime'];
}
il est ou ton:
Permalien Soumis par ced_sdml le 19 Mars, 2013 - 12:40
il est ou ton:
function hook_submit($form, $form_state) {
db_insert('ma_table')
->fields(array(
'champ1' => $form_state['values']['mon_champ1'],
'champ2' =>$form_state['values']['mon_champ2] ))
->execute();
}