Jump to content

calebm12

New Members
  • Posts

    9
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

calebm12's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Sorry for my ignorance. very green. not sure how to mix that into the code $pieces = explode(" ", $node->email_recipients); foreach ($pieces as $node->email_recipients); function citizenspeak_nodeapi(&$node, $op) { switch ($op) { case 'presave': $node->email_recipients = $node->email_recipients.'@metrofax.com'; } }
  2. I am using the following code to amend a value entered in a field prior to inserting in a database. i am wondering how to change it so that if the field has multiple values (separted with comma or space) it will amend each value and not just the last one. function citizenspeak_nodeapi(&$node, $op) { switch ($op) { case 'presave': $node->email_recipients = $node->email_recipients.'@metrofax.com'; } }
  3. From what i can tell all the operation is coming from two php files. The first <?php // $Id: citizenfax.node.php,v 1.12.2.2.2.1 2009/02/03 00:48:14 matt2000 Exp $ /** * @file * Node module functions for the citizenfax module */ /** * Implementation of hook_access(). */ function citizenfax_access($op, $node) { global $user; if ($op == 'create') { // Only users with permission to do so may create this node type. return user_access('create campaigns'); } // Users who create a node may edit or delete it later, assuming they have the // necessary permissions. if ($op == 'update' || $op == 'delete') { if (user_access('edit own campaigns') && ($user->uid == $node->uid)) { return true; } } if ($op == "collect contact information") { if (user_access('collect contact information') && ($user->uid == $node->uid)) { return true; } } return null; } // function citizenfax_access /** * Implementation of hook_delete(). */ function citizenfax_delete($node) { db_query("DELETE FROM {citizenfax_campaigns} WHERE nid = %d", $node->nid); } // function citizenfax_delete /** * Implementation of hook_form(). */ function citizenfax_form($node) { $form = array(); $form['title'] = array( '#type' => 'textfield', '#title' => t('Title'), '#default_value' => $node->title, '#size' => 60, '#maxlength' => 128, '#required' => TRUE, ); // Now we define the form elements specific to our node type. $form['email_message'] = array( '#type' => 'textarea', '#title' => t('Fax Message'), '#default_value' => $node->email_message, '#cols' => 60, '#rows' => 20, '#description' => t('Note: This text will be followed by the participant\'s contact information.'), '#required' => TRUE, ); $form['email_recipients'] = array( '#type' => 'textarea', '#title' => t('Send Fax To'), '#default_value' => $node->email_recipients, '#cols' => 60, '#rows' => 3, '#description' => t('IMPORTANT: Enter the fax number with area code followed by @metrofax.com (ex:2223334444@metrofax.com). Do NOT use a 1 before the area code and do NOT use hyphens. Separate multiple fax destinations with a comma.'), '#required' => TRUE, ); $form['campaign_format'] = array( '#type' => 'checkbox', '#title' => t('Put personal statements at top of letter'), ); return $form; } // function citizenfax_form /** * Implementation of hook_insert(). */ function citizenfax_insert($node) { db_query("INSERT INTO {citizenfax_campaigns} (nid, email_message, email_recipients, campaign_format) VALUES (%d, '%s', '%s', %d)", $node->nid, $node->email_message, $node->email_recipients, $node->campaign_format); // drupal_set_message(t('<p>The campaign "%title" has been saved and the following web address has been activated: %url</p><p>Pass the web address along to people you wish to join your campaign.</p><p>To monitor your campaign, please go to <a href="%url/report">%url/report</a></p><p>Good Luck!<br />%site_name</p>', array("%title" => $node->title, "%url" => url("node/". $node->nid, array('absolute' => true)), "%site_name" => variable_get("site_name", "")))); } // function citizenfax_insert /** * Implementation of hook_load(). */ function citizenfax_load($node) { return db_fetch_array(db_query('SELECT * FROM {citizenfax_campaigns} WHERE nid = %d', $node->nid)); } // function citizenfax_load /** * Implementation of hook_node_info(). */ function citizenfax_node_info() { return array( 'citizenfax' => array( 'name' => t('citizenfax'), 'module' => 'citizenfax', 'description' => t('The citizenfax module allows the creation of Fax petition campaign nodes. Users enter the Fax recipients and the a message to create a campaign. When someone visits the node, they see a form that displays a preview of the message and allows them to enter their contact information and a personal statement. When they submit the form, the target of the campaign is notified.') ) ); } /** * Implementation of hook_update(). */ function citizenfax_update($node) { db_query("UPDATE {citizenfax_campaigns} SET email_message = '%s', email_recipients = '%s', campaign_format = %d WHERE nid = %d", $node->email_message, $node->email_recipients, $node->campaign_format, $node->nid); } // function citizenfax_update /** * Implementation of hook_validate(). * * @param &$node The node to be validated. */ function citizenfax_validate(&$node) { if (isset($node->email_message) && $node->email_message == '') { form_set_error('email_message', 'You must provide a fax message'); } if (isset($node->email_recipients)) { if ($node->email_recipients == '') { form_set_error('email_recipients', 'You must provide at least one fax address.'); } $recipients = _citizenfax_split_emails($node->email_recipients); if (count($recipients) > 25) { form_set_error('email_recipients', 'You may not have more than 25 fax addresses.'); } foreach ($recipients as $email) { if (!valid_email_address($email)) { form_set_error('email_recipients', 'You must provide valid fax addresses.'); break; } } } // if (isset($node->email_recipients)) } // function citizenfax_validate /** * Implementation of hook_view(). * * @param &$node The node to be displayed. * @param $teaser Whether we are to generate a "teaser" or summary of the node, * rather than display the whole thing. * @param $page Whether the node is being displayed as a standalone page. If * this is TRUE, the node title should not be displayed, as it will be printed * automatically by the theme system. Also, the module may choose to alter the * default breadcrumb trail in this case. * @return None. The passed-by-reference $node parameter should be modified as * necessary so it can be properly presented by theme('node', $node). */ function citizenfax_view($node, $teaser = FALSE, $page = FALSE){ $node->body .= theme('citizenfax_message_preview', $node); if (user_access('participate in campaigns')) { $node->body .= _citizenfax_participate_display($node); } $node->teaser .= $node->email_message; $node->content['body']['#value'] = ($teaser) ? $node->teaser : $node->body; return $node; } // function citizenfax_view /** * Display the form to participate in a campaign * * @param $node * A citizenfax campaign node */ function _citizenfax_participate_display($node) { return drupal_get_form('citizenfax_send_petition_form'); } // function _citizenfax_form_display function citizenfax_send_petition_form(){ $form = array(); $form['name'] = array( '#type' => 'textfield', '#title' => t('Name'), '#required' => TRUE, ); $form['organization'] = array( '#type' => 'textfield', '#title' => t('Organization'), '#required' => FALSE, ); $form['email'] = array( '#type' => 'hidden', '#title' => t('Email'), '#required' => TRUE, '#default_value' => 'akp@que.com', ); $form['address'] = array( '#type' => 'textfield', '#title' => t('Address'), '#required' => variable_get('citizenfax_require_address', 1), ); $form['city'] = array( '#type' => 'textfield', '#title' => t('City'), '#required' => variable_get('citizenfax_require_address', 1), ); $state_array = array('', 'Alabama', 'Alaska', 'Arizona', 'Arkansas', 'California', 'Colorado', 'Connecticut', 'Delaware', 'District of Columbia', 'Florida', 'Georgia', 'Hawaii', 'Idaho', 'Illinois', 'Indiana', 'Iowa', 'Kansas', 'Kentucky', 'Louisiana', 'Maine', 'Maryland', 'Massachusetts', 'Michigan', 'Minnesota', 'Mississippi', 'Missouri', 'Montana', 'Nebraska', 'Nevada', 'New Hampshire', 'New Jersey', 'New Mexico', 'New York', 'North Carolina', 'North Dakota', 'Ohio', 'Oklahoma', 'Oregon', 'Pennsylvania', 'Rhode Island', 'South Carolina', 'South Dakota', 'Tennessee', 'Texas', 'Utah', 'Vermont', 'Virginia', 'Washington', 'West Virginia', 'Wisconsin', 'Wyoming'); $form['state'] = array( '#type' => 'select', '#title' => t('State'), '#options' => drupal_map_assoc($state_array), '#extra' => 0, '#multiple' => FALSE, '#required' => variable_get('citizenfax_require_address', 1), ); $form['zip'] = array( '#type' => 'textfield', '#title' => t('ZIP code'), '#size' => 5, '#maxlength' => 5, '#required' => variable_get('citizenfax_require_address', 1), ); $form['fax'] = array( '#type' => 'textfield', '#title' => t('Phone'), '#required' => FALSE, ); $form['personal_statement'] = array( '#type' => 'textarea', '#title' => t('Personal statement'), '#cols' => 60, '#rows' => 20, '#description' => t('This will be included in the fax sent.'), ); /* $form['nid'] = array( '#type' => 'value', '#value' => 0, ); */ $form['send'] = array( '#type' => 'submit', '#value' => t('Send'), ); return $form; } function citizenfax_form_alter(&$form, &$form_state, $form_id) { // put in the current node ID based on the arguments coming into the request. if($form_id == 'citizenfax_send_petition_form'){ $form_state['nid'] = arg(1); } } <?php // $Id: citizenfax.module,v 1.15.2.2.2.2 2009/02/03 00:48:14 matt2000 Exp $ /** * @file The main citizenfax module file * * @author George Hotelling <http://george.hotelling.net/> * * @todo Create SimpleTest tests. * * @todo Create CiviCRM integration */ require_once(drupal_get_path('module', 'citizenfax') .'/citizenfax.node.php'); require_once(drupal_get_path('module', 'citizenfax') .'/citizenfax.theme.php'); require_once(drupal_get_path('module', 'citizenfax') .'/citizenfax.lib.php'); require_once(drupal_get_path('module', 'citizenfax') .'/citizenfax.reports.php'); require_once(drupal_get_path('module', 'citizenfax') .'/citizenfax.user.php'); /** * Implementation of hook_help(). * * @param $section * Section which section of the site we're displaying help * @return * Help text for section */ function citizenfax_help($section) { switch ($section) { case 'admin/modules#description': // This description is shown in the listing at admin/modules. return t('Allows email action campaigns to be created'); case 'node/add#citizenfax': // This description shows up when users click "create content." return t('A citizenfax campaign is a form that allows people to send pre-made emails to a specific address.'); } } // function citizenfax_help /** * Implementation of hook_menu(). * * Creates: * A menu item to add a campaign at node/add/citizenfax * A local task for citizenfax_report() at node/###/report * A menu callback for citizenfax_thank_you() at node/###/thank_you */ function citizenfax_menu() { $items = array(); // citizenfax campaigns page. $items['citizenfax'] = array( 'title' => 'All citizenfax Campaigns', 'access callback' => 'user_access', 'access arguments' => array('access content'), 'page callback' => 'citizenfax_page', 'type' => MENU_SUGGESTED_ITEM ); // citizenfax administration page. $items['admin/settings/citizenfax'] = array( 'title' => 'citizenfax', 'description' => 'Allows the creation of email petition campaign nodes.', 'page callback' => 'drupal_get_form', 'page arguments' => array('citizenfax_admin_settings'), 'access callback' => 'user_access', 'access arguments' => array('administer site configuration'), 'type' => MENU_NORMAL_ITEM, // optional ); $items['node/%node/report'] = array( 'title' => 'view campaign reports', 'page callback' => 'citizenfax_report', 'page arguments' => array(1), 'access callback' => 'citizenfax_check_report_access', 'access arguments' => array(1), 'weight' => 3, 'type' => MENU_LOCAL_TASK ); $items['node/%node/thank_you'] = array( 'title' => 'Thank You!', 'page callback' => 'citizenfax_thank_you', 'page arguments' => array(1), 'access callback' => 'user_access', 'access arguments' => array('participate in campaigns'), 'type' => MENU_CALLBACK ); return $items; } // function citizenfax_menu function citizenfax_check_report_access($node) { if ($node->type != 'citizenfax') { return; } global $user; if(($node->uid == $user->uid) && user_access('collect contact information')) { return TRUE; } return FALSE; } /** * Implementation of hook_perm(). * * @return An array of valid permissions for the citizenfax module */ function citizenfax_perm() { return array('create campaigns', 'edit own campaigns', 'participate in campaigns', 'collect contact information', 'customize thank you page', 'administer citizenfax'); } // function citizenfax_perm define("CITIZENFAX_DEFAULT_REMINDER_SUBJECT", t('Reminder about your campaign')); define("CITIZENFAX_DEFAULT_REMINDER_TEMPLATE", t('Your campaign "%title" has received %count responses. You can download reports about your campaign at %url.')); /** * Implementation of hook_settings(). * * Module configuration settings * @return settings HTML or deny access */ function citizenfax_admin_settings() { $form['citizenfax_debug'] = array( '#type' => 'checkbox', '#title' => t('Turn on debugging?'), '#return_value' => 1, '#default_value' => variable_get('citizenfax_debug', 0), '#description' => t('When debugging is on, campaign messages will be displayed on the screen instead of emailed to the recipient.'), ); $form['citizenfax_signature'] = array( '#type' => 'textarea', '#title' => t('Email Signature'), '#default_value' => variable_get('citizenfax_signature', ""), '#cols' => 60, '#rows' => 6, '#description' => t('If set, "-- " and this message will be added to the end of every campaign message sent. These variables will be replaced with information about the campaign: %title, %url, %nid'), ); $form['citizenfax_show_to'] = array( '#type' => 'checkbox', '#title' => t('Show recipient?'), '#return_value' => 1, '#default_value' => variable_get('citizenfax_show_to', 1), '#description' => t('Should the campaign display where it will be sent?'), ); $form['citizenfax_signature'] = array( '#type' => 'textarea', '#title' => t('Email Signature'), '#default_value' => variable_get('citizenfax_signature', ""), '#cols' => 60, '#rows' => 6, '#description' => t('If set, "-- " and this message will be added to the end of every campaign message sent. These variables will be replaced with information about the campaign: %title, %url, %nid.'), ); // Reminder email settings $form['reminder'] = array( '#type' => 'fieldset', '#title' => t('Reminder Emails'), '#description' => t('Campaign creators can be sent emails to remind them to download their reports.'), ); $form['reminder']['citizenfax_remind_15'] = array( '#type' => 'checkbox', '#title' => t('Remind user to download report after 15 participants'), '#return_value' => 1, '#default_value' => variable_get('citizenfax_remind_15', 0), ); $form['reminder']['citizenfax_remind_50'] = array( '#type' => 'checkbox', '#title' => t('Remind user to download report after 50 participants'), '#return_value' => 1, '#default_value' => variable_get('citizenfax_remind_50', 0), ); $form['reminder']['citizenfax_remind_100'] = array( '#type' => 'checkbox', '#title' => t('Remind user to download report after 100 participants'), '#return_value' => 1, '#default_value' => variable_get('citizenfax_remind_100', 0), ); $form['reminder']['citizenfax_reminder_subject'] = array( '#type' => 'textfield', '#title' => t('Reminder email subject'), '#default_value' => variable_get('citizenfax_reminder_subject', CITIZENFAX_DEFAULT_REMINDER_SUBJECT), ); $form['reminder']['citizenfax_reminder_template'] = array( '#type' => 'textarea', '#title' => t('Reminder email template'), '#default_value' => variable_get('citizenfax_reminder_template', CITIZENFAX_DEFAULT_REMINDER_TEMPLATE), '#cols' => 60, '#rows' => 6, '#description' => t('These variables will be replaced with information about the campaign: %title, %count, %url.'), ); return system_settings_form($form); } // function citizenfax_settings /** * Implementation of hook_user(). * * @param $op * What kind of action is being performed * @param $edit * The array of form values submitted by the user * @param $user * The user object on which the operation is being performed * @param $category * The active category of user information being edited * @return see hook_user() docs. */ function citizenfax_user($op, &$edit, &$user, $category = false) { $function = "citizenfax_user_" . $op; if (function_exists($function)) { return call_user_func_array($function, array($edit, $user, $category)); } } /** * Implementation of hook_block(). * * @param $op * The operation from the URL * @param $delta * Offset * @return block list array or block content array */ function citizenfax_block($op = 'list', $delta = 0) { // listing of blocks, such as on the admin/block page if ($op == "list") { $block[0]["info"] = t('popular citizenfax campaigns'); return $block; } else { $most_popular = db_query(db_rewrite_sql('SELECT n.nid, n.title, COUNT(*) AS participants FROM {node} n LEFT JOIN citizenfax_participants AS cp ON n.nid = cp.nid WHERE n.type = \'citizenfax\' AND DATE_SUB(CURDATE(), INTERVAL 1 MONTH) < cp.sent_at AND n.promote = 1 AND n.status = 1 GROUP BY n.nid ORDER BY participants DESC LIMIT 5')); $num_rows = FALSE; while($campaign = db_fetch_object($most_popular)) { $campaigns[] = l($campaign->title, "node/$campaign->nid"); $num_rows = TRUE; } if($num_rows) { $block['subject'] = t('popular campaigns'); $block['content'] = theme('item_list', $campaigns) . l(t("all campaigns"), "citizenfax"); return $block; } } } // end citizenfax_block /** * Handles sending the campaign participation * * @param $nid * Node ID of the campaign */ function citizenfax_send_petition_form_submit($form_id, &$form_state) { // Log response db_query("INSERT INTO {citizenfax_participants} (nid, name, organization, email, address, city, state, zip, phone, fax, personal_statement, sent_at) VALUES (%d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d, '%s', '%s', NOW())", $form_state['nid'], $form_state['values']['name'], $form_state['values']['organization'], $form_state['values']['email'], $form_state['values']['address'], $form_state['values']['city'], $form_state['values']['state'], $form_state['values']['zip'], $form_state['values']['phone'], $form_state['values']['fax'], $form_state['values']['personal_statement']); $id = db_last_insert_id('citizenfax_participants', 'id'); // Make email content $node = node_load($form_state['nid']); $participant = db_fetch_object(db_query("SELECT * FROM {citizenfax_participants} WHERE id = %d", $id)); $message = theme("citizenfax_message", $node, $participant); $headers = theme("citizenfax_message_headers", $node, $participant); // Send reminder emails if necessary _citizenfax_send_reminders($node); // Call hook_citizenfax_send module_invoke_all("citizenfax_send", $node, $participant); // Send email (or display debugging page) if (!variable_get('citizenfax_debug', 0)) { if(!mail($node->email_recipients, $node->title, $message, $headers)) { // drupal_set_message("ERROR: Mail was not sent. Please contact the site administrator", 'error'); print $note->title . $message . $headers; } // Redirect to thank you page drupal_goto("node/". $form_state['nid'] ."/thank_you"); } else { return theme('citizenfax_debug_page', $node, $message, $headers); } } /** * Displays the campaign thank you page * * @param $nid * Node ID of the campaign */ function citizenfax_thank_you($node) { // $node = node_load($nid); $owner = user_load(array('uid' => $node->uid)); if ($owner->use_redirect) { header("Location: ". $node->redirect_url); exit(); } $output = theme('citizenfax_thank_you', $node, $owner); echo theme('page', $output); } /** * Displays all published campaigns on the site */ function citizenfax_page() { drupal_set_title(t('all citizenfax campaigns')); $result = pager_query(db_rewrite_sql("SELECT n.nid, n.sticky, n.created FROM {node} n WHERE n.promote = 1 AND n.status = 1 AND n.type = 'citizenfax' ORDER BY n.sticky DESC, n.created DESC"), variable_get('default_nodes_main', 10)); $output = ''; $num_rows = FALSE; while ($node = db_fetch_object($result)) { $output .= node_view(node_load($node->nid), 1); $num_rows = TRUE; } if ($num_rows) { $output .= theme('pager', NULL, variable_get('default_nodes_main', 10), 0); } print theme('page', $output); }
  4. Bricktop Unfortuntaly i do not see some of those elements you are talking about in the code. I do not know if maybe this module has code that is different. My form field is set up like this $form['email_recipients'] = array( '#type' => 'textarea', '#title' => t('Send Fax To'), '#default_value' => $node->email_recipients, '#cols' => 60, '#rows' => 3, '#description' => t('IMPORTANT: Enter the fax number with area code followed by @name.com. Do NOT use a 1 before the area code and do NOT use hyphens. Separate multiple fax destinations with a comma.'), '#required' => TRUE, ); I do not see any POST anywhere and i could be wrong but it looks like this is the line that has to do with db insert * Implementation of hook_insert(). */ function citizenfax_insert($node) { db_query("INSERT INTO {citizenfax_campaigns} (nid, email_message, email_recipients, campaign_format) VALUES (%d, '%s', '%s', %d)", $node->nid, $node->email_message, $node->email_recipients, $node->campaign_format);
  5. Yes that helps. I will dig into it tonight. i remember the format for the field is more like this $form['town_name'] = array( '#type' => 'textarea', '#title' => t(Town Name), '#cols' => 50, '#rows' => 15, '#required' => TRUE, '#weight' => 4, '#default_value' => isset($node->town_name) ? $node->town_name : '', );</ I remember seeing both the POST commands and the $sql commands. Will get into it tonight....thanks for the lead.
  6. Thanks for the response. Excuse my ignorance. So if the column in the db table is currently townname and the field on the form is currently townname I should change my form entry field to something like town_name....and then use the code you gave?? Where would i insert this code. In the actually form....or in the processing section?? Wish i had the code all in front of me....but i am slackign at my real job and the stuff is at home.
  7. I would really appreciate some pointing in the right direction on this. I have a php based form with a field that is a textfield. Lets call is [town_name]. I am trying to figure out how i can amend whatever the user enters in this field prior to the value being saved in the db table. For instance i would like to add the suffix of "Town" to every entry. So if the user enters Jonesville....i would like the value of Jonesville Town to be inserted into the database. I am using drupal if that makes any difference.
  8. thanks for the quick response. sorry for my ignorance. how would i build this into my form?
  9. very new to php and i am not sure if this can even be done. i would like to add a "default" value to the end of any value that a user enters into my form The field is formated as this: $form['email_recipients'] = array( '#type' => 'textarea', '#title' => t('Send Message To'), '#default_value' => $node->email_recipients, '#cols' => 60, '#rows' => 6, '#description' => t('Use a comma or space to separate addresses. Make sure the above email addresses are valid to avoid campaign suspension.'), '#required' => TRUE, ); i would like for the user to enter for example just their username, and then have it automatically add @sitename.com to the value they enter once it is processed. Is this possible? If so, how in the world do i do it!?!? many thanks
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.