Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

SmartyValidate: [validate plugin] form 'default' is not ...
Goto page 1, 2  Next
 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Add-ons
View previous topic :: View next topic  
Author Message
ricklach
Smarty Regular


Joined: 27 Aug 2004
Posts: 39

PostPosted: Fri Aug 27, 2004 5:18 am    Post subject: SmartyValidate: [validate plugin] form 'default' is not ... Reply with quote

When trying SmartyValidate I get the following notice: Notice: SmartyValidate: [validate plugin] form 'default' is not registered. in c:\Smarty\libs\plugins\function.validate.php on line 35
What does this error mean and how can I fix it?
Back to top
View user's profile Send private message
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7368
Location: Lincoln Nebraska, USA

PostPosted: Fri Aug 27, 2004 2:42 pm    Post subject: Reply with quote

make sure you call:

session_start();
SmartyValidate::connect($smarty);

In your PHP application before displaying the template.
Back to top
View user's profile Send private message Visit poster's website
ricklach
Smarty Regular


Joined: 27 Aug 2004
Posts: 39

PostPosted: Fri Aug 27, 2004 3:32 pm    Post subject: Reply with quote

Yes, I think I have done that. I have a multi-call form and I have put the session_start() at the beginning of the form and this makes me wonder now if that is not the problem. I am thinking that each time I submit the form a new session would start and then that would give me the error. Here is a snippet of the code that I am trying to validate:

$db = db_connect();
if ( DB::isError( $db ) ) {
error_message( $db->getMessage() );
}
$smarty =& new Smarty_gpbc;
SmartyValidate::connect($smarty, true); //initialize SmartyValidate
SmartyValidate::register_form('addDonation.php');
$smarty->clear_cache( "addDonation.tpl" );
if(empty($_POST)) {
$smarty->display( "addDonation.tpl" );
} else {
// validate after a POST
if(SmartyValidate::is_valid($_POST, 'addDonation.php')) {
// no errors, done with SmartyValidate
SmartyValidate::disconnect();
// add the data to the tables
// add some code here to display a success message
$success = "The record was successfully added to the database.";
//echo $success;
$smarty->assign( 'success', $success );
$smarty->assign( 'donation_type', true );
$smarty->display( "success.tpl" );

} else {
// error, redraw the form
$smarty->assign($_POST);
$smarty->assign( 'show_add', true );
$smarty->display('addDonation.tpl');
}
}

Some of the additional SmartyValidate code was added while experimenting.

Rick
Back to top
View user's profile Send private message
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7368
Location: Lincoln Nebraska, USA

PostPosted: Fri Aug 27, 2004 3:39 pm    Post subject: Reply with quote

Did you try connect() without the second parameter "true"? Is session_start() in your script before everything else?
Back to top
View user's profile Send private message Visit poster's website
ricklach
Smarty Regular


Joined: 27 Aug 2004
Posts: 39

PostPosted: Fri Aug 27, 2004 4:04 pm    Post subject: Reply with quote

Yes, I did try it without "true" first. And, session_start is at the very top of the page as the very first item after the <?php tag.

Rick
Back to top
View user's profile Send private message
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7368
Location: Lincoln Nebraska, USA

PostPosted: Fri Aug 27, 2004 5:05 pm    Post subject: Reply with quote

In your validate tags, you must supply the form name that you registered.

{validate form="addDonation.php" ...}

I'm not sure why you named it with a .php extention, that isn't necessary.
Back to top
View user's profile Send private message Visit poster's website
ricklach
Smarty Regular


Joined: 27 Aug 2004
Posts: 39

PostPosted: Fri Aug 27, 2004 8:11 pm    Post subject: Reply with quote

OK, I took out the php extension, added the necessary code to the template and now I am getting this error: Notice: SmartyValidate: [validate plugin] form 'addDonation' is not registered. Here is the code where I try to register the form:
$smarty =& new Smarty_gpbc;
SmartyValidate::connect($smarty, true); //initialize SmartyValidate
SmartyValidate::register_form('addDonation', true);
$smarty->clear_cache( "addDonation.tpl" );
Back to top
View user's profile Send private message
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7368
Location: Lincoln Nebraska, USA

PostPosted: Fri Aug 27, 2004 8:34 pm    Post subject: Reply with quote

Your addDonation form registration is getting reset every invocation with that "true" parameter. Get rid of the "true" parameters, clear out the session (run disconnect() once), then try again.
Back to top
View user's profile Send private message Visit poster's website
ricklach
Smarty Regular


Joined: 27 Aug 2004
Posts: 39

PostPosted: Sat Aug 28, 2004 3:02 am    Post subject: Reply with quote

Ok, I did what you suggested and I still get the same error message: Notice: SmartyValidate: [validate plugin] form 'addDonation' is not registered. in c:\Smarty\libs\plugins\function.validate.php on line 35
Any other suggestions? BTW I tried the example and it does not seem to work as I would expect - however, I do not get the error message. For example, when you do a SmartyValidate::is_valid($_POST) does it mean that all the name/values in the POST array have to be filled-in because it seems that when I run the test form it starts out with all the validate info in the form, even before I submit the form.

Rick
Back to top
View user's profile Send private message
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7368
Location: Lincoln Nebraska, USA

PostPosted: Sat Aug 28, 2004 1:29 pm    Post subject: Reply with quote

what does your session data look like?

[php:1:6ff7cbe6cd]print_r($_SESSION['SmartyValidate']);[/php:1:6ff7cbe6cd]
Back to top
View user's profile Send private message Visit poster's website
ricklach
Smarty Regular


Joined: 27 Aug 2004
Posts: 39

PostPosted: Sat Aug 28, 2004 5:36 pm    Post subject: Reply with quote

Here is the session data:
Array ( [default] => Array ( [registered_funcs] => Array ( [criteria] => Array ( ) [transform] => Array ( ) ) [validators] => Array ( ) [is_error] => ) [addDonation] => Array ( [registered_funcs] => Array ( [criteria] => Array ( ) [transform] => Array ( ) ) [validators] => Array ( ) [is_error] => ) )

There is nothing there. Is it critical where the code snippet for the session dump is placed?
Back to top
View user's profile Send private message
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7368
Location: Lincoln Nebraska, USA

PostPosted: Sat Aug 28, 2004 6:22 pm    Post subject: Reply with quote

Do you have any validators on your form? they should get populated into the session data on the first drawing of the form.
Back to top
View user's profile Send private message Visit poster's website
ricklach
Smarty Regular


Joined: 27 Aug 2004
Posts: 39

PostPosted: Mon Aug 30, 2004 3:14 am    Post subject: Reply with quote

Monte,
I have a validator in the template part of the form. This is a multi-part form:
function donation_type
first part of form with submit to show_add

function show_add
display the main form with the validator information
submit to the database

function do_add
add the stuff to the database after it is validated

The template follows the same logic. The start_session is on the very first line of the of the file that contains the three steps.
Back to top
View user's profile Send private message
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7368
Location: Lincoln Nebraska, USA

PostPosted: Mon Aug 30, 2004 3:14 pm    Post subject: Reply with quote

When you register the form, the empty form container is created in the $_SESSION (which it looks like yours did get created.) Then when you draw the form for the first time, the validator information should get written to the $_SESSION data. I don't see that in your session data.

So example:

[php:1:37e020c5ca]session_start();
$smarty =& new Smarty;
SmartyValidate::connect($smarty);
SmartyValidate::register_form('myform');

$smarty->display('myform.tpl');[/php:1:37e020c5ca]

myform.tpl:

Code:
{validate form="myform" criteria="notEmpty" field="name"}
<form action="{$SCRIPT_NAME}">
<input type="text" name="name">
</form>


After the script is ran and the form is drawn, the "notEmpty" criteria should be in the $_SESSION data for 'myform'.
Back to top
View user's profile Send private message Visit poster's website
kills
Smarty Elite


Joined: 28 May 2004
Posts: 493

PostPosted: Tue Aug 31, 2004 6:03 pm    Post subject: Reply with quote

hm i got a similar problem and dont know y?

PHP:
[php:1:7ffd2032a9]
.
.

/* SmartyValidate Objekt initialisieren */
SmartyValidate::connect( $oTpl);

if( !empty( $_POST)) {
// validate after a POST
if( SmartyValidate::is_valid( $_POST)) {
// no errors, done with SmartyValidate
SmartyValidate::disconnect();
$iNewsId = isset( $_GET["id_news"]) ? $_GET["id_news"] : null;
$oNews = new news( $iNewsId);
$oNews->setHeaderDetails( $_POST["id_newscat"], user::getUserId(),$_POST["title"], $_POST["intro"]);
} else {
// error, redraw the form
$oTpl->assign( $_POST);
}
}
[/php:1:7ffd2032a9]

TPL:
Code:

<form action="{ $smarty.server.PHP_SELF }?{ $smarty.server.QUERY_STRING}" method="post">
   <table>
      <colgroup>
        <col width="70px"/>
         <col width="450px"/>
      </colgroup>
      <tr>
         <td>
            Kategorie
         </td>
         <td>
            { validate field="id_newscat" criteria="notEmpty" message="Die Kategorie des Artikels fehlt!"|make_error }
            <select class="max" name="id_newscat">
               { html_options options=$aNewsCats selected=$id_newscat }
            </select>
         </td>
      </tr>
     
      <tr>
         <td>
            Titel
         </td>
         <td>
            { validate field="title" criteria="notEmpty" message="Der Titel des Artikels fehlt!"|make_error }
            <input type="text" style="width:100%" class="text" name="title" value="{ $title }" maxlength="255"/>
         </td>
      </tr>
     
      <tr>
         <td>
            Einleitung
         </td>
         <td>
            { validate field="intro" criteria="notEmpty" message="Die Einleitung des Artikels fehlt!"|make_error }
            <textarea style="width:100%" class="text" name="intro">{ $intro }</textarea>
         </td>
      </tr>
     
      <tr>
         <td style="text-align: center;" colspan="2">
            <input type="submit" value="Speichern" />
         </td>
      </tr>
   </table>
</form>


if i lose one filed the error which should occure occures.
But when all fields where filled and the form will be submitted this error is printed:

Notice: SmartyValidate: [validate plugin] form 'default' is not registered. in E:\wwwroot\html\st-carstyling\bin\classes\Smarty-2.6.3\plugins\function.validate.php on line 35
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Add-ons All times are GMT
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP