Forums

Validation fields

vsbr 01 Mar, 2009
Hello!

I created a form with some required fields, “validate-email” fields, … and validation (mootools) was working well. But, after I having included some PHP code in “Form HTML” box, I send the form with required fields blank (or filled out incorrectly) and the validation don’t work.
For example, if I add the following code, I think the problem is on the line "$rows=$db->loadAssocList();", but I don’t understand why. I don’t know if the problem is the code or if there is any conflict...

<DIV class=form_item>
<DIV class="form_element cf_dropdown"><LABEL class=cf_label style="width: 100px;" >País</LABEL>
<?php
   $db =& JFactory::getDBO();
   $query = "SELECT * FROM #__paises";
   $db->setQuery($query);
   $rows = $db->loadAssocList();
?>
<SELECT class="cf_inputbox" style="width: 220px;" id=pais size=1 name=pais >
<?php
   foreach ($rows as $row) {
      if($row[nome] == "Portugal")
      { echo "<option value='$row[id]' selected>$row[nome]</option>"; }
      else { echo "<option value='$row[id]'>$row[nome]</option>"; }
   }   
   ?>
</SELECT></DIV>
<DIV class=clear> </DIV></DIV>


How can I solve this problem? Or is there a best way of validating forms?

Thanks,
vsbr
GreyHead 01 Mar, 2009
Hi vsbr,

ChronoForms uses the $rows and $row variable names internally so when you use them too it causes problems. Change your code to something like
. . .
   $rowsx = $db->loadAssocList();
?>
<SELECT class="cf_inputbox" style="width: 220px;" id=pais size=1 name=pais >
<?php
   foreach ($rowsx as $rowx) {
      if($rowx[nome] == "Portugal")
      { echo "<option value='$rowx[id]' selected>$rowx[nome]</option>"; }
      else { echo "<option value='$rowx[id]'>$rowx[nome]</option>"; }
   }   
   ?>
. . .

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