It's pretty stright forward, im trying to display the results of my form, Im having trouble finding something that explains how to display the results outside of the drupal_set_message()
code, I think I am close with my current code.However I am getting this error Fatal error: Cannot use string offset as an array
/**
* Block info
*/
function zillow_block_info(){
$blocks['zillow_block'] = array(
'info' => t('Zillow Block'),
);
return $blocks;
}
function zillow_block_view($delta = ''){
$block = array();
switch ($delta){
case 'zillow_block';
$block['subject'] = t('Zillow Block');
$block['content'] = drupal_get_form('zillow_form');
break;
}
return $block;
}
/**
* Api info
*/
function zillow_api_info($form, &$zinfo){
set_time_limit(3600);
$state = $zinfo['values']['state'];
$zillow_id = 'XXXXXXXXXXX';
$xml = file_get_contents('http://www.zillow.com/webservice/GetRateSummary.htm?zws-id='.$zillow_id.'&state='.$state.'');
$zinfo = simplexml_load_string($xml);
foreach($zinfo->response as $rates){
$zinfo .= $rates->today->rate[0];
$zinfo .= $rates->today->rate[1];
$zinfo .= $rates->today->rate[2];
$zinfo .= $rates->lastWeek->rate[0];
$zinfo .= $rates->lastWeek->rate[1];
$zinfo .= $rates->lastWeek->rate[2];
}
return $zinfo;
}
/**
* Form
*/
function zillow_form($form, &$zinfo){
$form['description'] = array(
'#type' => 'item',
'#title' => t('Get your mortgage rates'),
);
$form['rates'] = array(
'#type' => 'fieldset',
'#title' => t('Mortgage Rates'),
'#collapsiable' => TRUE,
'#collapsed' => FALSE,
);
$form['rates']['state'] = array(
'#type' => ('select'),
'#title' => t('Choose One'),
'#options' => array(
'AK' => t('Alaska'),
'AZ' => t('Arizona'),
),
'#required' => TRUE
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Submit'),
);
if(isset($zinfo['values'])){
$form['page_output'] = array(
'markup' => 'Submitted value:'. $zinfo['values']['state']);
}
return $form;
}
/**
* Submission Output
*/
function zillow_form_submit($form, &$zinfo){
drupal_set_message(t('this is the info the form has submitted. states=@states, todaysrates=@todaysrates', array('@states' => $zinfo['values']['state'], '@todaysrates' => zillow_api_info($form, $zinfo))));
$zinfo['processed']['states'] = serialize($zinfo['values']['state']);
$zinfo['processed']['todaysrates'] = serialize(zillow_api_info($form, $zinfo));
}
Edit** My code has been modified I am now only getting this error
$zinfo
should be$form_state
, you api function takes$form
but doesn't use it. The error you get is due to an form array containing values that aren't allowed, but nothing looks wrong. (All non#attributes
should be arrays). – googletorp♦ Mar 21 '12 at 9:12