PHP Classes

ValidationServerFunction

Recommend this page to a friend!

      PHP Forms Class with HTML Generator and JavaScript Validation  >  PHP Forms Class with HTML Generator and JavaScript Validation package blog  >  Upcoming Visual HTML ...  >  All threads  >  ValidationServerFunction  >  (Un) Subscribe thread alerts  
Subject:ValidationServerFunction
Summary:ValidationServerFunction not really understood
Messages:8
Author:yves Lens
Date:2008-01-10 14:12:07
Update:2008-01-17 07:37:41
 

  1. ValidationServerFunction   Reply   Report abuse  
Picture of yves Lens yves Lens - 2008-01-10 14:12:07
Hello

I'm beginner in Object, i found these classes wonderful.

I ve tried to build a form with no problem. But when i want to make a controle with ValidationServerFunction it doesn't work
For exemple i have a form which works and this field

$form_create_user->AddInput(array(
"TYPE"=>"text",
"NAME"=>"alias",
"ID"=>"alias",
"ValidateAsNotEmpty"=>1,
"ValidateMinimumLength"=>8,
"ValidateMinimumLengthErrorMessage"=>"Longueur mini alias =8",
"MAXLENGTH"=>25,
"ValidationErrorMessage"=>"Erreur saisie Alias.",
"LABEL"=>"<u>A</u>lias",
"ACCESSKEY"=>"A",
"VALUE"=>"",
"ValidationServerFunction"=>"CheckUsernameUnique",
"ValidationServerFunctionErrorMessage"=>"erreur alias pas unique"

i've just writen a funtion to see if the program uses it
function CheckUsernameUnique(){
echo 'je passe dans la fonction CheckUsernameUnique';exit();
return false;
}
The program does not uses it

My question how to do for exemple after user has done the alias name in the form to control alias doesnt exist in a database?

Thanks

  2. Re: ValidationServerFunction   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2008-01-10 21:42:27 - In reply to message 1 from yves Lens
You should not call the exit function. You need to return 1 if the field is value is valid, or 0 otherwise.

  3. Re: ValidationServerFunction   Reply   Report abuse  
Picture of yves Lens yves Lens - 2008-01-11 06:24:50 - In reply to message 2 from Manuel Lemos
Hello
Yes i understand i don't need to put exit(); it was just to see if the program passed into in the function.
But it seems ithe program doesn't pass into this function
I ll try to understand and i ll look for the problem.

  4. Re: ValidationServerFunction   Reply   Report abuse  
Picture of yves Lens yves Lens - 2008-01-11 06:58:43 - In reply to message 2 from Manuel Lemos
Please
have you an exemple of form about this type of validation?

THANKS

  5. Re: ValidationServerFunction   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2008-01-11 07:26:34 - In reply to message 4 from yves Lens
There is not much to this kind of validation. You just need to define a function that returns 1 or 0 depending on whether the value is valid or not.

If the function is not being called, maybe you are not doing something, like your are not calling the Validate function. Maybe the value does not satisfy one of the other validation conditions.

It is hard to tell without seeing your whole script and what you are doing to test it.

  6. Re: ValidationServerFunction   Reply   Report abuse  
Picture of yves Lens yves Lens - 2008-01-16 09:59:24 - In reply to message 5 from Manuel Lemos
Hello
Sorry not to answer quickly
This is my test scripts

Thanks


the page test_function.php

<?php
/**
* Formulaire 1
* test
* @author Minguy Yves
* @(#) $Header: /home/mlemos/cvsroot/forms/test_form.php,v 1.32 2006/12/20 06:21:16 mlemos Exp $
*
*/
/**
* intégration de la classe forms.php
*/




if (!file_exists('class/forms.php')){
echo 'Une anomalie est survenue dans le déroulement du programme.
Merci de contacter l\'administrateur';exit();
}else {
if (!file_exists('class/class_ez_sql.php')){
echo 'Une anomalie est survenue dans le déroulement du programme.
Merci de contacter l\'administrateur';exit();
}else {
include('class/class_ez_sql.php');
if (!file_exists('config/config.inc.php')){
echo 'Une anomalie est survenue dans le déroulement du programme.
Merci de contacter l\'administrateur';exit();
}else {
include("config/config.inc.php") ;
$db = new db(EZSQL_DB_USER, EZSQL_DB_PASSWORD, EZSQL_DB_NAME, EZSQL_DB_HOST);
require("class/forms.php");




/**
* Création d'un objet formulaire
*/
$form_create_user=new form_class;
/**
* Définir le nom du formulaire qui sera utilisé par exemple en javascript
* validation générée par la classe
* Define the name of the form to be used for example in Javascript
* validation code generated by the class.
*/
$form_create_user->NAME="createUser_form";
/**
* Définiyion de la méthode utilisée
*
**/
$form_create_user->METHOD="POST";
/**
* Page activée après validation
* Make the form be displayed and also processed by this script.
*/
$form_create_user->ACTION="";
/**
* Specifier la fonction de sortie debug vous pouvez mettre n importe quel
* programme d erreur??
* Specify a debug output function you really want to output any
* programming errors.
*/
$form_create_user->debug="trigger_error";
/**
* Définir un message a afficher par javascript quand l utilisateur
* essaye de valider ce formulaire de nouveau depuis la meme page ??
* Define a warning message to display by Javascript code when the user
* attempts to submit the this form again from the same page.
*/
$form_create_user->ResubmitConfirmMessage=
"Etes vous sur de vouloir valider une deuxième fois?";
/**
* Output previously set password values
*/
$form_create_user->OutputPasswordValues=1;
/**
*
* Output multiple select options values separated by line breaks
*/
$form_create_user->OptionsSeparator="<br />\n";
/**
* Afficher toutes les erreurs de validation en meme temps
* Output all validation errors at once.
*/
$form_create_user->ShowAllErrors=1;
/**
* CSS a appliquer a chaque entrée non conforme
* Choisir une chaine de caractere non vide pour définir ce CSS
*
* CSS class to apply to all invalid inputs.
* Set to a non-empty string to specify the invalid input CSS class
*/
$form_create_user->InvalidCLASS='invalid';
/**
* Style à appliqyer pour toute entree invalide quand vous voulez juste
* ???????????????????????
* Style to apply to all invalid inputs when you just want to override a
* few style attributes, instead of replacing the CSS class
* Set to a non-empty string to specify the invalid input style attributes
*
* $form_create_user->InvalidSTYLE='background-color: #ffcccc; border-color: #000080';
*
*/
/**
* Text to prepend and append to the validation error messages.
* Texte qui apparait avant le libellé de l'erreur dans la fenetre java affichant les erreurs
*/
$form_create_user->ErrorMessagePrefix="* ";
$form_create_user->ErrorMessageSuffix="";
/**
* =========================================================================*
* Définir les champs du formulaire meme s'ils ne doivent pas être affichés.
* Define the form field properties even if they may not be displayed.
*/
/**
* champ 1 adresse email
*/
/**
* Champ 2 Nom avec pasage en maj apres validation
*/
/*$form_create_user->AddInput(array(
"TYPE"=>"text",
"NAME"=>"nom",
"ID"=>"nom",
"ValidationServerFunction"=>"test",
"ValidationServerFunctionErrorMessage"=>"erreur alias pas unique",
"ValidateAsNotEmpty"=>1,
"ValidateMinimumLength"=>5,
"ValidateMinimumLengthErrorMessage"=>"Longueur mini du nom =5",
"MAXLENGTH"=>100,
"Capitalization"=>"uppercase",
"ValidationErrorMessage"=>"Erreur saisie Nom.",
"LABEL"=>"<u>N</u>om",
"ACCESSKEY"=>"N"

));*/
$form_create_user->AddInput(array(
"TYPE"=>"text",
"NAME"=>"nom",
"ID"=>"nom",
"MAXLENGTH"=>50,
"LABEL"=>"<u>N</u>om",
"ACCESSKEY"=>"N",
"VALUE"=>$userdata['loginname'],
"ValidationServerFunction"=>"Test",
"ValidationServerFunctionErrorMessage"=>"User Name not unique - suggest you use your full email address?",
"SIZE"=>50
));


/**
* Bouton de validation
* Mettre obligatoirement le champ caché dessous
*
*/
$form_create_user->AddInput(array(
"TYPE"=>"submit",
"ID"=>"button_subscribe",
"VALUE"=>"Submit subscription",
"ACCESSKEY"=>"u"
));
$form_create_user->AddInput(array(
"TYPE"=>"image",
"ID"=>"image_subscribe",
"SRC"=>"images/add.png",
"ALT"=>"Submit subscription",
"STYLE"=>"border-width: 0px;"
));
/**
* Donner un nom au champ caché
* Give a name to hidden input field so you can tell whether the form is to
* be outputted for the first or otherwise it was submitted by the user.
*/
$form_create_user->AddInput(array(
"TYPE"=>"hidden",
"NAME"=>"doit",
"VALUE"=>1
));
/**
* controle après saisie du formulaire
*/

$form_create_user->LoadInputValues($form_create_user->WasSubmitted("doit"));
$verify=array();
/**
*
* le formualire a été saisi
*/
if($form_create_user->WasSubmitted("doit")) {
echo 'validé';
//$userAlias=$form_create_user->GetInputValue("alias");
//echo 'Alias'.$userAlias;

}else{
echo 'non validé';
}

?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Test for Manuel Lemos' PHP form class</title>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1">
<style type="text/css"><!--
.invalid { border-color: #ff0000; background-color: #ffcccc; }
// --></style>
</head>
<body onLoad="<?php echo $onload; ?>" bgcolor="#cccccc">
<center><h1>Essais de Formulaire Y Minguy</h1></center>
<hr />
<?php
/**
* Compose the form output by including a HTML form template with PHP code
* interleaaved with calls to insert form input field
* parts in the layout HTML.
*/

$form_create_user->StartLayoutCapture();
$title="Titre du formulaire";
$body_template="test_fonction.html.php";
require("templates/form_frame_yves.html.php");
$form_create_user->EndLayoutCapture();

/*
* Output the form using the function named Output.
*/
$form_create_user->DisplayOutput();
}
}
}
?>
</body>
</html>
<?php
function Test(){
global $form;
echo 'je passe dans la fonction CheckUsernameUnique';

return false;
}
?>

and the template

<p>form_formulaire1.html.php
</p>
<table width="250" border="1">
<tr>
<td><?php $form_create_user->AddLabelPart(array("FOR"=>"nom")); ?></td>
<td><?php $form_create_user->AddInputPart("nom"); ?></td>
<td><?php echo (IsSet($verify["nom"]) ? "[Verify]" : ""); ?></td>
</tr>



<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td> Saisie texte Transform premiere lettre majuscule</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td></td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td><?php $form_create_user->AddInputPart("image_subscribe"); ?>
<?php $form_create_user->AddInputPart("button_subscribe"); $form_create_user->AddInputPart("doit"); ?></td>
</tr>
</table>
<p>&nbsp; </p>


  7. Re: ValidationServerFunction   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2008-01-16 20:33:48 - In reply to message 6 from yves Lens
You are not calling the Validate() function anywhere.

  8. Re: ValidationServerFunction   Reply   Report abuse  
Picture of yves Lens yves Lens - 2008-01-17 07:37:41 - In reply to message 7 from Manuel Lemos
Hello
What a stupid boy i m

Sorry i was not searching at this place at all

THANKS