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&nbsp;!</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

Jaypan’s picture

This:

$form[$row['id']][$key] = array(
  'value' => t($result),
);

Should be this:

$form[$row['id']][$key] = array(
  '#markup' => $result, // Don't wrap $result in t()
);
neha.gangwar’s picture

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.

pixi’s picture

Thanks to you.

I don't really understand... Changed my code:

function page_accueil_form($form, &$form_state){

  $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(
		   '#markup' => '<p>'.$result.'</p>',
		   '#prefix' => '',
		);		
	  }
    }
  }

  $form['#theme'] = 'page_accueil_form';

  return $form;
}

And the .tpl:

<div class="row">
			
<?php 
          
	 //$form = drupal_get_form('page_accueil_form');

     	  foreach($form as $id => $data){
				
		print_r($data);
/*
Array ( [finalite] => Array ( [#markup] => finalité3
*/	
?>
	<div class="col-md-4">
		<div class="thumbnail">
			<div class="monDivImg">
				<div class="caption">
					<span class="label label-warning">Nouveau&nbsp;!</span><?php print render($data['finalite']); ?>
				</div>
...

I can't touch the value of the field 'finalite' ? :\

pixi’s picture

OK GOT IT !!
It works with this:<?php print drupal_render(t($data['finalite'])); ?>

THANK YOU BOTH ;)