Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
By pixi on
Hello :)
I'm back with a form trying to pass values in an array to the .tpl
function page_accueil_form(){
$query = 'SELECT finalite, thematique.libelle AS thematique, objectif.libelle AS objectif, idee.id AS id, reponse.reponse AS reponse, question.id AS id_question FROM {idee} ';
$query.= ' LEFT JOIN {thematique} ON (thematique.id = idee.id_thematique) ';
$query.= ' LEFT JOIN {objectif} ON (objectif.id = idee.id_objectif) ';
$query.= ' LEFT JOIN {reponse} ON (idee.id = reponse.id_idea) ';
$query.= ' LEFT JOIN {question} ON (question.id = reponse.id_question) ';
$results = db_query($query);
if ($results) {
$row = array();
while ($row = $results->fetchAssoc()) {
foreach ($row as $key => $result){
$form[$row['id']][$key] = array(
'value' => t($result),
);
}
}
}
$form['#theme'] = 'page_accueil_form';
return $form;
}
<div class="row">
<?php
foreach($form as $id => $data){
?>
<div class="col-md-4">
<div class="thumbnail">
<div class="monDivImg">
<div class="caption">
<span class="label label-warning">Nouveau !</span><?php print render($data["finalite"]["value"]); ?>
</div>
<div class="panel-body">
<div style="position:relative; left:0; top:0">
<?php //print render($data['img']); ?>
<img id="poitrash" src="images/trashcan.png" style="width:32px; height:32px; position:absolute; top:255px; left: 200px; cursor: pointer; display: none" />
</div>
</div>
<div class="panel-footer">
<div>Avancement: Cadrage</div>
<div class="progress" style="clear:both">
<div class="progress-bar" style="width:50%"></div>
</div>
<div class="cout">Coût de concrétisation: 2500€</div>
<div>Cible: Particuliers</div>
</div>
</div>
</div>
</div>
<?php
}
?>
</div>
<?php //print drupal_render_children($form); ?>
I got this error: Fatal error: Unsupported operand types
I don't understand which way to modify my files?
I have to use the field '#markup' to deal with values or how to do plz?
Comments
This:
This:
Should be this:
Some changes
First You need to change this to:
function page_accueil_form()
to
function page_accueil_form($form,&$form_state)
and then remove the t() function and may use '#markup' instead of 'value' as Jaypan suggested.
Thanks to you.
Thanks to you.
I don't really understand... Changed my code:
And the .tpl:
I can't touch the value of the field 'finalite' ? :\
OK GOT IT !!
OK GOT IT !!
It works with this:
<?php print drupal_render(t($data['finalite'])); ?>
THANK YOU BOTH ;)