I'm trying to add PHP code to create a default value for a textfield in a CCK content type. It doesn't matter what combination of PHP I use (I've searched these forums extensively & tried *too* many combinations). I always get the red box:
The default value php code returned an incorrect value
Expected format :
array(
0 => array('value' => value for value),
// You'll usually want to stop here. Provide more values
// if you want your 'default value' to be multi-valued :
1 => array('value' => value for value),
2 => ...
);
Returned value :
---
When I input the PHP in the text box and then view the HTML I notice that "->" is always replaced by ">" For example:
global $user;
return (array( 0 => array('uid' => $user->uid)));
becomes
global $user;
return (array( 0 => array('uid' => $user->uid)));
Could that be part of the problem, or is this normal and I'm just searching... If I input the text into the HTML and click update, when I return to the HTML the text will appear converted. This may not be part of the problem, but I'm not sure where else to look.
Has anyone ran into this?
Thanks for any help.
Comments
I'm not seeing any
I'm not seeing any difference in the two statements, regardless though, I think what you want is:
===
"Give a man a fish and you feed him for a day. Teach a man to fish and you feed him for a lifetime." - Lao Tzu
"God helps those who help themselves." - Ben Franklin
"Search is your best friend." - Worldfallz
My mistake. global
I tried inserting the code you provided and received the same error message as above. Also the difference in the text is that all of the ">" were printed as ">" (the drupal forum parsed the html in my post!)
hmmm... I just
hmmm... I just double-checked my code again and it works fine. you're putting it into a cck text field right?
Also, I'm not sure why you have an extra ";" in first line of code-- but it shouldn't be there.
EDIT: i just had a thought-- you're not putting in the php tags are you?
===
"Give a man a fish and you feed him for a day. Teach a man to fish and you feed him for a lifetime." - Lao Tzu
"God helps those who help themselves." - Ben Franklin
"Search is your best friend." - Worldfallz
1.) I go to
1.) I go to admin/content/types
2.) Edit custom content type "User Profile," which is integrated into the default user account profile via the Node Profile module.
3.) Click the manage fields tab. There are about seven custom text fields I've added to this content type.
4.) Click "Configure" (for any of the seven fields, it doesn't matter which because they all produce the same behavior).
5.) Click "Default Value" to reveal the PHP input textbox.
6.) Paste in the code without php tags.
7.) No matter what combination of code I try to use I always receive:
The default value php code returned an incorrect value
Expected format :
array(
0 => array('value' => value for value),
// You'll usually want to stop here. Provide more values
// if you want your 'default value' to be multi-valued :
1 => array('value' => value for value),
2 => ...
);
Returned value :
----
It's very frustrating. What am I doing wrong?
5.) Click "Default Value"
Ok maybe we found the problem-- the first text box you see is not the php code box-- under that box is a collapsed fieldset named "PHP code". Expand that fieldset and put the code there.
===
"Give a man a fish and you feed him for a day. Teach a man to fish and you feed him for a lifetime." - Lao Tzu
"God helps those who help themselves." - Ben Franklin
"Search is your best friend." - Worldfallz
the drupal forum parsed the
enclose your code in <code> tags ;-)
===
"Give a man a fish and you feed him for a day. Teach a man to fish and you feed him for a lifetime." - Lao Tzu
"God helps those who help themselves." - Ben Franklin
"Search is your best friend." - Worldfallz
1.) I go to
1.) I go to admin/content/types
2.) Edit custom content type "User Profile," which is integrated into the default user account profile via the Node Profile module.
3.) Click the manage fields tab. There are about seven custom text fields I've added to this content type.
4.) Click "Configure" (for any of the seven fields, it doesn't matter which because they all produce the same behavior).
5.) Click "Default Value" to reveal the PHP input textbox.
6.) Paste in the code without php tags.
7.) No matter what combination of code I try to use I always receive:
The default value php code returned an incorrect value
Expected format :
array(
0 => array('value' => value for value),
// You'll usually want to stop here. Provide more values
// if you want your 'default value' to be multi-valued :
1 => array('value' => value for value),
2 => ...
);
Returned value :
----
It's very frustrating. What am I doing wrong?
I'm not sure why you
I'm not sure why you reposted this-- it looks exactly like the previous post. As i said above, clicking "default value" (your step 5 above) does NOT open the php text box-- that's just a plain text box. Below that text box should be another collapsed fieldset named "PHP code"-- click that to open the php textbox.
===
"Give a man a fish and you feed him for a day. Teach a man to fish and you feed him for a lifetime." - Lao Tzu
"God helps those who help themselves." - Ben Franklin
"Search is your best friend." - Worldfallz
I should've been more clear.
I should've been more clear. The PHP code box is where I'm entering the code. I click Default value to reveal the single line text box & then click PHP code to reveal the textbox. Same result.
then i think i'm stumped--
then i think i'm stumped-- do you have a wysiwyg editor on that textbox?
===
"Give a man a fish and you feed him for a day. Teach a man to fish and you feed him for a lifetime." - Lao Tzu
"God helps those who help themselves." - Ben Franklin
"Search is your best friend." - Worldfallz
Yes, the text box is a
Yes, the text box is a rich-text WYSIWYG editor (with buttons for changing the font-weight, alignment, etc.)
Ok-- you need to disable the
Ok-- you need to disable the rich text editor for that textbox.
===
"Give a man a fish and you feed him for a day. Teach a man to fish and you feed him for a lifetime." - Lao Tzu
"God helps those who help themselves." - Ben Franklin
"Search is your best friend." - Worldfallz
How do I do that? I've been
That worked like a charm. The code is accepted, but unfortunately it doesn't seem to be populating the field with the value when I create a new content type that uses that field. (user id)
hmmm... not sure what the
hmmm... not sure what the problem is... it works perfectly on my site. try clearing the cache....
===
"Give a man a fish and you feed him for a day. Teach a man to fish and you feed him for a lifetime." - Lao Tzu
"God helps those who help themselves." - Ben Franklin
"Search is your best friend." - Worldfallz
It may be the WYSIWYG editor...
Set the text editor to "simple mode" and clear out values before saving content type...everytime you change your settings.
Related Question: Adding <blockquotes> between INPUTTED TEXT
I'd like the inputted text to be enclosed in blockquotes. How do I do that with PHP? Specifically, how do I refer to the user's inputted value ("VALUE-CALL"?)
Stumped...