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

form validaton (Form generated from scrpt)

 
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
netmastan
Smarty Regular


Joined: 02 Jul 2004
Posts: 64

PostPosted: Mon Oct 18, 2004 3:03 am    Post subject: form validaton (Form generated from scrpt) Reply with quote

hi
I have a file booking.php which generated a form based on the information passed from database..(Form:booking.tpl,Action:booking2.php)

Code:

<?
//booking.php
if(eregi("home.php",$_SERVER["PHP_SELF"])){
header("location:index.php");
die();
}

$index=1;

$page_title="Booking page";

require_once("mainfile.php");


global $db;
include("header.php");
$tpl= new Template();

//Origin
$qorigin=$db->query("SELECT * FROM travel_origin");
while($row=$db->fetch_array($qorigin)){
   $origin[]=$row;
}

//Destination
$qdestination=$db->query("SELECT * FROM travel_destination");
while($row2=$db->fetch_array($qdestination)){
   $destination[]=$row2;
}

$tpl->assign("origin",$origin);
$tpl->assign("destination",$destination);
$tpl->display("booking.tpl");
include("footer.php");




And second file booking2.php gets submitted value from booking.php file
(Form:booking2.tpl)


As far i kow To validate the form i will have to put the validation code(http://www.phpinsider.com/php/code/SmartyValidate/) in the booking.php and validation field in booking.tpl file ...but how i will put it as it generating the booking.tpl form.

Any ideas..
Back to top
View user's profile Send private message
mohrt
Administrator


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

PostPosted: Mon Oct 18, 2004 3:10 am    Post subject: Reply with quote

Do the examples that come with SmartyValidate not make sense?
Back to top
View user's profile Send private message Visit poster's website
netmastan
Smarty Regular


Joined: 02 Jul 2004
Posts: 64

PostPosted: Mon Oct 18, 2004 6:07 am    Post subject: Reply with quote

if the form is static i dont have any problem but my form is different.
I have a dropdownlist generated dynamically.

Code:

form.tpl
    --------
   
    <form method="POST" action="index.php">
   
    {validate field="FullName" criteria="notEmpty" message="Full Name cannot be empty"}
    Full Name: <input type="text" name="FullName">
   
    {validate field="Date" criteria="isDate" message="Date is not valid"}
    Date: <input type="text" name="Date">

 Destination:<select name="destination">
<option>--Select Destination--</option>
{section name="idx" loop="$destination"}
   <option value={$destination[idx].destination_id}>{$destination[idx].destination_name}</option>
{/section}
</select>
     

<input type="submit">

    </form>





Code:

//index.php

    session_start();
    require('Smarty.class.php');
    require('SmartyValidate.class.php');
   
    $smarty =& new Smarty;
   
    // required initialization
    SmartyValidate::connect($smarty);
   
    if(empty($_POST)) {
       $smarty->display('form.tpl');
    } else {   
       // validate after a POST
       if(SmartyValidate::is_valid($_POST)) {
           // no errors, done with SmartyValidate
           SmartyValidate::disconnect();
           $smarty->display('success.tpl');
       } else {
           // error, redraw the form
           $smarty->assign($_POST);
           $smarty->display('form.tpl');
       }
    }



if i add the following code in index.php i get errors(doesnot llike [] in the php validation code)
Code:

//Destination
$qdestination=$db->query("SELECT * FROM travel_destination");
while($row2=$db->fetch_array($qdestination)){
   $destination[]=$row2;
}

$smarty->assign("destination",$destination);
Back to top
View user's profile Send private message
mohrt
Administrator


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

PostPosted: Mon Oct 18, 2004 3:41 pm    Post subject: Reply with quote

what is the error?
Back to top
View user's profile Send private message Visit poster's website
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
Page 1 of 1

 
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