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

报告相同问题?

悬赏问题

  • ¥15 (标签-STM32|关键词-智能小车)
  • ¥20 关于#stm32#的问题,请各位专家解答!
  • ¥15 (标签-python)
  • ¥20 搭建awx,试了很多版本都有错
  • ¥15 java corba的客户端该如何指定使用本地某个固定IP去连接服务端?
  • ¥15 activiti工作流问题,求解答
  • ¥15 有人写过RPA后台管理系统么?
  • ¥15 Bioage计算生物学年龄
  • ¥20 如何将FPGA Alveo U50恢复原来出厂设置哇?
  • ¥50 cocos2d-x lua 在mac上接入lua protobuf?