I am at my wits end trying to use the hook_webform_submission_presave function on a webform that I have created for a Drupal 7 site. Ideally I would like to capture a list of nodes that a user has flagged and transfer that data into a field before the user submits their form. But the function is just not adding the data.  First I get the flags:  $flags = flag_get_user_flags($node-&gt;type);   Then I want to transfer that variable into a field with a component ID of 32.  // Update some component's value before it is saved.   $component_id = 32;   $submission-&gt;data[$component_id]['value'][0] = $flags;   Here is the full function:  function get_flags_webform_submission_presave($node, &amp;$submission) { $nodes_list = array(); $title = '';   // Get the flags.   $flags = flag_get_user_flags($node-&gt;type);    // Get the nodes.   if (!empty($flags)) { foreach ($flags as $flag) {     $nid = $flad-&gt;entity_id;     // Get node data. Delete to not get node titles.     $node = node_load($nid);     $title = $node-&gt;title;     // Combine data.     $nodes_list[] .= 'node/' . $nid . ' ' . $title . ",\n";     }   }    // Update some component's value before it is saved.   $component_id = 32;   $submission-&gt;data[$component_id]['value'][0] = $nodes_list; }   What am I doing wrong? I'd love some help!
120824
I am creating a page where I have a view listing about 100 nodes of a specific content type and then underneath that I have a contact form. When visitors (logged out users) come to my site I would like them to be able to select some nodes from this view that they like. Either with a checkbox next to each one of them or by some other flagging system. When they then complete my form the specific nodes they have chosen will be sent with the form submission.   Possible Solutions:   Create a template file for the view and add in a checkbox in front of each node. Use the flags module and pass the selected nodes when submitting.    I've never done something like this before so any help would be appreciated!
45620
I'm using drupal_get_form('event_signup_form') to embed my custom form inside a block. The form is being rendered as intended, but submitting the form triggers nothing.  The form function itself is called event_signup_form($form, &amp;$form_state) and the submit function is called event_signup_form_submit($form, &amp;$form_state) but it's not being called.  I am using  to show the form:  function event_block_view($delta = '') { $blocks = array(); if ($delta ...) { $blocks['content'] = drupal_render(drupal_get_form('event_signup_form')); } }   I managed to get this working - here is how (stub):  function hook_block_view($delta = '') { $blocks['content'] = drupal_render(drupal_get_form('event_signup_form')); }  function event_signup_form() { // Register form submit handler, same goes for validation handler $form['#submit'][] = 'event_signup_form_submit';  return $form; }  function event_signup_form_submit($form, &amp;$form_state) { // This is now triggered }
54687
The  documentation provides this example:  &lt;aura:component&gt;     &lt;lightning:recordEditForm recordId="003XXXXXXXXXXXXXXX" objectApiName="Contact"&gt;         &lt;lightning:messages /&gt;         &lt;lightning:inputField fieldName="FirstName" /&gt;         &lt;lightning:inputField fieldName="LastName" /&gt;         &lt;lightning:inputField fieldName="Email" /&gt;         &lt;lightning:button class="slds-m-top_small" variant="brand" type="submit" name="update" label="Update" /&gt;     &lt;/lightning:recordEditForm&gt; &lt;/aura:component&gt;   where a a click on the nested submit button causes the data to be saved.  Anyone know of a reliable/documented way to get the lightning:recordEditForm to save based on a click of a button located elsewhere in the page?
83825
How does one remove a field from a node programmatically? I have a migration in hook_update_N that moves the contents from a a field into a custom table. After that migration, I want to remove the field in that same function.  Are there any field API's that cater removing fields?  Edit, Solution: Because the answers lack actual code, here is what I did to move fields from the $users into my own records and subsequently remove the field from the database;  function my_module_update_7005(&amp;$sandbox) {   $slice = 100;   //Fetch users from database;   if (!isset($sandbox['progress'])) {     $sandbox['progress'] = 0;     $sandbox['current_uid'] = 0;     // We'll -1 to disregard the uid 0...     $sandbox['max'] = db_query('SELECT COUNT(DISTINCT uid) FROM {users}')-&gt;fetchField() - 1;   }   if (empty($users)) {     $sandbox["current_uid"] += $slice;   }   $users = db_select('users', 'u')     -&gt;fields('u', array('uid', 'name'))     -&gt;condition('uid', $sandbox['current_uid'], '&gt;')     -&gt;range(0, $slice)     -&gt;orderBy('uid', 'ASC')     -&gt;execute();   //Loop trough users;   foreach ($users as $user) {     $foo = new Foo();     // Warning: drupal's fields return mixed values; e.g. NULL versus an int.     $foo-&gt;debits = (int) $user-&gt;user()-&gt;field_credits["und"][0]["value"];     $foo-&gt;save();      $sandbox['progress']++;     $sandbox['current_uid'] = $user-&gt;uid;   }    $sandbox['#finished'] = empty($sandbox['max']) ? 1 : ($sandbox['progress'] / $sandbox['max']);    // Remove the field.   field_delete_field("field_credits"); //note that the name for Foo is field_foo   field_purge_batch($sandbox['max']+1);//Drupal seems to have an offbyone problem. }
46594
I have created a few webforms on our development server and would like to move them over to a production installation. Can I do this with node export?   I'm not concerned with migrate any user responses (as we were only testing).
27845
Is there still a hook_nodeapi in drupal 7 or do i have to try hook_node_load hook for appending some content to node?
122548
I have a submit button in my form and I want to implement it using ajax:  function myid_user_page_form(){      drupal_add_library('system', 'drupal.ajax');     $form = array();     $form['id'] = array(        '#type' =&gt; 'fieldset',        '#title' =&gt; t('ID Information'),        '#prefix' =&gt; '&lt;div id="myid_search_id_number_wrapper"&gt;',        '#suffix' =&gt; '&lt;/div&gt;'    );       $form['submit'] = array(       '#type' =&gt; 'button',       '#value' =&gt; 'Save',          '#ajax' =&gt; array(          'event' =&gt; 'click',          'callback' =&gt; 'myid_user_page_form_ajax_submit',          'wrapper' =&gt; 'myid_search_id_number_wrapper'       ),        '#attributes' =&gt; array(         'id' =&gt; 'myid_save',                    ), );  function myid_user_page_form_ajax_submit($form, &amp;$form_state) {      watchdog('Wow','Wow'); }   After executing the code above, the page still has it's refresh after it's clickfunctionality. The ajax doesnt work and no Wow message log in my watchdog table from my database, which means the ajax callback function isn't called. Where am I missing?
46315
I'm trying to query webform submissions based on a field value. The field is called "ticket_for". Somethings I tried and do not work:      -&gt;condition('ticket_for',$adnummer)     -&gt;condition('webform_submission_data:ticket_for',$adnummer,'CONTAINS') ...   What kind of condition should I be using in a query like this?  $query = \Drupal::entityQuery('webform_submission') -&gt;condition('webform_id', 'ticket') -&gt;condition('entity_id', $eventID) -&gt;condition('webform_submission_data:ticket_for',$adnummer,'CONTAINS');
89222
How do I get the form id of my form? I've just begun to make my modules and I'm at a standstill. I got this code from someone else and am trying to customize it:  function hook_form_alter(&amp;$form, &amp;$form_state, $form_id) {   if ($form_id == 'the form id for the node form') {     $form['#submit'][] = 'my_custom_submit_handler';   } }
41000
I'm trying to add two links on custom user form. The goal is this links to be displayed bellow the submit button.  I've tried with weight property, but it's not working.   What do I miss?  This is my code:  &lt;?php       function custom_alter_form_alter (&amp;$form, &amp;$form_state, $form_id) {          switch ($form_id) {                 case 'user_login':                  $form['name']['#title'] = t('Username');                 $form['pass']['#title'] = t('Password');                 $form['actions']['submit']['#value'] = t('Login');                 $form['actions']['submit']['#weight'] = 0;                  $form['page'] = array(                 '#markup' =&gt; '&lt;h2&gt;Login&lt;/h2&gt;',                 '#weight' =&gt; -10,                 );                  $form['register'] = array(                  '#type' =&gt; 'markup',                     '#markup' =&gt; '&lt;div class="user-login-register"&gt;You don't have an account?                 &lt;a class="user-login-register" href="/user/register"&gt;  Click here&lt;/a&gt;&lt;/div&gt;',                 '#weight' =&gt; 1,                 );                  $form['password_reset'] = array(                 '#markup' =&gt; '&lt;a class="user-login-password-reset" href="/user/password"&gt; You forgot your password&lt;/a&gt;',                 '#weight' =&gt; 2,                 );                  //krumo($form);                  break;             }          }
29087
/**  * Implements hook_form_alter().  */ function MODULE_NAME_form_alter(   &amp;$form,   \Drupal\Core\Form\FormStateInterface $form_state,   $form_id ) {    if ($form_id == 'node_article_form') {     $form["body"]["widget"][0]['#allowed_formats'] = ['full_html']; // Your default format     $form["body"]["widget"][0]['#after_build'][] = 'MODULE_NAME_hide_format';   } }  function MODULE_NAME_hide_format(   &amp;$element,   FormStateInterface $form_state ) {   if (isset($element["format"]["format"])) {     $element["format"]["format"]["#access"] = FALSE;   }    return $element; }
18957
I have read this post  about how to use field_attach_update to save nodes without the overhead of node_save().  I would like to use this for users (which it should work for, as per ) . However, I'm not sure how to apply the examples to users.  Currently, this is my code:  if (isset($uid)) {     $user = user_load($uid);     $user_og_groups = $user-&gt;og_user_node[LANGUAGE_NONE];     $user_committee_positions = $user-&gt;field_committee_position_serno[LANGUAGE_NONE];     $user_data = my_module_import_user($cust_info, $cust_attributes, $drupal_countries, $employers);     $user = user_save($user, $user_data);   }   The $user_data variable is an array of data, which is what user_save expects (). user_save() doesn't work exactly the same as node_save() and doesn't accept a user object.  How then can I use field_attach_update to programmatically update users?
8593
I have a paragraphs field that takes a term reference.  I need to count how many terms there are for a specific vocabulary and then create that many instance of the paragraphs multiple value field for when creating a node of a certain type. Can this be done with Hook_form_alter ?  It is important that these fields are loaded when the node creation form is loaded rather than the user having to click add more  Any help would be greatly appreciated  I have tried this but when saving the node it doesn't save the new fields  function hook_form_alter(&amp;$form, $form_state, $form_id) {    if ($form_id == 'my_form') {    $item = $form['field_features']['widget']['0'];    // get taxonomy terms   $query = \Drupal::entityQuery('taxonomy_term');   $query-&gt;condition('vid', "my_voc");   $tids = $query-&gt;execute();   $terms = \Drupal\taxonomy\Entity\Term::loadMultiple($tids);    $count = count($terms);    $i = '1';   foreach($terms as $term){     $form['field_features_para']['widget'][$i] = $item;     $form['field_features_para']['widget'][$i]['#delta'] = $i;     $form['field_features_para']['widget'][$i]['#weight'] = $i;     $i ++;   }  } }
47613
I am using an checkboxes element within a form in module that I started developing for Drupal 7. This is my first attempt at module development and using the Form API. I am creating a list of checkboxes that list down all the content types of a specific site. An array of all the content types can be obtained by using the following: $nodeTypesRaw=node_type_get_names();. An array with the machine names of the content types as the keys and the human readable names as the values are obtained.  By default, I would like all the checkboxes to be selected and when the form is submitted. How do I achieve that? The Form API pages on the drupal site aren't very helpful with regards to setting the default values for checkboxes.   $nodeTypesRaw=node_type_get_names(); $nodeMachineNames=array_keys($nodeTypesRaw); $form['process_comments']['custommod_published_comments_select_node_types']['custommod_published_comments_node_types_checkboxes']=array(           '#deafult_value'=&gt;$nodeMachineNames,           '#options'=&gt;$nodeTypesRaw,           '#type'=&gt;'checkboxes', );   I initially started out with the above code, but it won't work. It does display the list of checkboxes, but they are not checked by default. The variable does get on form submission though (checked via drush and var_dump).
44848
I'm using Drupal 7 and created a content type 'NewArticle' with the fields 'Title', 'Text' and 'Image'. Users have the permission to create a 'NewArticle', but I don't like the way of displaying the administration bar in order to let them create a 'NewArticle'.  Instead, I'd like to work with . My goal is to create a Webform with exactly the same fields as the content type 'NewArticle'. So what I want is: when users filled in the form and submit it, a new node 'NewArticle' is created with the submitted information.  How can I do this? Are there modules that make this possible? I can't find any...
64525
I'd like to do something pretty straightforward: After user fills out a , I'd like a button that simply redirects them to a URL (in this case it's to a demo sandbox). Of course I'd want the user to fill in their info to capture for lead-generation purposes. My  is set up correctly in that it correctly captures all the user fields and submits them to me via email. However, upon completion "click" I'd like to have the user redirected to a determined internal URL www.mysite.com/foo  I can't figure out how this is done with the vanilla webform settings. Am I missing something obvious?
67969
I have a custom search form that I posts a year + month, such as 2014-04 I would like to get all nodes created that month, when I create the timestmap I use: "SELECT .......         AND changed >= 'strtotime($date)'"  This is the code for form date:  $form['aqar_date'] = array( '#type' =&gt; 'date_select',  '#title' =&gt; t('Date'), '#prefix' =&gt; '&lt;div id="space_replace" class="search-title-date"&gt;   &lt;h2&gt;Node date&lt;/h2&gt;', '#suffix' =&gt; '&lt;/div&gt;',      '#date_format' =&gt; 'Y-m', '#default_value' =&gt; date('Y-m'), '#date_year_range' =&gt; '-4:+0',  );   This is the form submit:  $start_date = strtotime($date); $query = " SELECT `nid` FROM `node` WHERE  `type` = 'custom'  AND `changed` &gt;= '$start_date'";   But I'm not getting, I need a way to specify to only this month period not this month and newer!  Thanks!