kingot
01-26-2012, 11:06 AM
Hi,
I'm working on user input using smarty to grab user details and output it to the user, but the code is not working and giving me errors
Here is the assign.php page code
<?php
require ('C:/wamp/www/test/smarty/libs/Smarty.class.php');
$smarty = new Smarty;
$smarty->template_dir = 'C:/wamp/www/test/smarty/template';
$smarty->compile_dir = 'C:/wamp/www/test/smarty/template_c';
$smarty->assign('title','Smarty section and loop assignment');
$smarty->assign('user','Field the form below');
//the form checking start here
$smarty->assign('output',{if}(isset($_POST['name'])&&isset($_POST['phone'])&&isset($_POST['country'])){
$name=$_POST['name'];
$phone=$_POST['phone'];
$country=$_POST['country'];
{elseif}(!empty($name)&&!empty($phone)&&!empty($country)){
$smarty->assign('error','Please all fileds are required');;
} {/if}
}
);
$smarty->display('assign.tpl');
?>
And here is the assign.tpl code
<html>
<head><title>{$title}</title></head>
<font color="red">{$user}</font>
{$smarty name=input loop=$output}
Name: {$output[input.name]}
Phone: {$output[input.phone]}
Country: {$output[input.country]}
{sectionelse}
{$smarty name= error loop=$error}
Error: {$error[error]}
{/section}
<table>
<form action="assign.php" method="POST">
<tr><td>Your Name: </td><td><input type="text" name="{$name}"></td></tr>
<tr><td>Your Phone No: </td><td><input type="text" name="{$phone}"></td></tr>
<tr><td>Your Country: </td><td><input type="text" name="{$country}"></td></tr>
<tr><td> </td><td><input type="submit" value="Submit"></td></tr>
</form>
</table>
<body>
</body>
</html>
Please any help would be much appreciated..on grabing the user input
Thanks
Clement Osei
I'm working on user input using smarty to grab user details and output it to the user, but the code is not working and giving me errors
Here is the assign.php page code
<?php
require ('C:/wamp/www/test/smarty/libs/Smarty.class.php');
$smarty = new Smarty;
$smarty->template_dir = 'C:/wamp/www/test/smarty/template';
$smarty->compile_dir = 'C:/wamp/www/test/smarty/template_c';
$smarty->assign('title','Smarty section and loop assignment');
$smarty->assign('user','Field the form below');
//the form checking start here
$smarty->assign('output',{if}(isset($_POST['name'])&&isset($_POST['phone'])&&isset($_POST['country'])){
$name=$_POST['name'];
$phone=$_POST['phone'];
$country=$_POST['country'];
{elseif}(!empty($name)&&!empty($phone)&&!empty($country)){
$smarty->assign('error','Please all fileds are required');;
} {/if}
}
);
$smarty->display('assign.tpl');
?>
And here is the assign.tpl code
<html>
<head><title>{$title}</title></head>
<font color="red">{$user}</font>
{$smarty name=input loop=$output}
Name: {$output[input.name]}
Phone: {$output[input.phone]}
Country: {$output[input.country]}
{sectionelse}
{$smarty name= error loop=$error}
Error: {$error[error]}
{/section}
<table>
<form action="assign.php" method="POST">
<tr><td>Your Name: </td><td><input type="text" name="{$name}"></td></tr>
<tr><td>Your Phone No: </td><td><input type="text" name="{$phone}"></td></tr>
<tr><td>Your Country: </td><td><input type="text" name="{$country}"></td></tr>
<tr><td> </td><td><input type="submit" value="Submit"></td></tr>
</form>
</table>
<body>
</body>
</html>
Please any help would be much appreciated..on grabing the user input
Thanks
Clement Osei