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 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看