DrupalBin
Submit Code
About
Recent Posts
Code
Fix for Fix for Code
Fix for Code
Code
Node type whitelist
an axe coach accessories
coach purses married
Fix for de las ghd alturas
de las ghd alturas
Code
more
User login
Log in using OpenID:
What is OpenID?
Username:
*
Password:
*
Log in using OpenID
Cancel OpenID login
Create new account
Request new password
Tags
CCK
drupal
fapi
jquery
menu
module
php
simpletest
taxonomy
test
theme
views
more tags
Home
›
Code
Fix for Code
View
Fix
Fixes are not saved to the database until you submit.
Summary:
Tags:
Any tags you'd like to associate with your code, delimitered by commas (example: Views, CCK, Module, etc).
Show summary in full view
<?php function hookContact_menu() { $items['contact/js/addInfos'] = array( 'page callback' => 'hookContact_addInfos', 'type' => MENU_CALLBACK, 'access callback' => TRUE, ); return $items; } /** * Implementation of hook_form_alter(). * @see http://api.drupal.org/api/function/hook_form_alter * We add a few custom fields to the default Drupal contact form */ function hookContact_form_contact_mail_page_alter(&$form, $form_state) { $form['contact_info'] = array( '#tree' => TRUE, '#prefix' => '<div id="wrapper-infos">', '#suffix' => '</div>', '#type' => 'hidden', ); $form['choix'] = array( '#type' => 'radios', '#title' => t('Type de contact'), '#default_value' => $form_state['values']['choix'], '#options' => array( 'mail' => 'mail', 'tel' => 'téléphone', ), '#ahah' => array( 'event' => 'change', 'path' => 'contact/js/addInfos', 'wrapper' => 'wrapper-infos', 'methode' => 'prepend', ), '#required' => TRUE, ); $form['copy'] = array( '#type' => 'checkbox', '#title' => t('Send yourself a copy.'), ); // reorder the elements in the form to include the elements being inserted $order = array('contact_information', 'name', 'entreprise', 'mail', 'choix', 'contact_info', 'subject', 'message', 'copy', 'submit'); foreach($order as $key => $field) { $form[$field]['#weight'] = $key; } } function hookContact_addInfos() { //On récupère id unique du formulaire $form_build_id = $_POST['form_build_id']; $cached_form_state = array(); //On récupère le formulaire en cache $cached_form = form_get_cache($form_build_id, $form_state); $cached_form['#post'] = $_POST; $cached_form_state['post'] = $_POST; //$cached_form_state['values'] = $form_state['values']; $cached_form = form_builder($form['form_id']['#value'], $cached_form, $cached_form_state); $addForm = hookContact_subForm($_POST['choix']); $cached_form = array_merge($cached_form, $addForm); form_set_cache($form_build_id, $cached_form, $cached_form_state); $debug = "<pre>".print_r($cached_form, true)."</pre>"; drupal_json(array('status' => TRUE, 'data' => $debug . drupal_render($addForm))); } function hookContact_subForm($choix) { if($choix =='tel') { return array( 'heure' => array( '#name' => 'heure', '#type' => 'select', '#options' => array( '8h-12h' => '8h-12h', '12h-14h' => '12h-14h', '14h-17h' => '14h-17h', '17h-20h' => '17h-20h', ), ), 'jour' => array( '#name' => 'jour', '#type' => 'select', '#options' => array( 'lundi' => 'Lundi', 'mardi' => 'Mardi', 'mercredi' => 'Mercredi', 'jeudi' => 'Jeudi', 'vendredi' => 'Vendredi', ), ), 'tel' => array( '#name' => 'tel', '#type' => 'textfield', '#title' => t('Votre numéro de téléphone'), ) ); } else if($choix =='mail'){ return array(); } } function hookContact_mail_alter(&$message) { $v = var_export($message, true); drupal_set_message("message: " . $v); switch($message['id']) { case 'contact_page_mail': if($message['params']['choix'] == 'tel') { $message['body'][] = 'Moyen de contact : téléphone\n'; $message['body'][] = 'Numéro de téléphone : '. $message['params']['tel']; $message['body'][] = 'Jour et heure : le '. $message['params']['jour'] .' entre '.$message['params']['heure'] ; } else { $message['body'][] = 'Moyen de contact : mail '; } break; } }
Syntax highlighting mode:
ActionScript
ColdFusion
Diff
Drupal 5
Drupal 6
HTML
INI
Javascript
MySQL
PHP
Python
robots.txt
SQL
Text
Select the syntax highlighting mode to use.
See Also:
Order
Title:
URL:
-1
0
1
Title:
URL:
-1
0
1
Any links you'd like to have associated with the post (Drupal.org issue, Wikipedia article, etc).
File attachments
Changes made to the attachments are not permanent until you save this post. The first "listed" file will be included in RSS feeds.
Attach new file:
The maximum upload size is
1 MB
. Only files with the following extensions may be uploaded:
jpg jpeg gif png txt doc xls pdf ppt pps odt ods odp phps
.