...

View Full Version : Help me on smarty user input field error



kingot
01-26-2012, 12:06 PM
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

Dan13071992
01-26-2012, 12:10 PM
what are the errors?

kingot
01-26-2012, 12:56 PM
Hi Sir,
Thanks for your support..
Here is the error

Parse error: syntax error, unexpected '{' in C:\wamp\www\test\smarty\assign.php on line 16

But I'm trying a coupel of ways to get it work but not.Help if any i can get any tutorials to learn.

Thanks

Clement Ose

Dan13071992
01-26-2012, 01:02 PM
if and elseif statements shouldnt be wrapped in { } tags for example:

your code:



{if}(isset($_POST['name'])&&isset($_POST['phone'])&&isset($_POST['country'])){


should be:


if (isset($_POST['name'])&&isset($_POST['phone'])&&isset($_POST['country'])){

kingot
01-26-2012, 01:32 PM
Hi Sir,

Thanks for your support.But still getting this error

Parse error: syntax error, unexpected T_IF in C:\wamp\www\test\smarty\assign.php on line 16

But sir, in smarty is that how this should be coded looking at this code below and above tpl file



<?php
//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'];

if(!empty($name)&&!empty($phone)&&!empty($country)){

$smarty->assign('error','Please all fileds are required');;
}

}

);

$smarty->display('assign.tpl');

?>

Thanks and really grateful ..

Dan13071992
01-26-2012, 01:34 PM
sorry i miss read your question, i believed it was code of your own, sorry

kingot
01-26-2012, 01:53 PM
Hi Sir,
It not no body code ..it is mine having problem errors.

Look at the usrename Kingot.

Please help



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum