drupal email problem - drupal

Below is my contactus module,
am trying to send email, guess email not sending successfully,
is there any mistake in my snippet
<?php
function contactus_menu() {
$items['contactus/reachus'] = array(
'title' => 'Contact US',
'page callback' => 'contactus_description',
'access callback' => TRUE,
'expanded' => TRUE,
);
return $items;
}
function contactus_description(){
return drupal_get_form('contactus_form');
}
function contactus_form() {
$form['#attributes']['enctype'] = 'multipart/form-data';
$form['fullname'] = array(
'#type' => 'textfield',
'#title' => t('Enter your full name'),
'#description' => t('Please enter your name here'),
'#required' => TRUE,
);
$form['emailid'] = array(
'#type' => 'textfield',
'#title' => t('Enter your Email-ID'),
'#description' => t('Please enter your Email-ID'),
'#required' => TRUE,
);
$form['message'] = array(
'#type' => 'textarea',
'#title' => t('Enter your message'),
'#default_value' => variable_get('Please enter your message', ''),
'#cols' => 60,
'#rows' => 5,
'#description' => t('Please write your mssage'),
);
$form['file_upload'] = array(
'#title' => t('Upload file'),
'#required' => TRUE,
'#type' => 'file',
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Reach Me '),
);
return $form;
}
function contactus_form_submit($form_id, $form_values) {
$message = 'You have submitted the ' . $form_id . ' form which contains the following data:<pre>' . print_r($form_values,true) . '</pre>';
$fullname = $form_values['values']['fullname'];
$emailid = $form_values['values']['emailid'];
$email_flag = valid_email_address($emailid);
$message = $form_values['values']['message'];
$message = $fullname . "\n" .$emailid. "\n" .$message;
$validators = array();
$dest = 'file';
$file = file_save_upload('file_upload', $validators, $dest);
//$file will be 0 if the upload doesn't exist, or the $dest directory
//isn't writable
if ($file != 0) {
$dest_path = 'contactus';
$result = file_copy($file, $dest_path, FILE_EXISTS_RENAME);
if ($result == 1) {
//Success, $file object will contain a different (renamed)
//filename and filepath if the destination existed
$file_msg = "successfully uploaded\n";
}
else {
//Failure
$file_msg = "failed uploaded\n";
}
}
else {
form_set_error('myform', t("Failed to save the file."));
}
$message = $fullname."\n".$emailid." ---$email_flag ----\n".$message."\n".$file_msg;
$to = 'bharanikumariyerphp#gmail.com';
$from = 'bharanikumariyerphp#gmail.com';
$subject = st('New Drupal site created!');
drupal_mail('university-profile', $to, $subject, $message, $from);
}
?>

You're calling drupal_mail with the wrong parameters. The correct way to send mail in Drupal requires you to implement the hook_mail hook where, based on a key and some parameters sent by drupal_mail you return the title and the subject of the email.
Take a look here for a simple example: http://api.lullabot.com/drupal_mail
If, however, you want to skip drupal_mail you can use this:
<?php
$message = array(
'to' => 'example#mailinator.com',
'subject' => t('Example subject'),
'body' => t('Example body'),
'headers' => array('From' => 'example#mailinator.com'),
);
drupal_mail_send($message);
Make sure you pass all text through t() since drupal_mail_send doesn't take care of localisation.

Related

Drupal Form autocomplete

I wanted to have a textfield in a form that autocompletes from the database. I have been reading the tutorials and trying to get it to work but thus far not much luck. I am farely new to Drupal so I'm mostly unsure what I am doing xD
My code thus far:
function my_module_menu() {
$items = array();
$items['my_module/form'] = array(
'title' => t('Add List'),
'page callback' => 'my_module_form',
'access arguments' => array('access content'),
'description' => t('My form'),
'type' => MENU_CALLBACK,
);
// path with autocomplete function for casters
$items['caster/autocomplete'] = array(
'title' => t('Autocomplete for casters'),
'page callback' => '_caster_autocomplete',
'access arguments' => array('use autocomplete'),
'type' => MENU_CALLBACK
);
return $items;
}
function my_module_form() {
return drupal_get_form('my_module_my_form');
}
function _caster_autocomplete($string) {
$matches = array();
$results = db_select('warnoun', 'w')
->fields('w', array('full_name'))
->condition('full_name', '%' . db_like($string) . '%', 'LIKE')
->execute();
// save the query to matches
foreach ($results as $result) {
$matches[$result->full_name] = check_plain($result->full_name);
}
// Return the result to the form in json
drupal_json_output($matches);
}
function my_module_my_form($form_state) {
$form['points'] = array(
'#type' => 'select',
'#title' => t('Points'),
'#required' => TRUE, // Added
'#options' => array(
0 => t('15'),
1 => t('25'),
2 => t('35'),
3 => t('50'),
),
);
$form['caster'] = array(
'#type' => 'textfield',
'#title' => t('Caster'),
'#maxlength' => 50,
'#autocomplete_path' => 'caster/autocomplete',
'#required' => TRUE,
);
$entries = db_query('SELECT id, short_name FROM factions ORDER BY id ASC');
$options = array();
foreach ($entries as $entry){
$options[$entry->id] = t($entry->short_name);
}
$form['faction'] = array(
'#type' => 'select',
'#title' => t('Faction'),
'#options' => $options,
);
// Simple Submit Button
$form['submit'] = array(
'#type' => 'submit',
'#value' => 'Submit',
'#required' => TRUE, // Added
);
return $form;
}
So basically there is a table called warnoun with a column full_name and it's with that content that I want to autocomplete the textfield caster.
Any idea what I'm missing/doing wrong?
Cheers

Drupal 6 create CRUD grid in settings form

I'm quite new to Drupal and I want to create a custom grid that has some editable columns, some other columns witch checkboxes etc.
I'm using the theme() function to create the table and render it at the settings. Since I cannot find any way to access the form/settings variables, inside the theme function, I create a custom table at the drupal database that will contain the gid values, and I render those rows. For testing purposes I fetch the 'variables' table rows. Here is the code so far:
$form['module_settings']['profile_grid'] = array(
'#type' => 'item',
'#title' => t('Profile Mapping'),
'#theme' => 'profile_mapping_grid'
);
function theme_profile_mapping_grid($sender) {
$header = array('', t('name'), t('value'));
$result = db_query('SELECT v.name, v.value from {variable} v');
while ($pair = db_fetch_object($result)) {
$format = array(
'#type' => 'textfield',
'#size' => 30,
'#value' => $pair->name
);
$hhfield = array(
'#type' => 'textfield',
'#size' => 30,
'#value' => $pair->value
);
$row = array('');
$row[] = drupal_render($format);
$row[] = drupal_render($hhfield);
$rows[] = array('data' => $row);
}
$output = theme('table', $header, $rows, array('id' => 'gridErrors'));
return $output;
}
The grid is generated correctly, but I have an issue. I cannot set the 'name' attribute to the textfield, in order to collect it's value later on, on a submit action.
Furthermore, I'm not sure if this is the best way to create a settings grid.
Any ideas, opinions etc are more than welcome.
According to Drupal 6 Form API Quickstart Guide:
Don't use the '#value' attribute for any form element that can be changed by the user. Use the '#default_value' attribute instead. Don't put values from $form_state['values'] (or $_POST) here! FormsAPI will deal with that for you; only put the original value of the field here.
You have to use '#default_value' => $pair->name not '#value' => $pair->value.
Here is the sample module with settings table.
install file:
<?php
// $Id$
/**
* #file
* The your_module module install file, which handles the install/uninstall tasks.
*
*/
function your_module_install() {
// Create tables.
drupal_install_schema('your_module');
}
/**
* Implementation of hook_schema().
*/
function your_module_schema() {
/* Settings table */
$schema['your_module_settings'] = array(
'description' => 'Stores module settings.',
'fields' => array(
'record_id' => array(
'description' => 'The primary identifier for a record.',
'type' => 'serial',
'unsigned' => TRUE,
'not null' => TRUE),
'item_code' => array(
'type' => 'varchar',
'length' => '255',
'not null' => TRUE),
'setting_one' => array(
'type' => 'varchar',
'length' => '255',
'not null' => TRUE),
'setting_two' => array(
'type' => 'varchar',
'length' => '255')),
'unique keys' => array(
'record_id' => array('record_id')),
'primary key' => array('record_id')
);
return $schema;
}
/**
* Implementation of hook_uninstall().
*/
function your_module_uninstall() {
// Remove tables.
drupal_uninstall_schema('your_module');
}
module file:
<?php
/**
* Implementation of hook_help()
*/
function your_module_help($path, $arg)
{
switch ($path)
{
case 'admin/help#your_module':
return '<p>'. t('Module description.') .'</p>';
}
}
/**
* Implementation of hook_menu()
*/
function your_module_menu()
{
$items = array();
/* module settings page */
$items['admin/settings/your_module'] = array(
'description' => 'Administer your_module module settings.',
'title' => 'Some title',
'page callback' => 'drupal_get_form',
'page arguments' => array('your_module_admin_settings'),
'access arguments' => array('access administration pages'),
'type' => MENU_NORMAL_ITEM,
);
return $items;
}
/**
* Implementation of hook_theme().
*/
function your_module_theme() {
return array(
'your_module_products_settings' => array(
'arguments' => array('form' => NULL),
),
);
}
/**
* Settings form
*/
function your_module_admin_settings(&$form_state)
{
$form['your_module'] = array(
'#type' => 'fieldset',
'#title' => t('Settings'),
'#description' => t('Settings description.'),
);
$form['your_module']['products_settings_table'] = array(
'#theme' => 'your_module_products_settings',
'#tree' => TRUE,
);
$form['your_module']['products_settings_table']['products_settings'] = array();
$result = db_query('SELECT record_id, item_code, setting_one, setting_two FROM {your_module_settings} ORDER BY item_code');
while ($product_setting = db_fetch_object($result)) {
$form['your_module']['products_settings_table']['products_settings'][$product_setting->record_id] = array();
$form['your_module']['products_settings_table']['products_settings'][$product_setting->record_id]['item_code'] = array(
'#type' => 'textfield',
'#default_value' => $product_setting->item_code,
'#size' => 8,
'#maxlength' => 16,
);
$form['your_module']['products_settings_table']['products_settings'][$product_setting->record_id]['setting_one'] = array(
'#type' => 'textfield',
'#default_value' => $product_setting->setting_one,
'#size' => 16,
'#maxlength' => 16,
);
$form['your_module']['products_settings_table']['products_settings'][$product_setting->record_id]['setting_two'] = array(
'#type' => 'textfield',
'#default_value' => $product_setting->setting_two,
'#size' => 40,
'#maxlength' => 255,
);
}
/* "add new row" fields */
$form['your_module']['products_settings_table']['products_settings_new'] = array();
/* new item_code */
$form['your_module']['products_settings_table']['products_settings_new']['item_code'] = array(
'#type' => 'textfield',
'#size' => 8,
'#maxlength' => 16,
'#description' => t('description'),
);
/* new setting_one */
$form['your_module']['products_settings_table']['products_settings_new']['setting_one'] = array(
'#type' => 'textfield',
'#size' => 16,
'#maxlength' => 16,
'#description' => t('description'),
);
/* setting_two */
$form['your_module']['products_settings_table']['products_settings_new']['setting_two'] = array(
'#type' => 'textfield',
'#size' => 40,
'#maxlength' => 255,
'#description' => t('description'),
);
/* Submit button */
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Save Settings'),
'#name' => 'SubmitButton',
);
return $form;
}
/**
* Custom theme function for a table of products settings
*/
function theme_your_module_products_settings($form) {
$header = array(t('Item Code'), t('Setting One'), t('Setting Two'));
$rows = array();
/* saved rows */
foreach (element_children($form['products_settings']) as $key) {
$row = array();
$row[] = drupal_render($form['products_settings'][$key]['item_code']);
$row[] = drupal_render($form['products_settings'][$key]['setting_one']);
$row[] = drupal_render($form['products_settings'][$key]['setting_two']);
$rows[] = $row;
}
/* new row to add */
$row = array();
$row[] = drupal_render($form['products_settings_new']['item_code']);
$row[] = drupal_render($form['products_settings_new']['setting_one']);
$row[] = drupal_render($form['products_settings_new']['setting_two']);
$rows[] = $row;
$output = theme('table', $header, $rows);
return $output;
}
/**
* Submission function for your_module_admin_settings form.
*/
function your_module_admin_settings_submit($form, &$form_state) {
/* processing changes */
if (isset($form_state['values']['products_settings_table']['products_settings'])) {
foreach ($form_state['values']['products_settings_table']['products_settings'] as $record_id => $data) {
if (empty($data['item_code']) && empty($data['setting_one']) && empty($data['setting_two'])) {
/* delete saved row if all fields are empty */
db_query("DELETE FROM {your_module_settings} WHERE record_id=%d", $record_id);
drupal_set_message(t('Deleted.'), 'status');
}
else {
/* update */
db_query("UPDATE {your_module_settings} SET item_code='%s', setting_one='%s', setting_two='%s' WHERE record_id=%d",
$data['item_code'], $data['setting_one'], $data['setting_two'], $record_id);
}
}
}
/* adding new row */
$item_code = $form_state['values']['products_settings_table']['products_settings_new']['item_code'];
$setting_one = $form_state['values']['products_settings_table']['products_settings_new']['setting_one'];
$setting_two = $form_state['values']['products_settings_table']['products_settings_new']['setting_two'];
if (!empty($item_code) && !empty($setting_one) && !empty($setting_two)) {
db_query("INSERT INTO {your_module_settings} (item_code, setting_one, setting_two) VALUES ('%s', '%s', '%s')",
$item_code, $setting_one, $setting_two);
drupal_set_message(t('Added new setting.'), 'status');
}
drupal_set_message(t('Settings updated.'), 'status');
}
You're generating the fields in the theme function and it will not work because the submit function will only act on the fields generated by your form function.
The correct way is to generate all fields in the form function (basically what you're doing now in the theme function) and render them in the theme using drupal_render.
Since I cannot find any way to access the form/settings variables, inside the theme function
The form is passed to the theme function as an argument, in your case $sender, and that's how you access them.
Here's some code, untested, but you get the idea. Remember that the call $output .= drupal_render($form); is very important because it renders the hidden fields needed by the Form API such as the form_id and the CSRF protection. Without this call submit won't work.
function mymodule_grid_form($form_state) {
$form = array();
$form['variables'] = array();
$result = db_query('SELECT v.name, v.value from {variable} v');
while ($pair = db_fetch_object($result)) {
$form['variables'][$pair->name][$pair->name . '_name'] = array(
'#type' => 'textfield',
'#size' => 30,
'#value' => $pair->name
);
$form['variables'][$pair->name][$pair->name . '_value'] = array(
'#type' => 'textfield',
'#size' => 30,
'#value' => $pair->value
);
}
return $form;
}
function theme_mymodule_grid_form($form) {
$header = array('', t('name'), t('value'));
foreach ($form['variables'] as $variable => $values) {
$row = array('');
$row[] = drupal_render($values[$variable . '_name']);
$row[] = drupal_render($values[$variable . '_value']);
$rows[] = array('data' => $row);
}
$output = theme('table', $header, $rows, array('id' => 'gridErrors'));
$output .= drupal_render($form);
return $output;
}
function mymodule_theme() {
return array(
'mymodule_grid_form' => array(
'arguments' => array('form' => NULL),
),
);
}

how to load database content to dropdown options (select)

i'm still working on my own drupal 7 module, and i'm having some trouble. I'm trying to load database content to dropdown option (select), i have read and write the same code from drupal example, but my database still not loading, only empty option.
what i'm asking is there anything wrong on my code or is there any faster way to load database to dropdown option other than the drupal example???
here the code i'm working on
function prod_entry_load($entry = array()) {
$select = db_select('aa_1122','aa');
$select->fields('aa');
foreach ($entry as $field => $value) {
$select->condition($field, $value);
}
return $select->execute()->fetchAll();
}
function prod(){
return drupal_get_form('prod_form');
}
function prod_form($form_state){
$form = array(
'#prefix' => '<div id="updateform">',
'#suffix' => '</div>',
);
$entries = prod_entry_load();
$keyed_entries = array();
if (empty($entries)) {
$form['no_values'] = array(
'#value' => t("No entries exist in the table dbtng_example table."),
);
return $form;
}
foreach ($entries as $entry) {
$options[$entry->no] = t("#no: #name ", array('#no' => $entry->no, '#name' => $entry->name));
$keyed_entries[$entry->no] = $entry;
}
$default_entry = !empty($form_state['values']['no']) ? $keyed_entries[$form_state['values']['no']] : $entries[0];
$form_state['entries'] = $keyed_entries;
$form['no'] = array(
'#type' => 'select',
'#title' => t('Choose'),
'#default_value' => $default_entry->no,
'#ajax' => array(
'wrapper' => 'updateform',
'callback' => 'prod_form_update_callback',
),
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => 'Submit',
'#ajax' => array(
'callback' => 'ajax_alert',
),
);
return $form;
}
function prod_form_update_callback($form, $form_state) {
$entry = $form_state['entries'][$form_state['values']['no']];
foreach (array('name') as $item) {
$form[$item]['#value'] = $entry->$item;
}
return $form;
}
You've just forgotten to add the #options key to your select element, the code should read like this:
$form['no'] = array(
'#type' => 'select',
'#title' => t('Choose'),
'#default_value' => $default_entry->no,
'#options' => $options, // This is the bit that was missing
'#ajax' => array(
'wrapper' => 'updateform',
'callback' => 'prod_form_update_callback',
),
);
You could shorten your query/options code slightly using a combination of string concatenation in MySQL and the db fetchAllKeyed() method:
$query = db_select('aa_1122', 'aa')->fields('aa', array('no'));
$query->addExpression("CONCAT(no, ': ', name)", 'display');
$options = $query->execute()->fetchAllKeyed();

Drupal module function theming with ahah

My main question is:
Does the theme_hook() function gets called whenever the form gets rebuilt via ahah (ahah_helper) ?
I'm trying to show a select box, with some filtering options, when the user changes it, the table below it changes too.
I have this by now:
function veiculos_listar_form($form_state)
{
$form = array();
ahah_helper_register($form, $form_state);
//biulds $options
$form['listar_veics'] = array(
'#type' => 'fieldset',
'#prefix' => '<div id="listar-veics-wrapper">',
'#suffix' => '</div>',
'#tree' => TRUE,
);
if (!isset($form_state['values']['listar_veics']['filial']))
$form['#filial_veic'] = 1;
else
$form['#filial_veic'] = $form_state['values']['listar_veics']['filial'];
$form['listar_veics']['filial'] = array(
'#type' => 'select',
'#title' => "Listar veículos da filial",
'#options' => $filiais,
'#default_value' => $form['#filial_veic'],
'#ahah' => array(
'event' => 'change',
'path' => ahah_helper_path(array('listar_veics')),
'wrapper' => 'listar-veics-wrapper',
'method' => 'replace',
),
);
return $form;
}
function veiculos_listar_form_submit($form, &$form_state)
{
}
function _listar_veiculos_tabela($filial)
{
//builds $header and $data
$table = theme_table($header, $data);
return $table;
}
function theme_veiculos_listar_form($form)
{
$output = drupal_render($form);
$filial = $form['#filial_veic'];
$output .= '<br>' . $filial . '<br>';
$output .= _listar_veiculos_tabela($filial);
return $output;
}
function veiculos_theme() {
return array(
'veiculos_listar_form' => array(
'arguments' => array('form' => NULL),),
);
}
In my little and innocent world, it should work if theme_hook is called on every ahah event (change).
The problem is, the variable printed is always the same, like what the user is choosing isn't being stored. If the user select a different options, it shows the new option, but the $filial variable is always the same when the theme prints.
Like this:
http://img230.imageshack.us/img230/9646/62144334.jpg
Any suggestion on what i could do to make this work? I'm developing our own module, so using views module isn't a good idea.
Thanks.
You should redo code this way.
Ahah callback I do not wrote, I think you would not have problem with it.
Check some examples on drupal.org
function veiculos_listar_form($form_state)
{
$form = array();
ahah_helper_register($form, $form_state);
//biulds $options
// remove divs because we do not want to reload selector with ahah
$form['listar_veics'] = array(
'#type' => 'fieldset',
'#tree' => TRUE,
);
if (!isset($form_state['values']['listar_veics']['filial']))
$form['#filial_veic'] = 1;
else
$form['#filial_veic'] = $form_state['values']['listar_veics']['filial'];
// add cover div here, because we will reload table
$form['table'] = array(
'#prefix' => '<div id="listar-veics-wrapper">',
'#suffix' => '</div>',
'#type' => 'markup',
'#value' => _listar_veiculos_tabela($form['#filial_veic']),
);
$form['listar_veics']['filial'] = array(
'#type' => 'select',
'#title' => "Listar veículos da filial",
'#options' => $filiais,
'#default_value' => $form['#filial_veic'],
'#ahah' => array(
'event' => 'change',
'path' => ahah_helper_path(array('listar_veics')),
'wrapper' => 'listar-veics-wrapper',
'method' => 'replace',
),
);
return $form;
}
function veiculos_listar_form_submit($form, &$form_state)
{
}
function _listar_veiculos_tabela($filial)
{
//builds $header and $data
$table = theme_table($header, $data);
return $table;
}
function theme_veiculos_listar_form($form)
{
$output = drupal_render($form);
return $output;
}
function veiculos_theme() {
return array(
'veiculos_listar_form' => array(
'arguments' => array('form' => NULL),),
);
}

Drupal Ctools Form Wizard in a Block

I created a custom module that has a Ctools multi step form. It's basically a copy of http://www.nicklewis.org/using-chaos-tools-form-wizard-build-multistep-forms-drupal-6.
The form works. I can see it if I got to the url i made for it.
For the life of me I can't get the multistep form to show up in a block.
Any clues?
/**
* Implementation of hook_block()
* */
function mycrazymodule_block($op='list', $delta=0, $edit=array()) {
switch ($op) {
case 'list':
$blocks[0]['info'] = t('SFT Getting Started');
$blocks[1]['info'] = t('SFT Contact US');
$blocks[2]['info'] = t('SFT News Letter');
return $blocks;
case 'view':
switch ($delta){
case '0':
$block['subject'] = t('SFT Getting Started Subject');
$block['content'] = mycrazymodule_wizard();
break;
case '1':
$block['subject'] = t('SFT Contact US Subject');
$block['content'] = t('SFT Contact US content');
break;
case '2':
$block['subject'] = t('SFT News Letter Subject');
$block['content'] = t('SFT News Letter cONTENT');
break;
}
return $block;
}
}
/**
* Implementation of hook_menu().
*/
function mycrazymodule_menu() {
$items['hellocowboy'] = array(
'title' => 'Two Step Form',
'page callback' => 'mycrazymodule_wizard',
'access arguments' => array('access content')
);
return $items;
}
/**
* menu callback for the multistep form
* step is whatever arg one is -- and will refer to the keys listed in
* $form_info['order'], and $form_info['forms'] arrays
*/
function mycrazymodule_wizard() {
$step = arg(1);
// required includes for wizard
$form_state = array();
ctools_include('wizard');
ctools_include('object-cache');
// The array that will hold the two forms and their options
$form_info = array(
'id' => 'getting_started',
'path' => "hellocowboy/%step",
'show trail' => FALSE,
'show back' => FALSE,
'show cancel' => false,
'show return' =>false,
'next text' => 'Submit',
'next callback' => 'getting_started_add_subtask_next',
'finish callback' => 'getting_started_add_subtask_finish',
'return callback' => 'getting_started_add_subtask_finish',
'order' => array(
'basic' => t('Step 1: Basic Info'),
'lecture' => t('Step 2: Choose Lecture'),
),
'forms' => array(
'basic' => array(
'form id' => 'basic_info_form'
),
'lecture' => array(
'form id' => 'choose_lecture_form'
),
),
);
$form_state = array(
'cache name' => NULL,
);
// no matter the step, you will load your values from the callback page
$getstart = getting_started_get_page_cache(NULL);
if (!$getstart) {
// set form to first step -- we have no data
$step = current(array_keys($form_info['order']));
$getstart = new stdClass();
//create cache
ctools_object_cache_set('getting_started', $form_state['cache name'], $getstart);
//print_r($getstart);
}
//THIS IS WHERE WILL STORE ALL FORM DATA
$form_state['getting_started_obj'] = $getstart;
// and this is the witchcraft that makes it work
$output = ctools_wizard_multistep_form($form_info, $step, $form_state);
return $output;
}
function basic_info_form(&$form, &$form_state){
$getstart = &$form_state['getting_started_obj'];
$form['firstname'] = array(
'#weight' => '0',
'#type' => 'textfield',
'#title' => t('firstname'),
'#size' => 60,
'#maxlength' => 255,
'#required' => TRUE,
);
$form['lastname'] = array(
'#weight' => '1',
'#type' => 'textfield',
'#title' => t('lastname'),
'#required' => TRUE,
'#size' => 60,
'#maxlength' => 255,
);
$form['phone'] = array(
'#weight' => '2',
'#type' => 'textfield',
'#title' => t('phone'),
'#required' => TRUE,
'#size' => 60,
'#maxlength' => 255,
);
$form['email'] = array(
'#weight' => '3',
'#type' => 'textfield',
'#title' => t('email'),
'#required' => TRUE,
'#size' => 60,
'#maxlength' => 255,
);
$form['newsletter'] = array(
'#weight' => '4',
'#type' => 'checkbox',
'#title' => t('I would like to receive the newsletter'),
'#required' => TRUE,
'#return_value' => 1,
'#default_value' => 1,
);
$form_state['no buttons'] = TRUE;
}
function basic_info_form_validate(&$form, &$form_state){
$email = $form_state['values']['email'];
$phone = $form_state['values']['phone'];
if(valid_email_address($email) != TRUE){
form_set_error('Dude you have an error', t('Where is your email?'));
}
//if (strlen($phone) > 0 && !ereg('^[0-9]{1,3}-[0-9]{3}-[0-9]{3,4}-[0-9]{3,4}$',
$phone)) {
//form_set_error('Dude the phone', t('Phone number must be in format xxx-xxx-
nnnn-nnnn.'));
//}
}
function basic_info_form_submit(&$form, &$form_state){
//Grab the variables
$firstname =check_plain ($form_state['values']['firstname']);
$lastname = check_plain ($form_state['values']['lastname']);
$email = check_plain ($form_state['values']['email']);
$phone = check_plain ($form_state['values']['phone']);
$newsletter = $form_state['values']['newsletter'];
//Send the form and Grab the lead id
$leadid = send_first_form($lastname, $firstname, $email,$phone, $newsletter);
//Put into form
$form_state['getting_started_obj']->firstname = $firstname;
$form_state['getting_started_obj']->lastname = $lastname;
$form_state['getting_started_obj']->email = $email;
$form_state['getting_started_obj']->phone = $phone;
$form_state['getting_started_obj']->newsletter = $newsletter;
$form_state['getting_started_obj']->leadid = $leadid;
}
function choose_lecture_form(&$form, &$form_state){
$one = 'event 1'
$two = 'event 2'
$three = 'event 3'
$getstart = &$form_state['getting_started_obj'];
$form['lecture'] = array(
'#weight' => '5',
'#default_value' => 'two',
'#options' => array(
'one' => $one,
'two' => $two,
'three' => $three,
),
'#type' => 'radios',
'#title' => t('Select Workshop'),
'#required' => TRUE,
);
$form['attendees'] = array(
'#weight' => '6',
'#default_value' => 'one',
'#options' => array(
'one' => t('I will be arriving alone'),
'two' =>t('I will be arriving with a guest'),
),
'#type' => 'radios',
'#title' => t('Attendees'),
'#required' => TRUE,
);
$form_state['no buttons'] = TRUE;
}
/**
* Same idea as previous steps submit
*
*/
function choose_lecture_form_submit(&$form, &$form_state) {
$workshop = $form_state['values']['lecture'];
$leadid = $form_state['getting_started_obj']->leadid;
$attendees = $form_state['values']['attendees'];
$form_state['getting_started_obj']->lecture = $workshop;
$form_state['getting_started_obj']->attendees = $attendees;
send_second_form($workshop, $attendees, $leadid);
}
//----PART 3 CTOOLS CALLBACKS -- these usually don't have to be very unique
/**
* Callback generated when the add page process is finished.
* this is where you'd normally save.
*/
function getting_started_add_subtask_finish(&$form_state) {
dpm($form_state);
$getstart = &$form_state['getting_started_obj'];
drupal_set_message('mycrazymodule '.$getstart->name.' successfully deployed' );
//Get id
// Clear the cache
ctools_object_cache_clear('getting_started', $form_state['cache name']);
$form_state['redirect'] = 'hellocowboy';
}
/**
* Callback for the proceed step
*
*/
function getting_started_add_subtask_next(&$form_state) {
dpm($form_state);
$getstart = &$form_state['getting_started_obj'];
$cache = ctools_object_cache_set('getting_started', $form_state['cache name'],
$getstart);
}
//PART 4 CTOOLS FORM STORAGE HANDLERS -- these usually don't have to be very unique
/**
* Remove an item from the object cache.
*/
function getting_started_clear_page_cache($name) {
ctools_object_cache_clear('getting_started', $name);
}
/**
* Get the cached changes to a given task handler.
*/
function getting_started_get_page_cache($name) {
$cache = ctools_object_cache_get('getting_started', $name);
return $cache;
}
//Salesforce Functions
function send_first_form($lastname, $firstname,$email,$phone, $newsletter){
$send = array("LastName" => $lastname , "FirstName" => $firstname, "Email" => $email
,"Phone" => $phone , "Newsletter__c" =>$newsletter );
$sf = salesforce_api_connect();
$response = $sf->client->create(array($send), 'Lead');
dpm($response);
return $response->id;
}
function send_second_form($workshop, $attendees, $leadid){
$send = array("Id" => $leadid , "Number_Of_Pepole__c" => "2" );
$sf = salesforce_api_connect();
$response = $sf->client->update(array($send), 'Lead');
dpm($response, 'the final response');
return $response->id;
}
Am assuming you have enabled the block from admin. To do a quick check that the block is indeed getting rendered on the page you are looking at, try returning a test string along with your rendered form, from your block callback.
If that doesn't work, try clearing your cache from admin/settings/performance and try again. If I am not wrong, blocks are cached by default. Let us see if it shows up then.

Resources