drvlf9739
2017-01-19 12:40
浏览 42
已采纳

Smarty $ smarty.post它甚至没有工作,它工作的所有保留变量包括.get等

How I can use this

<input name="name" type="input" value="<?php echo @$_POST['name'] ?>" />

In smarty engine.

I have try reserved variable

{$smarty.post.name}

But it's giving error undefined variable and my smarty class object name is $Smarty.

Here is my form

<form method="post">
  {if strpos($SessionMessage, "Success") === FALSE}
    <h4 style="margin-top:10px">Post Your Comment:</h4>
    {$Message}

    <div class="form-group">
      <label>Name:</label>
      <input type="text" class="form-control" name="name" value="{if isset($smarty.post.name)}{$smarty.post.name}{/if}" placeholder="ext: Jon doe" />
    </div>
    <div class="form-group">
      <label>Comment:</label>
      <textarea cols="5" rows="5" class="form-control" name="comment" value="{if isset($smarty.post.comment)}{$smarty.post.comment}{/if}" placeholder="comments"></textarea>
    </div>
    <div class="form-group">
      <input type="submit" class="btn btn-success" value="Submit" name="submit" />
    </div>
  {else}
    {$Message}
  {/if}
</form>

This is my PHP Code

if(isset($_POST['submit'])) {
    $Name = trim($_POST['name']);
    $Body = trim($_POST['comment']);

    if(!empty($Body)) {
        $Comment = Comment::Make($Photo->id,$Name,$Body);
        if (is_object($Comment)) {
            if($Comment->Create()) {
                $Comment->SendNotification();
                $Session->MSG("Success: Comment is submit, awaiting for approval");
                RedirectTo("photo.php?id={$Photo->id}");
            } else {
                $Session->MSG("Danger: Something is Wrong");
                RedirectTo("photo.php?id={$Photo->id}");
            }
        } else {
            $Session->MSG("Danger: Something is Wrong");
            RedirectTo("photo.php?id={$Photo->id}");
        }           
    }else{
        $Session->MSG("Danger: Comment is empty");
        RedirectTo("photo.php?id={$Photo->id}");
    }
}

This is my all code related form you can check this out if i'm doing something wrong in it so kindly let me know. actually smarty .get it's working fine but .post it's not working.

2条回答 默认 最新

相关推荐 更多相似问题