By hexa on
Hi,
I use form api to generate a form, capture output from post variables and then output this variable true theme() function. But if i output it thru theme() it doesn't get displayed while if i do simple echo it does. Why does theme() noy display the contents of this ($_POST['edit']['urly']) variable?
Here is the code i use for capturing and displaying variable:
1. This one doesn't display/echo contents of $_POST['edit']['urly']
$urly=$_POST['edit']['urly'];
$output .= 'XX'. $urly . 'XX';
print theme('page',$output);
2. This one DOES display/echo contents of $_POST['edit']['urly'] (but it's not themable outout)
$urly=$_POST['edit']['urly'];
echo $urly;
Can any1 tell me how to display contents of $_POST['edit']['urly'] thru theme function?
Comments
Your question is missing some context
Is this a custom node type (using form, submit, insert, update hooks) or a custom form?
From which function are you trying to do the print theme('page', $output)? This does make a difference as it will no do what you expect if is in the submit function for a custom form.
If you are just trying to make sure things are set properly you could use drupal_set_message($output);
tnx
I wanted to keep it as short as possible ;-)
i don't really fully understand what are you asking for so i'll try to write just necessary info.
I'm writing a module and making drupal aware of it like this:
Then i generate menu items like this:
Now i'm trying to implement settings function (method?) import_news_my_settings() like this:
'; //debug line
//echo $_POST['edit']['urly']; //debug line
$urly=$_POST['edit']['urly'];
//echo $urly; //debug line
$output .= 'XX'. $urly . 'XX'; //debug line
variable_set('importNewsURLyahoo',$_POST['edit']['urly']);
$output .= variable_get('importNewsURLyahoo','Variable never been set before.');
$output .= '
';
//form for variable setting.
//'action' => $_SERVER['REQUEST_URI'],
$output .= 'You can change setting here.
';
$forma[urly] = array(
'#type' => 'textfield',
'#title' => t('Enter Yahoo news URL'),
'#default_value' => 'http://www.yahoo.org/',
'#maxlenght' => '333',
);
$forma['submit'] = array('#type' => 'submit', '#value' => t('Save new settings.'));
//let's add this form to output
$output .= drupal_get_form('my_form', $forma);
//print out the page
print theme('page',$output);
}//function import_news_my_settings
This method should display site for settings, as well as be able to set those settings. I'm trying to be consistent with drupal module development requirements so i'm using form api and theme function.
I've also taken a look at drupal_set_message in api.dru..org and besides noticing that it's evil ;-) (located in includes/bootstrap.inc, line 666) :-) don't understand how it can help me.
i hope this additional information is enough for someone to tell me why theme() function doesn't want to display my POST captured variables :-(
Tnx for help.
Here is a version that works
When you submit your form, the code gets called twice (I suspect this has do to with the way the form API works), so you need to make sure the post variable is set before saving. You could also use the my_form_submit($form_id, $form_values) function to save the value. [Side note on form_id, it really should start with your module name to avoid a name clash].
Also a minor point in 4.7 it is probably better to do a
return $outputthanprint theme('page', $output).The following version of your function gets the current value by calling variable_get (which is also used to get the default value). In addition it checks to make sure the value is set before saving it.
Tnx
Thank you once more.
I'll try and implement your code.