[PHP] [Smarty] Warning: Smarty error: validate

Pagina: 1
Acties:

Onderwerpen


Acties:
  • 0 Henk 'm!

  • annuh
  • Registratie: Februari 2006
  • Laatst online: 16-09 05:42
Tweakers!
Ik ben bezig om een site te maken met behulp van Smarty, hier is ook een hele handige plugin voor te vinden, nl. SmartyValidate (http://www.phpinsider.com/php/code/SmartyValidate/)
Het probleem is alleen, dat ik deze plugin niet goed werkend kan krijgen..
Ik krijg namelijk de volgende foutmeldingen:
code:
1
Warning: Smarty error: validate: validator id 'fusername' is not registered. in C:\xampp\htdocs\smarty\libs\Smarty.class.php on line 1095
Etc..

Dit zijn de codes:

registratie.php
PHP:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
<?php
$smarty->assign('content_title','Registreren');
require_once('smarty/libs/SmartyValidate.class.php');
if(empty($_POST)) {
        SmartyValidate::connect($smarty, true);
        SmartyValidate::register_validator('fusername','Username','notEmpty');
        SmartyValidate::register_validator('fwachtwoord1','Wachtwoord1','notEmpty');
        SmartyValidate::register_validator('fwachtwoord2','Wachtwoord2','notEmpty');
        SmartyValidate::register_validator('femail','Email','notEmpty');        
        $smarty->assign('template', 'registratie.tpl');
    } else {    
        SmartyValidate::connect($smarty);
       // validate after a POST
       if(SmartyValidate::is_valid($_POST)) {
           // no errors, done with SmartyValidate
           SmartyValidate::disconnect();
           echo 'Gelukt!';
       } else {
           // error, redraw the form
           $smarty->assign($_POST);
           $smarty->assign('template', 'registratie.tpl');
       }
    }
?>


registratie.tpl
PHP:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
<form name="registreer" method="post" action="{$domein}/profiel/registreren" enctype="multipart/form-data">
    Om te registeren moet je onderstaand formulier even invullen!   
    <fieldset>
        <legend>Account Gegevens</legend>
            {validate id="fusername" message="Vul een gebruikersnaam in!"}
        <label for="username">Username</label> <input type="text" name="Username" id="username" /><br />
            {validate id="fwachtwoord1" message="Vul een wachtwoord in!<br>"}
        <label for="wachtwoord">Wachtwoord</label> <input type="password" name="Wachtwoord1"/><br />
            {validate id="fwachtwoord2" message="Vul ook hier een wachtwoord in!<br>"}          
        <label for="wachtwoord2">Wachtwoord <i>(controle)</i> </label> <input type="password" name="Wachtwoord2" id="wachtwoord2"/><br />
            {validate id="femail" message="Vul een geldig emailadres in!<br>"}
        <label for="email">E-mail</label> <input type="text" name="Email" id="email" value="{$email|escape}"/>
    </fieldset>
// Nog meer inputs...       
            <fieldset>
            <legend>Controleren</legend>
            <label for="akkoord">Ik ga akkoord met de regels</label><input type="checkbox" name="akkoord" id="akkoord"><br /><br />
            <input type="submit" class="submit" value="Versturen!">
            </fieldset>
            <input type="hidden" name="registreer_form" value="1"> 
            </form>


index.php
PHP:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
<?php
require_once('smarty/libs/Smarty.class.php');
$smarty = new Smarty();
$smarty->template_dir = 'smarty/templates/';
$smarty->compile_dir  = 'smarty/templates_c/';
$smarty->config_dir   = 'smarty/configs/';
$smarty->cache_dir    = 'smarty/cache/';

$smarty->assign('domein', 'http://localhost');

$pad = explode('/', $_SERVER['REQUEST_URI']);

$smarty->assign('location', $pad[1]);

$onderdeel = $pad[1];
$pagina = $pad[2];

if ($onderdeel == '') {
    // de code voor nieuwspagina's
    include ('home.php');
}
    

if ($onderdeel == 'profiel') {
    if ($pagina == 'registreren') {
    include ('profiel/registratie.php');
}

}
//** un-comment the following line to show the debug console
$smarty->debugging = true;
$smarty->display('index.tpl');

?> 

[ Voor 12% gewijzigd door annuh op 12-03-2008 14:53 ]


Acties:
  • 0 Henk 'm!

  • Frenkeman
  • Registratie: December 2007
  • Laatst online: 19-09 21:35
http://www.google.nl/sear...ered%22&btnG=Zoeken&meta=

5000 resultaten, zoek er maar 1 uit ;-)

Acties:
  • 0 Henk 'm!

  • annuh
  • Registratie: Februari 2006
  • Laatst online: 16-09 05:42
Wat denk je dat ik de hele dag al gedaan heb...? :P Maar helaas zonder resultaat! De meeste hits zijn pagina's die dezelfde foutmeldinge hebben er stond een 'tip' tussen
have the same problem. And I find it's because the $_POST is not empty.
So, replace
if(empty($_POST)) {
by
if(!isset($_SESSION['form_first_time'])){
$_SESSION['form_first_time'] = true;
Maar dit werkte niet bij mij.. Dus ik hoopte dat er hier iemand wist wat er aan de hand was.
Volgens mij 'register' ik ze wel.. :?

[ Voor 7% gewijzigd door annuh op 12-03-2008 14:57 ]


Acties:
  • 0 Henk 'm!

  • Matthis
  • Registratie: Juli 2004
  • Laatst online: 13-06 13:45
al 'ns het Smarty-forum zelf geprobeerd?

Acties:
  • 0 Henk 'm!

  • LuCarD
  • Registratie: Januari 2000
  • Niet online

LuCarD

Certified BUFH

Je mist de session_start() in je index.php

Programmer - an organism that turns coffee into software.


Acties:
  • 0 Henk 'm!

  • annuh
  • Registratie: Februari 2006
  • Laatst online: 16-09 05:42
LuCarD schreef op woensdag 12 maart 2008 @ 17:07:
Je mist de session_start() in je index.php
AARGH! 8)7 Je hebt gelijk!
Duizendmaal dank! _/-\o_

Acties:
  • 0 Henk 'm!

  • Cavorka
  • Registratie: April 2003
  • Laatst online: 27-03-2018

Cavorka

Internet Entrepreneur

annuh schreef op woensdag 12 maart 2008 @ 17:37:
[...]


AARGH! 8)7 Je hebt gelijk!
Duizendmaal dank! _/-\o_
error_reporting(E_ALL) wil ook nog wel eens helpen als je een website aan het bouwen bent. ;)

the-blueprints.com - The largest free blueprint collection on the internet: 50000+ drawings.


Acties:
  • 0 Henk 'm!

  • annuh
  • Registratie: Februari 2006
  • Laatst online: 16-09 05:42
Ja, maar in dit geval dus niet.. :o

Weet iemand of het ook mogelijk is om 1 validator aan meerde velden toe te wijzen?
Ik heb bijvoorbeeld 3 input-velden voor de geboortedatum, 1 voor de dag, 1 voor de maand en een voor het jaar. Nu zou ik graag willen dat als 1 (of meerdere) van deze dingen fout was, je de volgende tekst zag: "Vul een geldige geboortedatum in!"

registratie.php
PHP:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
<?php
$smarty->assign('content_title','Registreren');
require_once('smarty/libs/SmartyValidate.class.php');
if(empty($_POST)) {
        SmartyValidate::connect($smarty, true);
        SmartyValidate::register_validator('fgeb','gebjaar','isNumber');
        SmartyValidate::register_validator('fgeb','gebdag','isNumber');
        
        $smarty->assign('template', 'registratie.tpl');
    } else {    
        SmartyValidate::connect($smarty);
       // validate after a POST
       if(SmartyValidate::is_valid($_POST)) {
           // no errors, done with SmartyValidate
           SmartyValidate::disconnect();
           echo 'Gelukt!';
       } else {
           // error, redraw the form
           $smarty->assign($_POST);
           $smarty->assign('template', 'registratie.tpl');
       }
    }
?>



snippet registratie.tpl
PHP:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
        <label for="gebdag">Geboortedatum</label>
            <select name="gebdag"> 
                <option value="dag">Dag</option>
                <option value="01">01</option> 
                <option value="02">02</option> 
                <option>03</option> 
                <option>04</option> 
            </select>
            <select name="gebmaand"> 
                <option value="">Maand</option>
                <option value="01">Januari</option> 
            </select>
            <input type="text" id="gebjaar" name="gebjaar" size="4" maxlength="4">
            <font class="error">{validate id="fgeb" message="Vul een geldige geboortedatum in!"}</font>


Maar nu controleert hij alleen 'gebdag' omdat deze regel als laatste genoemd wordt in 'registratie.tpl'
Weet iemand of dit kan? In het forum van Smarty kunnen ze me ook niet verder helpen.. :'(

Acties:
  • 0 Henk 'm!

  • Oid
  • Registratie: November 2002
  • Niet online

Oid

PHP:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
<?php 
$smarty->assign('content_title','Registreren'); 
require_once('smarty/libs/SmartyValidate.class.php'); 
if(empty($_POST)) { 
        SmartyValidate::connect($smarty, true); 
        SmartyValidate::register_validator('fgeb','gebjaar:gebdag','isNumber'); 
         
        $smarty->assign('template', 'registratie.tpl'); 
    } else {     
        SmartyValidate::connect($smarty); 
       // validate after a POST 
       if(SmartyValidate::is_valid($_POST)) { 
           // no errors, done with SmartyValidate 
           SmartyValidate::disconnect(); 
           echo 'Gelukt!'; 
       } else { 
           // error, redraw the form 
           $smarty->assign($_POST); 
           $smarty->assign('template', 'registratie.tpl'); 
       } 
    } 
?>


Probeer dit eens
Pagina: 1