On Thursday, 24. January 2008, Feijó wrote:
If I try '#default_value' => 'test ' . $row['name'],
only test apears!
Imho, that behaviour suggests that something is wrong with $row['name'] and less with Form API itself. (Because string concatenation fails even before the Form API gets the value passed over.) Not sure, but maybe print_r($row) and/or gettype($row['name']) reveals some useful information...
If #value is set, #default_value will be ineffective. From form.inc: if (!isset($form['#value'])) { $function = $form['#type'] . '_value'; if (function_exists($function)) { $function($form); } else { $form['#value'] = isset($form['#default_value']) ? $form['#default_value'] : ''; } } Because the form is built multiple times, this can be confusing.
I already try with print_r !
it shows the content "array(['name'] => 'name test')" in #description and #value, but never on #default_value
The name field is varchar(50), with 'name test'. Just it.
Yesterday a PHP expert was here, he take a look at this, we try a lot of possibilities, no clue whatsoever
It cant be explained :)
Jakob Petsovits escreveu:
On Thursday, 24. January 2008, Feijó wrote:
If I try '#default_value' => 'test ' . $row['name'],
only test apears!
Imho, that behaviour suggests that something is wrong with $row['name'] and less with Form API itself. (Because string concatenation fails even before the Form API gets the value passed over.)
Not sure, but maybe print_r($row) and/or gettype($row['name']) reveals some useful information...
Probably means your #value is getting set through some other mechanism. FormAPI can be pretty subtle at times. I seem to remember having a similar problem when I was playing around with #multistep, but I don't remember how I fixed it. good luck, -tao Feijó wrote:
John,
I only used #value to test my array content!! I do not intent to use both
With #value, it shows up, when I change to #default_value, the information is gone!!!
its clear now? :)
thanks!! Feijó
John VanDyk escreveu:
If #value is set, #default_value will be ineffective. From form.inc:
if (!isset($form['#value'])) { $function = $form['#type'] . '_value'; if (function_exists($function)) { $function($form); } else { $form['#value'] = isset($form['#default_value']) ? $form['#default_value'] : ''; } }
Because the form is built multiple times, this can be confusing.
I already try with print_r !
it shows the content "array(['name'] => 'name test')" in #description and #value, but never on #default_value
The name field is varchar(50), with 'name test'. Just it.
Yesterday a PHP expert was here, he take a look at this, we try a lot of possibilities, no clue whatsoever
It cant be explained :)
Jakob Petsovits escreveu:
On Thursday, 24. January 2008, Feijó wrote:
If I try '#default_value' => 'test ' . $row['name'],
only test apears!
Imho, that behaviour suggests that something is wrong with $row['name'] and less with Form API itself. (Because string concatenation fails even before the Form API gets the value passed over.)
Not sure, but maybe print_r($row) and/or gettype($row['name']) reveals some useful information...
Does your form builder function get any parameter? Do you use any of them in your query? Are you sure that they have the same values on every build? On Jan 24, 2008 7:53 PM, Feijó <patrao@legendas.feijo.info> wrote:
Yes, I'm using #multistep
I thought about that, $form been built more than one time. My test seens to point somewhere else.
look at this:
// my previous array $report, returned by db_fetch_array $report['name'] .= ' something'; // I insert 'something' into it
$form['saveit']['name'] = array( '#type' => 'textfield', '#title' => t('Name'), * '#default_value' => $report['name'], ** '#description' => $report['name'], ***
what should be the result from default_value and description? The same? No, look:
Nome: Array ( [name] => test something )
'something' shows on both outputs, but 'test' only in #descrtption. If is the SAME source ($report['name']), where is 'test' ??? I'm geting crazy with that :P
I can provide a demo site if its a good idea.
Feijó
Tao Starbow escreveu:
Probably means your #value is getting set through some other mechanism. FormAPI can be pretty subtle at times. I seem to remember having a similar problem when I was playing around with #multistep, but I don't remember how I fixed it.
good luck, -tao
Feijó wrote:
Yes, I use that return ($form_values) into my query:
$result = db_query('select name from {reports} where rid=%d', $form_values['saved']); $report = db_fetch_array($result);
Why not simplify the code as much as possible, then post the _entire_ relevant snippet (form builder, validate and submit handlers) on one of the pastebins? Regards, Heine Deelstra -- Rarely is the feuilleton the best medium to conduct debugging in. See also http://heine.familiedeelstra.com/coding-help-tips
You explained that you are using multistep. And perhaps you're problem appears on the second or subsequent form. (I'm guessing). #default_value is the default, and it is replaced by values from the post. So try a print_r($_REQUEST) and see if name or edit[name] is being passed in. Also try a print_r($form), after your alter to see what's really in #default_value. -Dave
i guess "in the first step the query returns an empty result and default value (and value) and description are set empty(they are not visible yet). in the second step, the query returns a non-empty result and only description is set, value is not set since it was set in the first step." On Jan 25, 2008 2:58 AM, Dave Cohen <drupal@dave-cohen.com> wrote:
You explained that you are using multistep. And perhaps you're problem appears on the second or subsequent form. (I'm guessing).
#default_value is the default, and it is replaced by values from the post. So try a print_r($_REQUEST) and see if name or edit[name] is being passed in.
Also try a print_r($form), after your alter to see what's really in #default_value.
-Dave
participants (7)
-
Dave Cohen -
Feijó -
Heine Deelstra -
Jakob Petsovits -
John VanDyk -
Tao Starbow -
ufuk bayburt