Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    Regular Coder
    Join Date
    Feb 2011
    Posts
    114
    Thanks
    12
    Thanked 0 Times in 0 Posts

    Help me on smarty user input field error

    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 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

  • #2
    Regular Coder
    Join Date
    Dec 2010
    Location
    Kent, UK
    Posts
    573
    Thanks
    23
    Thanked 10 Times in 10 Posts
    what are the errors?
    http://360-tactics.co.uk/forum/index.php

    Crime-Wave

    please post your code wrapped in tags
    please post your PHP wrapped in tags

  • #3
    Regular Coder
    Join Date
    Feb 2011
    Posts
    114
    Thanks
    12
    Thanked 0 Times in 0 Posts
    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

  • #4
    Regular Coder
    Join Date
    Dec 2010
    Location
    Kent, UK
    Posts
    573
    Thanks
    23
    Thanked 10 Times in 10 Posts
    if and elseif statements shouldnt be wrapped in { } tags for example:

    your code:

    PHP Code:
    {if}(isset($_POST['name'])&&isset($_POST['phone'])&&isset($_POST['country'])){ 
    should be:
    PHP Code:
    if (isset($_POST['name'])&&isset($_POST['phone'])&&isset($_POST['country'])){ 
    http://360-tactics.co.uk/forum/index.php

    Crime-Wave

    please post your code wrapped in tags
    please post your PHP wrapped in tags

  • #5
    Regular Coder
    Join Date
    Feb 2011
    Posts
    114
    Thanks
    12
    Thanked 0 Times in 0 Posts
    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


    Code:
    <?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 ..

  • #6
    Regular Coder
    Join Date
    Dec 2010
    Location
    Kent, UK
    Posts
    573
    Thanks
    23
    Thanked 10 Times in 10 Posts
    sorry i miss read your question, i believed it was code of your own, sorry
    http://360-tactics.co.uk/forum/index.php

    Crime-Wave

    please post your code wrapped in tags
    please post your PHP wrapped in tags

  • #7
    Regular Coder
    Join Date
    Feb 2011
    Posts
    114
    Thanks
    12
    Thanked 0 Times in 0 Posts
    Hi Sir,
    It not no body code ..it is mine having problem errors.

    Look at the usrename Kingot.

    Please help


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •