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条回答 默认 最新

  • donglijuan8227 2017-01-19 13:01
    关注

    After adding your form and your PHP code, the problem seems obvious : you're adding a redirect, which doesn't transmit POST data.

    You should send directly your form to photo.php?id={$Photo->id} and treat it there, without any redirect.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?