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 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog