I have put the param om 1, to be sure if more than 1 records would give the message"> Custom Server Side validation - Forums

Forums

Custom Server Side validation

SPABO 23 Jan, 2012
Next to tackle....the following code, which worked nicely in V3, does not give any resukts in V4
<?
$db =& JFactory::getDBO();
$pst = "SELECT COUNT(*) AS %s FROM %s
  WHERE %s = %s";
$query = sprintf(
  $pst,
  $db->nameQuote('items'),
  $db->nameQuote('j17_chronoforms_data_Test2'),
  $db->nameQuote('Wedstrijddatum'),
  $db->Quote(JRequest::getString('Wedstrijddatum')));
$db->setQuery($query);
$result = $db->loadObject();
$total = $result->items+1;
if (($total = $result->items+1)>1) {
Return "Here the message : too many etc etc";
}
?>


I have put the param om 1, to be sure if more than 1 records would give the message
SPABO 24 Jan, 2012
Sorry, the previous topic is solved now, but this
Customer Server Side Validation

If the nr of records exceeds a "value" it should return an error message
Tried the following, (with no success)
<?
$db =& JFactory::getDBO();
$pst = "SELECT COUNT(*) AS %s FROM %s
  WHERE %s = %s";
$query = sprintf(
  $pst,
  $db->nameQuote('items'),
  $db->nameQuote('j17_chronoforms_TEST3'),
  $db->nameQuote('datum'),
  $db->Quote(JRequest::getString('datum')));
$result = $db->loadObject();
$total = $result->items+1;
$form->data['total'] = $total;
if ($form->data['total']>1) 
{
Return "Dear etc etc , sorry, etc etc";
}
?>
SPABO 24 Jan, 2012
Sorry for bumping, but pls could you help, I'm now trying and trying, but I;m missing the point apperently
GreyHead 24 Jan, 2012
Hi SPABO,

If in doubt check the Help tab.

In CFV4 the syntax has changed: replace
Return "Dear etc etc , sorry, etc etc";
with
  $form->validation_errors['some_input_name'] = "Dear etc etc , sorry, etc etc";
  return false;

Bob
SPABO 25 Jan, 2012
Dear Bob,
I tried this as wel, however , it does not show any error message
This is what I now have put in:
<?
    $db =& JFactory::getDBO();
    $pst = "SELECT COUNT(*) AS %s FROM %s
      WHERE %s = %s";
    $query = sprintf(
      $pst,
      $db->nameQuote('items'),
      $db->nameQuote('j17_chronoforms_TEST3'),
      $db->nameQuote('datum'),
      $db->Quote(JRequest::getString('datum')));
    $result = $db->loadObject();
    $total = $result->items+1;
    $form->data['total'] = $total;
    if ($form->data['total']>5){
    $form->validation_errors['datum'] = "Dear etc etc , sorry, etc etc";
      return false;}
    ?>
SPABO 27 Jan, 2012
Yes.....It works now...
Also had to play around how to order the various events, and you must not put the Lopp Event on "Submit" !!
I have one moer question on this topic.
How to remove the text under the fieldname, see picture

Look forward hearing from you soon

Pls find the code as well
<?
    $db =& JFactory::getDBO();
    $pst = "SELECT COUNT(*) AS %s FROM %s
      WHERE %s = %s";
    $query = sprintf(
      $pst,
      $db->nameQuote('items'),
      $db->nameQuote('j17_chronoforms_TEST3'),
      $db->nameQuote('datum'),
      $db->Quote(JRequest::getString('datum')));
    $result = $db->loadObject();
    $total = $result->items+1;
    $form->data['total'] = $total;
    if (($result->items+1)>5){
    $form->validation_errors['datum'] = 
    "Helaas, het maximum aantal deelnemers is reeds bereikt!<br>
    Stuur een e-mail naar de wedstrijdleiding als u op de<br>
    reservelijst wenst te komen.";
    return false;}
    ?>
GreyHead 29 Jan, 2012
Hi SPABO ,

I don't think you can - you could hide them with CSS or CSS + JavaScript though.

There is a setting on the Form General tab to turn off the Top Messages but I don't see any option to turn off the messages under the input.

Bob
SPABO 29 Jan, 2012
No problem Bob.

Pls put it on the "wishlist"

Tx so far!
This topic is locked and no more replies can be posted.