Forums

Prblems with serverside validation

alexpj 11 Apr, 2010
Hi,

1. i tryd to enable the "build in" validation. This will work fine with all forms made by the wizzard, but not with my "old" importet forms. (my mistake?)

2. So testet the serverside validation. That works fine.
But in case of an error the reshown form has no data. All fields are blank!
My website: http://www.dj-hochzeit.net/buchungsanfrage.html

Could you please help me for 1. or 2.?


My Code:
<?php
$errors = array();
$name = JRequest::getString('nachname','', 'post');
if ( !$name ) {
  $errors[] = 'Bitte geben Sie Ihre Nachnamen ein';
}
$name = JRequest::getString('email','', 'post');
if ( !$name ) {
  $errors[] = 'Bitte geben Sie eine gültige Emailadresse an';
}
$name = JRequest::getString('vaort','', 'post');
if ( !$name ) {
  $errors[] = 'Bitte ggf. PLZ und den Ort Ihrer Veranstaltung eintragen';
}
$name = JRequest::getString('vaanlass','', 'post');
if ( !$name ) {
  $errors[] = 'Bitte den Anlass Ihrer Veranstaltung eintragen';
}
if ( count($errors) ) {
  $message = "";
  foreach ($errors as $error ) {
    $message .= "<div class='error' >$error</div>";
  }
  return $message;
}
?>


And the Formcode
<table width="592" border="0" > <tr valign="top"> <td colspan="3" > <p align="center"><font face="Arial, Helvetica, sans-serif" size="3"><b><font size="4">Ja, ich interessiere mich für die <font color="#666666">Mobildiscothek</font></font><font color="#FF6633" size="4">nice</font><font size="4">!</font></b></font><font face="Arial, Helvetica, sans-serif"><b><br><br><font face="Arial, Helvetica, sans-serif"><b><font size="2">Bitte machen Sie mir ein unverbindliches Angebot für folgende Veranstaltung:<br><em>Sie können vorab <a href="http://www.mobildisco-nice.de/calendar.html">hier in der Buchungsübersicht</a> prüfen, ob der Termin noch frei ist. Sollte der Termin rot hinterlegt sein werde ich Ihre Anfrage ggf. an einen Kollegen weiterleiten.</em><br><i>(Bitte geben Sie die Daten ein und drücken Sie dann ABSENDEN.) </i></font></b></font><font size="2"></font></b></font></p>

<table border="0" cellpadding="0" cellspacing="0" width="586" height="994"><tr><td valign="top" height="991"> <table border=0 cellspacing=0 cellpadding=0 width=580> <tr>  <td align=left height="23"><font color="#000000" size="1">Die  mit einem </font><font color="#000000"><font color="#FF0000">*</font></font><font color="#000000" size="1">  gekennzeichneten Felder sind Pflichtfelder,  ohne die wir Ihre Anfrage leider nicht  korrekt bearbeiten können.</font></td> </tr> </table> <hr align=left width="580"> <table border=0 cellspacing=0 cellpadding=0 width=580> <tr>  <td colspan="4" align=left height="25"><font color="#000000"><b>Termin  der Veranstaltung</b></font></td> </tr> <tr>  <td width="65"><font color="#000000">Datum:<font color="#FF0000">*</font></font></td> <td width="184"><font color="#000000">  

<input type="Text" name="vadatum" size="25" title="Datum der Veranstaltung"> 

</font></td> <td width="67" font color=#FFFFFF size="-1"><font color="#000000">Startzeit:</font></td> <td width="225"><font color="#000000">  

<input type="Text" name="vabeginn" size="25"> 

</font></td> </tr> <tr>  <td width="70">  <td width="197"> </tr> <tr valign="bottom">  <td colspan="4" align=left height="25">  <hr align=left width="580"> </td> </tr> <tr>  <td colspan="4" align=left height="25"><font color="#000000"><b>Kundenadresse</b></font></td> </tr> <tr>  <td width="65" height="25"><font color="#000000">Vorname:</font></td> <td width="184" height="25"><font color="#000000">  

<input type="text" name="vorname" size="25">

</font></td> <td width="67" height="25"><font color="#000000">Nachname:<font color="#FF0000">*</font></font></td> <td width="225" height="25"><font color="#000000">  

<input type="text" name="nachname" size="25" title="Ihren Nachnamen">

</font></td> </tr> <tr>  <td width="65" height="25"><font color="#000000">Straße:</font></td> <td width="184" height="25"><font color="#000000">  

<input type="text" name="strasse" size="25">

 </font></td> <td width="67" height="25"><font color="#000000">Firma:</font></td> <td width="225" height="25"><font color="#000000">  

<input type="text" name="firma" size="25">

</font></td> </tr> <tr>  <td width="65" height="25"><font color="#000000">PLZ:<font color="#FF0000">*</font></font></td> <td width="184" height="25"><font color="#000000">  

<input type="text" name="plz" size="25" title="Ihre Postleitzahl">

</font></td> <td width="67" height="25"><font color="#000000">Ort:<font color="#FF0000">*</font></font></td> <td width="225" height="25"><font color="#000000">  

<input type="text" name="ort" size="25">

</font></td> </tr> <tr>  <td width="65" height="25"><font color="#000000">Telefon:<font color="#FF0000">*</font></font></td> <td width="184" height="25"><font color="#000000">  

<input type="text" name="tel" size="25">

</font></td> <td width="67" height="25"><font color="#000000">Telefax:</font></td> <td width="225" height="25"><font color="#000000">  

<input type="text" name="fax" size="25">

</font></td> </tr> <tr>  <td width="65" height="25"> </td> <td width="184" height="25"> </td> <td width="67" height="25"><font color="#000000">e-mail:<font color="#FF0000">*</font></font></td> <td width="225" height="25"><font color="#000000">  

<input type="text" name="email" size="25">

</font></td> </tr> <tr valign="bottom">  <td colspan="4" align=left height="25">  <hr align=left width="580"> </td> </tr> <tr>  <td colspan="4" align=left height="25">  <p><font color="#000000"><b> Lokalität  (Hotel, Vereinshaus etc.)</b> </font></p></td> </tr> <tr>  <td width="65"><font color="#000000">Name:</font></td> <td width="184"><font color="#000000">  

<input type="text" name="valokal" size="25">

</font></td> <td width="67"><font color="#000000">PLZ  / Ort:<font color="#FF0000">*</font></font></td> <td width="225"><font color="#000000">  




<input type="text" name="vaort" size="25" title="Ort Ihrer Veranstaltung"> 

</font></td> </tr> <tr valign="bottom">  <td colspan="4" align=left height="25">  <hr align=left width="580"> </td> </tr> <tr>  <td colspan="4" align=left height="25"><font color="#000000"><b>  Veranstaltung</b> </font></td> </tr> <tr valign="middle">  <td width="65" height="15"><font color="#000000">Anlass:<font color="#FF0000">*</font></font><font color="#000000"><font color="#FF0000"></font></font></td> <td width="184" height="15"><font color="#000000">  

<input type="text" name="vaanlass" size="25" title="Anlass Ihrer Veranstaltung">

 </font></td> <td width="67" height="15"><font color="#000000">Anzahl<br> der Gäste:<font color="#FF0000">*</font></font></td> <td width="225" height="15"><font color="#000000">  

<input type="text" name="pax" size="10">

</font></td> </tr> <tr valign="bottom">  <td colspan="4" height="25"> <hr> </td> </tr> <tr>  <td colspan="4" height="25"> <p><font color="#000000"><b>Alterstruktur  Ihrer Gäste</b></font></p></td> </tr> <tr>  <td colspan="4" align="left" valign="middle" height="7"><font color="#000000">  



<input type="checkbox" name="check1" value="X"> <20 Jahre |  

<input type="checkbox" name="check2" value="X"> 20-30 Jahre |  

<input type="checkbox" name="check3" value="X"> 30-40 Jahre |  

<input type="checkbox" name="check4" value="X"> 40-50 Jahre |  

<input type="checkbox" name="check5" value="X"> 50-60 Jahre |  

<input type="checkbox" name="check6" value="X"> 60+ </font> 







</td> </tr> <tr valign="bottom">  <td colspan="4" height="25"> <hr align=left width="580">  </td> </tr> </table> <table border=0 cellspacing=0 cellpadding=0 width=580 height="48"> <tr>  <td colspan="4" align=left height="25"><font color="#000000"><b>Wie  sind Sie auf uns aufmerksam geworden?</b></font></td> </tr> <tr>  <td align="left" colspan="4"> <font color="#000000">  

<select name="aufmerksam" size="1">
<option value= „„>Auswahl:</option> 
<option>Empfehlung</option>
<option>Lokalitaet</option>
<option>Live erlebt</option>
<option>Werbeflyer</option>
<option>Suchmaschine</option>
<option>sonstiges</option> 
</select>

 </font></td> </tr> </table> <hr align=left width="580"> <table border=0 cellspacing=0 cellpadding=0 width=580> <tr>  <td colspan="4" align=left height="25"><font color="#000000"><b>  Wie möchten Sie die gewünschten Informationen erhalten?</b>  </font></td> </tr> <tr>  <td align="left" colspan="4"> <font color="#000000" size="2">  

<input type="radio" value="email" name="mailinfo">

 </font> <font color="#000000" size="-1">per  Email</font> <font color="#000000" size="2"><br> 

<input type="radio" value="tel" name="telinfo"> 

</font> <font color="#000000" size="-1">Ich wünsche eine Beratung per Telefon unter </font><font size="2" color="#000000">  

<input type="text" name="infotel" size="15">

 <font size="1">(falls anders wie oben  angegeben)</font></font></td> </tr> </table> <hr align=left width="580"> <table border=0 cellspacing=0 cellpadding=0 width=580> <tr>  <td align=left><font color="#000000"><b>Kommentare/Fragen</b></font>  <p><font color="#000000" size="-1">Sollten  Sie Fragen, Kommentare, Anmerkungen  haben,<br> können Sie uns diese im folgenden  Feld mitteilen:<br>  </font> </td> </tr> <tr>  <td align=left> <font color="#000000">  <textarea name="kommentare" cols=60 rows=8></textarea> </font></td> </tr> </table> <font color="#000000">  </font> <table border=0 cellspacing=0 cellpadding=0 width=580> <tr>  <td align=left colspan="4"> <font color="#000000">  

<input type=SUBMIT value="ABSENDEN" name="SUBMIT"> 

<input type=reset value="RESET" name="Cancel"> 

  </font></td> </tr> </table> <br> </td> </tr> </table>  
GreyHead 11 Apr, 2010
Hi alexpj,

1) On the Form General tab set "Republish fields if error occured" to "Try to Republish"

2) Seems to work OK here, how are you enabling the validation?

Bob
alexpj 11 Apr, 2010

Hi alexpj,
1) On the Form General tab set "Republish fields if error occured" to "Try to Republish"


Thats it! The form now works fine with serverside validation. Big Thanks for that quick and great support!!!!!!

2) Seems to work OK here, how are you enabling the validation?
Bob


the shown code is placed in the validation tab.

Any ideas why the "build in" validation only works with wizzard made forms?
I put all the fieldnames in the correct validation field (1 - required, not emty and 7- validate-email (a valid email address)but nothing happens in my own forms. Is the something missing in the form code?

Last question ;-)
fot that build in validation ---> 7- validate-email (a valid email address)
i've looked for an example code for server side validation an found some PHP code. But it does not work. I think there is a better way by using the Joomla JRequest::getVar() syntax?
May you give me a code sniplet???

if ($_POST['email'] != "") {
    $email = filter_var($_POST['email'], FILTER_SANITIZE_EMAIL);
    if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
        $errors .= "$email is <strong>NOT</strong> a valid email address.<br/><br/>";
    }
} else {
    $errors .= 'Please enter your email address.<br/>';
}


thanks a lot and greetings from northern germany
Alex
GreyHead 11 Apr, 2010
Hi alexpj,

The Built-in JavaScript validation work OK with your Form HTML. I tested it.

Have you set Enable Validation to Yes?

Try this
$email = JRequest::getString('email', '', 'post');
if ( !$email ) {
    $messages[] = 'Please enter your email address.<br/>';
} else {
  $email = filter_var($_POST['email'], FILTER_SANITIZE_EMAIL);
  if ( !filter_var($email, FILTER_VALIDATE_EMAIL) ) {
    $messages[] = "$email is <strong>NOT</strong> a valid email address.<br/><br/>";
  }
}

Bob
GreyHead 11 Apr, 2010
Hi alexpj,

The JQuery no conflict command is loading before JQuery is called and breaking the JavaScrip. You may also have problems with YooTools on the same page and a slightly different MooTools version.

Bob
alexpj 11 Apr, 2010
Hi Bob,
after hours with try & error all works fine! Big thanks for your support!!!!!!!!!!!

My stupid mistakes:
[list]The "build in" Validation must be also activated in GENERAL Tab:
Load Chronoforms CSS/JS Files? = YES

The input type="text" is case sensitive. If input type="Text" the "build in" validation won't work[/list]

For all scriptsearcher here my (Your :-)) server side working Script:
Check for some emty fields
check for emty / valid email
gives a summary of Errors

<?php
$errors = array();

$name = JRequest::getString('vadatum','', 'post');
if ( !$name ) {
  $errors[] = 'Bitte das Datum Ihrer Veranstaltung eintragen';
}
$name = JRequest::getString('nachname','', 'post');
if ( !$name ) {
  $errors[] = 'Bitte geben Sie Ihre Nachnamen ein';
}
$email = JRequest::getString('email', '', 'post');
if ( !$email ) {
    $errors[] = 'Bitte geben sie eine eMail adresse an';
} else {
  $email = filter_var($_POST['email'], FILTER_SANITIZE_EMAIL);
  if ( !filter_var($email, FILTER_VALIDATE_EMAIL) ) {
    $errors[] = "$email ist <strong>keine</strong> gültige eMail adresse";
  }
}
$name = JRequest::getString('vaort','', 'post');
if ( !$name ) {
  $errors[] = 'Bitte ggf. PLZ und den Ort Ihrer Veranstaltung eintragen';
}
$name = JRequest::getString('vaanlass','', 'post');
if ( !$name ) {
  $errors[] = 'Bitte den Anlass Ihrer Veranstaltung eintragen';
}
if ( count($errors) ) {
  $message = "";
  foreach ($errors as $error ) {
    $message .= "<div class='error' >$error</div>";
  }
  return $message;
}
?>
alexpj 18 Apr, 2010
Hi Bob,
the form and valitation works fine, but there are some little problems at: http://www.dj-hochzeit.net/buchungsanfrage.html
I've build my checkboxes in an array to send correct values to the Email & confirmation page.

my Problems:
1. In case of an serverside validation check-error, are the marked boxes deleted on the reshown form.

MY CHECKBOX ARRAY:

<tr>  
    <td height="25" colspan="4" align="left"><font color="#000000"><b>Alterstruktur Ihrer Gäste</b></font></td>
</tr> 
<tr>  
    <td colspan="4" align="left"><font color="#000000"> 
<input value="unter 20 Jahre" title="" class="radio" id="check20" name="check2[]" type="checkbox"/><label for="check20" class="check_label"><20 Jahren |</label>
           
<input value="20-30 Jahre" title="" class="radio" id="check21" name="check2[]" type="checkbox"/><label for="check21" class="check_label">20-30 Jahre |</label>
      
<input value="30-40 Jahre" title="" class="radio" id="check22" name="check2[]" type="checkbox"/> <label for="check22" class="check_label">30-40 Jahre |</label>
      
<input value="40-50 Jahre" title="" class="radio" id="check23" name="check2[]" type="checkbox"/>  <label for="check23" class="check_label">40-50 Jahre |</label>

<input value="50-60 Jahre" title="" class="radio" id="check24" name="check2[]" type="checkbox"/>  <label for="check24" class="check_label">50-60 Jahre |</label>

<input value="60+ Jahre" title="" class="radio" id="check25" name="check2[]" type="checkbox"/>
<label for="check25" class="check_label">60+ Jahre</label>     
</div>
</div>
<div class="cfclear"> </div>
</div>
</td> </tr> 


And the serverside validation code:
<?php
$errors = array();

$name = JRequest::getString('vadatum','', 'post');
if ( !$name ) {
  $errors[] = 'Bitte das Datum Ihrer Veranstaltung eintragen';
}
$name = JRequest::getString('nachname','', 'post');
if ( !$name ) {
  $errors[] = 'Bitte geben Sie Ihre Nachnamen ein';
}
$email = JRequest::getString('email', '', 'post');
if ( !$email ) {
    $errors[] = 'Bitte geben sie eine eMail adresse an';
} else {
  $email = filter_var($_POST['email'], FILTER_SANITIZE_EMAIL);
  if ( !filter_var($email, FILTER_VALIDATE_EMAIL) ) {
    $errors[] = "$email ist <strong>keine</strong> gültige eMail adresse";
  }
}
$name = JRequest::getString('vaort','', 'post');
if ( !$name ) {
  $errors[] = 'Bitte ggf. PLZ und den Ort Ihrer Veranstaltung eintragen';
}
$name = JRequest::getString('vaanlass','', 'post');
if ( !$name ) {
  $errors[] = 'Bitte den Anlass Ihrer Veranstaltung eintragen';
}
if ( count($errors) ) {
  
  $message = "";
foreach ($errors as $error ) {
    $message .= "<div class='error'>$error</div>";
  }
  
return $message;
}
?>
alexpj 19 Apr, 2010
Is the a solution? (Show my marked checkboxes after server side validation error)
GreyHead 19 Apr, 2010
Hi Alexpj,

Try setting "ChronoForms handle my posted arrays:" to 'Yes' on the form General tab.

Bob
alexpj 19 Apr, 2010
Hi Bob, this option was already enabled.
This topic is locked and no more replies can be posted.