Forums

form works with ChConnectivity does not work with ChContact

beillard 16 Feb, 2010
Hi,

The form below works perfectly when it is called from Chronoconnectivity, but it does not work when it is called by Chronoform.

Part of the code of the form :
<div class="form_item">
  <div class="form_element cf_dropdown">
    <label class="cf_label" style="width: 280px;"><span style="color: #ff0000;">Nom de la bourse</span></label>
    <select class="cf_inputbox required" id="nomBourse" size="1" title="nomBourse"  name="nomBourse">
	<option value="">Sélectionner une bourse</option>
 <?php 
 $sql = 'SELECT nom_bourse FROM jos_chronoforms_NomBourses WHERE dateFinBourse >= CURRENT_DATE ORDER BY dateFinBourse'; 

$resultat = mysql_query($sql);
while ($data = mysql_fetch_object($resultat))
echo "<option value='$data->nom_bourse'> $data->nom_bourse </option>";

mysql_free_result($resultat);
 ?> 
    </select> 
	<div class="cfclear"> </div>
</div>
</div>

The error message with Chronocontact is : Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' ... in line
echo "<option value='$data->nom_bourse'> $data->nom_bourse </option>";

The Php code works fine with "Jumi".
Could you help me to understand where is the mistake (for Chronocontact) in this line above
echo "<option value='$data->nom_bourse'> $data->nom_bourse </option>";


Thanks in advance
André
GreyHead 16 Feb, 2010
Hi beillard,

I think it probably needs quotes around the object references.
echo "<option value='".$data->nom_bourse."'> ".$data->nom_bourse." </option>";

Bob
beillard 16 Feb, 2010
Hi Bob,

Thanks for your answer.
This does not solve the problem. ( Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in.. )

When I delete this line, the form works fine. I tried many option with quotes, without, but I can't make it working with the dropdown list.

Any ideas?

André
GreyHead 16 Feb, 2010
Hi André,

It's a standard PHP error but, like you I don't see anything wrong with the code you've posted. It's not how I would write it, and it's not using the Joomla database methods but it looks like good PHP to me :-(

Bob
beillard 16 Feb, 2010
Hi Bob,

I think I modified an example that I found in the forum.
What should be the good way to fill a dropdown list with a database table?

Best regards

André
GreyHead 16 Feb, 2010
Hi André,

I'd write it like this
<?php
$db =& JFactory::getDBO();
$sql = "
  SELECT `nom_bourse` 
    FROM `#__chronoforms_NomBourses` 
    WHERE `dateFinBourse` >= CURRENT_DATE 
    ORDER BY `dateFinBourse`
";
$db->setQuery($sql);
$resultat = $db->loadResultArray();
$options = array();
foreach ( $resultat as $v ) {
  $options() = "<option value='$data->nom_bourse' > $data->nom_bourse </option>";
}
?>
<div class="form_item">
  <div class="form_element cf_dropdown">
    <label class="cf_label" style="width: 280px;"><span style="color: #ff0000;">Nom de la bourse</span></label>
    <select class="cf_inputbox required" id="nomBourse" size="1" title="nomBourse"  name="nomBourse">
      <option value="">Sélectionner une bourse</option>
<?php
  echo implode('', $options);
?>
    </select>
  <div class="cfclear"> </div>
  </div>
</div>
beillard 17 Feb, 2010
Hi Bob,

I would not bore you. It is very kind of you to write this code.

When I tried to save the form with your code, (in the backend), I got this error : Fatal error: Can't use function return value in write context in ...t/administrator/components/com_chronocontact/admin.chronocontact.php(2736) : eval()'d code on line 33

Line 33 is :
$options() = "<option value='$data->nom_bourse' > $data->nom_bourse </option>";


Yesterday night, after many tries out, I got a result with my code by changing the line "echo" in two lines :
 echo "<option value='$data->nom_bourse'> $data->nom_bourse </option";

echo ">"; 

It's not very smart but it works.

Thanks for help
Don't spend more time on this issue.

Best regards

André
GreyHead 17 Feb, 2010
Hi André,

My error - writing too quickly. I should have written:
 $options[] = "<option value='".$data->nom_bourse."' > ".$data->nom_bourse." </option>";
Square brackets and more quotes.

Bob
beillard 17 Feb, 2010
Thanks again for help

André
This topic is locked and no more replies can be posted.