|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
netmastan Smarty Regular
Joined: 02 Jul 2004 Posts: 64
|
Posted: Mon Oct 18, 2004 3:03 am Post subject: form validaton (Form generated from scrpt) |
|
|
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 |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Mon Oct 18, 2004 3:10 am Post subject: |
|
|
Do the examples that come with SmartyValidate not make sense? |
|
Back to top |
|
netmastan Smarty Regular
Joined: 02 Jul 2004 Posts: 64
|
Posted: Mon Oct 18, 2004 6:07 am Post subject: |
|
|
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 |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Mon Oct 18, 2004 3:41 pm Post subject: |
|
|
what is the error? |
|
Back to top |
|
|
|
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
|