I'm using a custom module to change subject and recipient email. Actually my fields are a single text field for the subject, and a select field for recipients.
I would like to add a more options actually. My webform is on a public page opened to all. I add a new page with a link to the contact form and I want that link to provide some options.
So my link is like this: /node/5?option=1
This bring me to the aforementioned page and set the subject field according to my custom module like this:
function ca_formdispatch_form_alter(&$form, &$form_state, $form_id)
{
$nid = arg(1);
drupal_set_message(t(" webform_client_form: .", $form_id));
//determination de l'ID du formulaire afin de l'alt�rer
if ($form_id == 'webform_client_form_5' && $nid == 5)
{
$origine = $_GET['origine'];
drupal_set_message(t("contenu d'origine : @origine.", array("@origine" => $origine)));
//liste des email destintaire possible en fonction de l'origine du destinataire
switch ($origine)
{
case '1':
$email_dest='[email protected]';
$sujet_mail="Message pour 1";
break;
case '2':
$email_dest='[email protected]';
$sujet_mail="Message pour 2";
break;
}
//affectation de la valeur de $email_dest comme email destinataire du message,
$form['submitted']['destinataire']['#default_value']=$email_dest;
drupal_set_message(t("contenu de email : @email.", array("@email" => $email_dest)));
//affectation de la valeur de $sujet_mail comme sujet du message
$form['submitted']['sujet']['#default_value']=$sujet_mail;
drupal_set_message(t("contenu de sujet mail : @sujet_mail.", array("@sujet_mail" => $sujet_mail)));
}
}
It works for the subject field but not for the recipient field. My recipient select field can take 4 options. I can set the select on an existing key but not add a new key not provided by the select by default.
I would to lock the key set by the module or hide the select field to don't allow is change by the user that did click on the link before.Is it possible? I know I can use hook_webform_select_options
or hook_webform_select_options_alter
but I don't know how with to make this code ... if someone could help me.
EDIT: i test this to get the "key" and pass it to the webform field but i think it doesn't work.
switch ($origine) {
case 'charge-relation-entreprise'://valeur de $origine
$clef="Chargé des Relations Entreprises";
$email='[email protected]';
break;....
$form['submitted']['choisissez_votre_destinataire']['#options'][$clef] = $clef;
$form['submitted']['choisissez_votre_destinataire']['#value']=$clef;
$form['submitted']['choisissez_votre_destinataire']['#key']=$clef;
but if this display the right text in the select,it doesn't send mail...
EDIT2 : i get the right key label displayed if i set a default value key in the webform select list setting like here https://computing.artsci.wustl.edu/help/drupal-webforms-advanced
But my select doesn't work anymore if i go to the webform page directly,whithout instructions in the url.Like with the edit1