Hey guys I have a module that allows someone to request a file on my website and then download it. I have also added cookie code so they don't have to continually enter their information everytime to download a file.

However, I am getting a problem when I go to /file_download/quest on my website

Here is the error:

warning: call_user_func_array() [function.call-user-func-array]: First argument is expected to be a valid callback, 'file_download_quest_testform' was given in C:\Inetpub\wwwroot\includes\form.inc on line 218.

The code is below:

All of the functions seem to be calling the correct arrays, etc.

Any help is appreciated.

Thanks.

<?php

function file_download_help($section) {
switch ($section) {
case 'admin/modules#description':
// This description is shown in the listing at admin/modules.
return t('The file_download module allows B to gather information of clients and sends them the link for the requested document.');
break;
case 'file_download/request/fileid':
$output = '

'.t('The file you have requested will be sent to the e-mail address provided below.');
return $output;
break;

}
}

function file_download_perm() {
return array('file download');
}

function file_download_menu($may_cache) {
$items = array();

$access = user_access('file download');

if ($may_cache) {

$items[] = array('path' => 'file_download/request', 'title' => t('File Download'),
'type' => MENU_CALLBACK, 'callback' => file_download_request, 'access' => $access);

$items[] = array('path' => 'file_download/quest', 'title' => t('File Download'),
'type' => MENU_CALLBACK, 'callback' => file_download_quest, 'access' => $access);

$items[] = array('path' => 'file_download/test', 'title' => t('Thank You'),
'type' => MENU_CALLBACK, 'callback' => file_download_test, 'access' => $access);

$items[] = array('path' => 'file_download/sent', 'title' => t('Thank You'),
'type' => MENU_CALLBACK, 'callback' => file_download_sent, 'access' => $access);

// Error Page
$items[] = array('path' => 'file_download/failed', 'title' => t('Error Processing Request'),
'type' => MENU_CALLBACK, 'callback' => file_download_failed, 'access' => $access);
}

return $items;
}

function file_download_request_form($fileid) {

$myCookie = $_COOKIE["mikeknowsall"];

if (isset($myCookie)) {
$mikeknowsall = explode("|", $myCookie);

$fname = $mikeknowsall[0];
$lname = $mikeknowsall[1];
$email = $mikeknowsall[2];
$phone = $mikeknowsall[3];

file_download_request_form_submit2($fileid, $fname, $lname, $phone, $email);

return;
}

function file_download_quest_testform($fileid) {

$myCookie = $_COOKIE["mikeknowsall"];

$mikeknowsall = explode("|", $myCookie);

$fname = $mikeknowsall[0];
$lname = $mikeknowsall[1];
$email = $mikeknowsall[2];
$phone = $mikeknowsall[3];

file_download_request_form_testsubmit($fileid, $fname, $lname, $phone, $email);

return;
}

$form = array();

$form['information'] = array(
'#value' => variable_get('form_information', t('The file you requested will be sent to the e-mail address provided below. B respects the privacy of visitors to its Web site, and NEVER rents or sells e-mail addresses to outside parties.')),
);

$form['fname'] = array(
'#type' => 'textfield',
'#title' => t('First Name'),
'#size' => 10,
'#maxlength' => 15,
'#required' => TRUE
);

$form['lname'] = array(
'#type' => 'textfield',
'#title' => t('Last Name'),
'#size' => 10,
'#maxlength' => 15,
'#required' => TRUE
);

$form['title'] = array(
'#type' => 'textfield',
'#title' => t('Title'),
'#size' => 4,
'#maxlength' => 15,
'#required' => FALSE
);

$form['companyname'] = array(
'#type' => 'textfield',
'#title' => t('Company Name'),
'#size' => 25,
'#maxlength' => 40,
'#required' => TRUE
);

$form['email'] = array(
'#type' => 'textfield',
'#title' => t('Email Address'),
'#size' => 30,
'#maxlength' => 50,
'#required' => TRUE
);

$form['phone'] = array(
'#type' => 'textfield',
'#title' => t('Phone Number'),
'#size' => 20,
'#maxlength' => 14,
'#required' => TRUE
);

//$form['needs'] = array(
// ('#type' => 'radio',
// '#title' => t('Personal Need'),
// '#size' => 20,
// '#value' => 0,
// '#values' => array( 0 => 'no', 1 => 'yes'),
// '#required' => TRUE),
//('#type' => 'radio',
// '#title' => t('Business Need'),
// '#size' => 20,
// '#maxlength' => 14,
// '#value' => 0,
// '#values' => array( 0 => 'no', 1 => 'yes'),
// '#required' => TRUE)
// );

$form['fileid'] = array(
'#type' => 'hidden',
'#value' => $fileid
);

$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Send Request'));

return $form;
}

function file_download_request($fileid) {

DebugMe($fileid);

$output = t('');
$output .= drupal_get_form('file_download_request_form', $fileid);
return $output;

}

function file_download_quest($fileid) {

DebugMe("REQUEST 2");

$output = t('');
$output .= drupal_get_form('file_download_quest_testform', $fileid);
return $output;

}

function file_download_request_form_submit2($file_id, $fname, $lname, $phone, $email) {

$file = get_file($file_id);
if (strlen($file) > 0){
email_success($fname, $lname, $email, $file, $phone);
drupal_goto('file_download/sent/' . $file_id);
}
else{
email_failed($fname, $lname, $email, $file_id, $phone);
drupal_goto('file_download/failed');
}

}

function file_download_request_form_submit($form_id, $form_values) {
session_start();
$file = get_file($form_values['fileid']);
$_SESSION['file'] = $file;
if (strlen($file) > 0){
email_success($form_values['fname'], $form_values['lname'], $form_values['email'], $file, $form_values['phone']);

$cookieValue = $form_values['fname'];
$cookieValue .= "|";
$cookieValue .= $form_values['lname'];
$cookieValue .= "|";
$cookieValue .= $form_values['email'];
$cookieValue .= "|";
$cookieValue .= $form_values['phone'];

setcookie("mikeknowsall", $cookieValue , time()+86400);

drupal_goto('file_download/sent/' . $form_values['fileid']);
}
else{
email_failed($form_values['fname'], $form_values['lname'], $form_values['email'], $form_values['fileid'], $form_values['phone']);
drupal_goto('file_download/failed');
}

}

function file_download_request_form_testsubmit($file_id, $fname, $lname, $phone, $email) {

$file = get_file($file_id);
if (strlen($file) > 0){
email_success($fname, $lname, $email, $file, $phone);
drupal_goto('file_download/test/' . $file_id);
}
else{
email_failed($fname, $lname, $email, $file_id, $phone);
drupal_goto('file_download/failed');
}

}

function file_download_sent($fileid) {

$myCookie = $_COOKIE["mikeknowsall"];

if (isset($myCookie)) {

$fileurl = "";

$mikeknowsall = explode("|", $myCookie);
$fname = $mikeknowsall[0];
$lname = $mikeknowsall[1];

$output = "Thanks for your interest in B

";
$output .= "If you are ";
$output .= $fname;
$output .= " ";
$output .= $lname;
$output .= " ";
$output .= "please click on the following link to have the document delivered to your mailbox";
$output .= " ";
$output .= $fileurl;
$output .= "send document.";
$output .= " ";
$output .= "otherwise,";
$output .= " ";
$output .= "click here.";

}

else{

$output = '

';
$output .= "Thanks for your interest in SCC. The requested document should be arriving in your mailbox shortly. ";
$output .= "Please let us know if we could be of further assistance.

";
$output .= "B
";
$output .= "Contact";
$output .= '

';

}

return $output;
}

function file_download_failed() {

$output .= '

';
$output .= "There was a problem processing your request. B will contact you for further assistance.
";
$output .= "B
";
$output .= "Contact";
$output .= '

';

return $output;
}

function file_download_test($fileid) {

$output = '

';
$output .= "Thanks for your interest in B. The requested document should be arriving in your mailbox shortly. ";
$output .= "Please let us know if we could be of further assistance.

";
$output .= "B
";
$output .= "Contact";
$output .= '

';

return $output;

}

Comments

hello12345’s picture

PROBLEM SOLVED!!PROBLEM SOLVED!!PROBLEM SOLVED!!PROBLEM SOLVED!!PROBLEM SOLVED!!

shirishab’s picture

we have problem

Cannot use string offset as an array in C:\Inetpub\wwwroot\includes\form.inc on line 973

is comming we have added code in user.module file the code is

function user_sitekey_block()
{

if($_SESSION['mcuid'] == '')
{
$form = array(
'#action' => url($_GET['q'], array('query' => drupal_get_destination())),
'#id' => 'user-sitekey-form',
'access arguments' => array('access administration pages'),
'#submit' => array('user_sitekey_submit'),
);

$form['sitekey'] = array('#type' => 'textfield',
'#title' => t('Enter Sitekey'),
'#maxlength' => USERNAME_MAX_LENGTH,
'#size' => 15,
'#default_value' => $form_state['values']['sitekey'],
'#required' => TRUE,
);

$form['submit'] = array('#type' => 'submit',
'#value' => t('Submit'),

);
return $form;
}
}
function user_sitekey_submit($form, &$form_state)
{
$form_state['storage']['submit'] = TRUE;

if($form_state['values']['sitekey'] != '')
{
$client = new MCWSClient() ;

$param = array( 'loginSessionID' => $_SESSION['lid'],
'siteKey' => $form_state['values']['sitekey']);

$ret = $client->ValidateSiteKey($param) ;
if($ret->ValidateSiteKeyResult)
{
//$_SESSION['lid'] = '-1';
$_SESSION['mcuid']= $ret;

}
else echo 'Failed';
}
}

Is there any mistake in the code

can you please help me to solve the problem its very important

fxtradesman’s picture

How was it solved? I am having the same issue and do not know where to go.

Thanks.

naveenpl’s picture

warning: call_user_func_array() [function.call-user-func-array]: First argument is expected to be a valid callback, 'file_download_quest_testform' was given in C:\Inetpub\wwwroot\includes\form.inc on line 218.

When you don't pass the return output stream through drupal_get_form() function you get this error message
It can be avoided by 2 methods.
first method
'callback' => 'drupal_get_form',
'callback arguments' => array('function_name'),
This way of calling function from hook_menu
eg:
$menu[] = array('path' => 'path',
'title'=>t('title'),
'description' => t('description.'),
'weight' => 2,
'type' => MENU_LOCAL_TASK,
'callback' => 'drupal_get_form',
'callback arguments' => array('function_name'),
'access' => user_access('user'),
);
second method
passing output throught drupal_get_form before returning it.
eg:
$output = drupal_get_form('function_name2');
here hook_menu() is like this.
$menu[] = array('path' => 'path',
'title'=>t('title'),
'description' => t('description.'),
'weight' => 2,
'type' => MENU_LOCAL_TASK,
'callback ' => 'function_name',
'access' => user_access('user'),
);

Hope this will help.
Cheers.