Modification to Recipe
Firstly I should say that I am normally a Java developer rather than a php developer so there is a good chance that the problem is with my low php knowledge.
I am using Drupal 6.2 on a Linux/Apache box.
I am developing a website for some friends and decided to try using Drupal as the site is getting rapidly larger. It was required that I include some recipes in the site so I added the Recipe module.
Now the site required some functionality that the standard recipe module doesn't supply, primarily a category ('soup', 'meat' etc.) and a cuisine type ('English', 'French' etc.). This meant that I needed to add two 'select' boxes to the form with a list of elements. However I get an error.
'recoverable fatal error: Object of class stdClass could not be converted to string in /var/www/html/includes/form.inc on line 1406.'
Now this is a casting problem. Line 1406 of Form.inc is :
<?php
if ($value_valid && (!$value_is_array && (string)$element['#value'] === $key || ($value_is_array && in_array($key, $element['#value'])))) {
?>and the problem data that is passed is an array of strings. dvm() from the devel module gives the data as :
array(9) {
[0]=>
string(7) "chinese"
[1]=>
string(5) "czech"
[2]=>
string(7) "english"
[3]=>
string(6) "french"
[4]=>
string(6) "german"
[5]=>
string(5) "greek"
[6]=>
string(7) "italian"
[7]=>
string(4) "thai"
[8]=>
string(7) "unknown"
}
The problem seems to involve the involve the cast to (string). If this is removed the problem goes away. However I rather suspect that there is a good reason for the cast to be there.
Any assistance would be appreciated.

I don't know what the cause
I don't know what the cause of the error might be, but I want to ask you another question: how did you add the select boxes to the recipe module? The reason I ask: since you're quite new to Drupal, you may not be aware of the existing solutions to do it. I have never experienced errors such as yours when using existing modules.
Solution 1: CCK
CCK (Content Construction Kit, http://drupal.org/project/cck) is a module which allows you to add fields (for instance a select box with text values) to the create/edit form of a content type. CCK is a fantastic module - I guess 99% of the Drupal developers couldn't do without it. CCK for Drupal 6 is still in beta however.
Solution 2: Taxonomy
The taxonomy module is built into the Drupal core and allows categorization of nodes. In your case, you would create two vocabularies ('category' and 'cuisine'). You set up the vocabularies so that they apply to the recipe content type and add the terms to the vocabs. The taxonomy module would then add two select boxes to the create/edit form.
Well as I started this as a
Well as I started this as a method of learning Drupal/PHP I started with the existing recipe.module file and basically cut and pasted.
I added this in the middle of the recipe_form function,
<?php$category = $node->category;
if ($category) {
$form['category'] = array(
'#type' => 'select',
'#title' => t("Category"),
'#default_value' => $category,
'#options' => recipe_category_options(),
'#description' => t("Under what category would you place this recipe?"),
);
} else {
$form['category'] = array(
'#type' => 'select',
'#title' => t("Category"),
'#default_value' => 'Unknown',
'#options' => recipe_category_options(),
'#description' => t("Under what category would you place this recipe?"),
);
}
?>
and created a function to get the data from the database.
<?php
/**
* Returns a cached array of recipe category types.
*/
function recipe_category_options() {
static $categories;
static $cat_rs;
if (!isset($cat_rs)) {
$cat_rs = db_query('SELECT category FROM {recipe_category} ORDER BY category');
$categories = array();
while ($c = db_fetch_object($cat_rs)) {
$categories[] = t($c->category);
}
}
return $categories;
}
?>
Again these were modifications of code that I cut from the existing file. The 'select' boxes appear in the form page and the data appears within them but I get the error I reported earlier. The error has been reported before and seems to be caused when casting objects to strings, however not with this exact reason.
It is up to you to choose
It is up to you to choose your method, but I would recommend to combine unchanged modules (Recipe + Taxonomy in this case) instead of cooking up your own. The advantages of using standard modules:
- You can easily update them when new versions or security fixes are released.
- Lots of other modules expand on Taxonomy. Faceted search, for instance, makes it very easy to filter lists by category.
- More people can help you here on the forum.
- When, in the future, another developer has to continue what you started, it's easier for him to build upon standard code. So, a site built from standard components is more valuable for your client.
- You might be programming things that others have programmed already.
Thanks I'll look into doing
Thanks I'll look into doing that way.