I'd like to send a file to everyone who gets my webform. This should be a hidden file that the person filling in the form doesn't need to attach but the receiver gets. Its for a job advert that someone fills in a request and then they get sent back a 'Thanks' message and they are asked to fill in a word document about equal opportunities.
I guess its probably doable with webform rules but I'm not getting any luck with that.
Write a custom module with hook_form_alter implementation, and add a custom submission callback to handle the file attachment.
This way you can handle form fields and values, before the webform values getting saved in database or getting sent via email.
Code sample:
function MODULE_form_alter(&$form, &$form_state, $form_id) {
if($form_id === 'YOUR_FORM_ID') {
// code as needed in here :)
// add another submission callback
$form['submit'][] = 'YOUR_NEW_FORM_SUBMISSION_CALLBACK';
}
}
function YOUR_NEW_FORM_SUBMISSION_CALLBACK($form, &$form_state) {
// code as needed here
}
Related
My Drupal 6 installation has the php filter disabled so I can't use <?php ... ?> in the node itself.
I have a case where I need to run a little bit of PHP code on a small number of pages. Is there a way in Drupal 6 to create a module that will match a URL pattern and then before showing the page execute a function?
Specifically, on a few pages I need to process some data and then send an HTTP header. I know that I can create a custom .tpl file for these pages but putting application logic like this in a .tpl file feels like a hack.
If you want to do this specifically for node pages then you'd be better off implementing hook_nodeapi(). This would mean you don't have to perform a match based on the URL and you can add your header in the most 'structured' manner possible:
function MYMODULE_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
if ($op == 'view') {
drupal_set_header('some header');
}
}
If you need to do it for non-node pages then you'll want to implement hook_init() instead:
function MYMODULE_init() {
if ($_GET['q'] == 'node/1') { // or whatever path
drupal_set_header('some header');
}
}
Both of the hooks are invoked well before the headers are sent to the client so either way will work.
In Drupal 6 you could use code similar to the following one:
function example_user($op, &$edit, &$account, $category = NULL) {
switch($op) {
case 'load':
$account->fb_id ='xyz'
break;
}
}
In Drupal 7, the documentation for hook_user_load() states the following:
Due to the static cache in user_load_multiple() you should not use this hook to modify the user properties returned by the {users} table itself since this may result in unreliable results when loading from cache.
Why do I get users and not just a user?
Is it ok to add properties to this?
http://api.drupal.org/api/drupal/modules--user--user.api.php/function/hook_user_load/7
You get an array of user objects because the hook is called from user_load_multiple(), which generally calls DrupalDefaultEntityController::load(), which then calls DrupalDefaultEntityController::attachLoad().
It is fine to add custom properties, but not to override the default properties that are loaded from the {users} table; as reported from the documentation, in that case you could get some problem when loading the user object from the cache, which is what the entity API normally does.
Edit
The basic question here is "when does the $op parameter get defined as 'search'"?
I am trying to create a custom search in an implementation of hook_search(). I have been looking through the Drupal documentation for the method here: http://api.drupal.org/api/drupal/developer--hooks--core.php/function/hook_search/6
I know the method is running because I can slip a die('killed inside of implementation of hook_search()') into the top of the function and see the output.
In the following code, the script is never killed so that I can see the output search caught inside of my_search(). This leads me to believe that the 'search' case of the switch statement is never firing. Does anybody know where I might go from here?
/**
* Implementation of hook_search()
*/
function my_search($op = 'search', $keys = NULL) {
switch($op)
{
case 'search':
die('search caught inside of my_search()');
break;
}
}
First things first.
Assuming your module is called 'my', try to go to URL /search/my/whatever - probably you will see access forbidden page (assuming you do not have anything more in your code besides what you have pasted in your question).
That's because you do not return anything when search module calls your hook with $op = 'name' (see _search_menu() in search.module). You need to return "a translated name defining the type of items that are searched for with this module ('content', 'users', ...)" - see http://api.drupal.org/api/drupal/developer--hooks--core.php/function/hook_search/6 And access forbidden gone.
Once this is done, search will call your hook again (actually, there are quite a few calls, you can for example drupal_set_message($op) in your hook to see them all), and one of those calls will be with $op = "search" as well (coming from search_data() in search.module).
I am doing some access to content using hook_form_alter as there are problems using hook_access with content types defined outside of your module. If a user does not have access I am setting a message at the top of the page and I don't want to output the form. I have the following code.
function mymodule_form_alter(&$form, $form_state, $form_id) {
switch ($form_id) {
case 'cmyformm':
dsm($form);
$from = null;
dsm($form);
drupal_set_message('You do not have access to this page');
break;
}
}
The dsm however is returning the same information for $form even if I set it to null. How do I not display the form but a message?
I don't quite understand the question, but for starters you are setting $fROm to null and not $fORm. Setting for to null or just doing unset($form); should do the trick.
Access control shouldn't be done at the form level. Access control should be implemented with hook_access or in the router's access arguments. If you must do this at the form level, use user_access() along with the defined roles that you have.
In addition to the typo as pointed out by #zeroFIG, you are really doing this access check in the wrong way. I have used the node_example module with sucess on all node types - none were defined in the same module as the hook_access. Have a look here: http://api.drupal.org/api/examples/node_example--node_example.module/6
I'am trying to develop a Custom drupal module which will read arguments from the URL and populate the form fields accordingly.
I was successful in doing that for title filed but i was unable to that for body field and a custom cck field, i named field_url
here is my code
function formexample_form_alter(&$form, &$form_state, $form_id) {
// This code gets called for every form Drupal builds; use an if statement
// to respond only to the user login block and user login forms.
if ($form_id == 'bookmark_node_form') {
$form['title']['#value'] = $_GET['x'];
$form['field_url']['#value'] = $_GET['y'];
$form['body']['#default_value'] = $_GET['x'];
}
}
here is my url i am trying to enter http://localhost:8082/acquia-drupal/node/add/bookmark?x=hjsajskajsjasa&y=asasasasas
title field is getting populate with the value of x from the url arguments but other fields don't.
You might look to the Prepopulate module for inspiration, if it doesn't achieve your needs on its own.