I like to use a single contact form that is routed to different expert emails depending on where the user comes from. I also need the form title and intro text needs to be customized. I am using the webform module.
Example: I have a link “talk to expert A” and a second link “talk to expert B”. Both links point to the same form at forms/generic_form.
link A points to forms/generic_form?recipient=expert_a@example.com
link B points to forms/generic_form?recipient=expert_b@example.com
In the form I have set a field “recipient” with a default value of %get[recipient]
In the webform module setup I have checked the recipient email under “Conditional e-mail recipients”
Now I like to add a specific title and some intro text to the form depending on the targeted expert.
I added a webform-form.tpl.php file to my theme. My intention is to inject title and intro text into the node object via template.php. However, webform-form.tpl.php doesn’t make the node object available. It provides only access to the $form array. And the node object only includes the rendered form and unprocessed form, e.g. it will give only "%get[recipient]" as the default value not "recipient=expert_a@example.com"
I like to access the parameter that I have passed in the url (recipient=expert_a@example.com) and use that to generate context specific titles and intro text in template.php.
Sorry for the long explanation but I really would appreciate if a Drupal expert would point me in the right direction.
My question really is: Am I doing this right? If no, what is the right way of approaching this. If yes, how can I get this working?
Comments
Custom Content Type?
Are you talking about essentially having two separate forms, or would you want different text to appear on a single form, based on what a user chooses from a dropdown or other interface element? In that case, you would use JavaScript to make the change on-the-fly.
I did something similar to this by creating a custom content type and using some custom php code in the rules module to send the message with reply-to headers to a group of recipients based on their choice of subject from a dropdown. The nodes are then saved unpublished, so they can be accessed by Views, which Webform entries generally cannot.
You can add JS and CSS custom to that node-add form using the .tpl.php
This required a little work inside of a module (since modules can access nodes) to change the submit button to say "Send" and other minute details.
Not sure if this is any help, but any more details you can provide on your intended application would help to diagnose the issue.
Thanks for the reply
Thanks for the reply ao5357.
I do want to use only ONE form and that form is than "customized" depending on what link is clicked....see my original post. The links that lead to this form may eventually count in the 10s so it is important to automate the customization.
I have progressed somewhat since the original post.
I have overwritten the node template with node-webform.tpl.php in my theme folder.
In template.php I get the url argument with $_GET['argument'] and based on the argument I customize two new variables $formTitle and $formIntro.
$formTitle and $formIntro are then called in node-webform.tpl.php and bingo I have custom titles and intro section. They change depending on which link was clicked originally.
This works well but it feels like a kludge. Also, I have to maintain the different titles and intro texts in template.php. I might be able to pull in nodes for that but is currently beyond me.
Being new to Drupal I do not have a grasp on what approaches are considered best-practice. So I am looking for a better way of doing this, if there is one.
can you share some of your code?
Hey wernerglinka,
I am trying use the logic you talked about to change the email reciptant based on the url (not having the email in the url but use the argument to query a node and grab an email from a cck field)
can you share your template.php code and your node-webform.tpl.php code,
I think it would help me understand the logic and made connect the dots and go from there.
Thanks
Also would like to see how this is done
This post is kind of old now but I'm trying to do this exact same thing with webform but I'm kind of new to Drupal and still learning the structure and api. I wish there was more info here and what files to modify and and how to connect it all together. I really want to figure out how to do this. I've been searching for days but haven't found anything yet.
Anyone else still checking here?