当前位置: 首页>>代码示例>>PHP>>正文


PHP csrf_field函数代码示例

本文整理汇总了PHP中csrf_field函数的典型用法代码示例。如果您正苦于以下问题:PHP csrf_field函数的具体用法?PHP csrf_field怎么用?PHP csrf_field使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了csrf_field函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: displayComments

/**
 * Recursive function to output the html we need
 * @param $comments
 * @param $post
 */
function displayComments($comments, $post)
{
    foreach ($comments as $comment) {
        echo '<div class="well">';
        echo '<div>';
        echo $comment->text . '-' . $comment->user->name . '</div>';
        echo '<div>';
        if (Auth::check()) {
            if (Auth::user()->admin) {
                echo "<form action='/comment/" . $comment->id . "/delete' method='POST'>";
                echo csrf_field();
                echo method_field('DELETE');
                echo "<button type='submit' id='delete-comment-" . $comment->id . "' class='btn btn-danger btn-xs'>";
                echo "<i class='fa fa-btn fa-trash'></i> Delete Comment";
                echo "</button>";
                echo "</form>";
                echo "<br>";
            }
            echo '<button id="/comment/' . $post->id . '/' . $comment->id . '" class="btn btn-primary btn-xs"><i class="fa fa-reply"></i> Reply</button> ';
            echo '<button id="/commend/' . $comment->id . '" class="btn btn-success btn-xs"><i class="fa fa-thumbs-up"></i> Commend (' . $comment->voteCount . ')</button> ';
            if (Auth::user()->admin) {
                echo "<a href=" . route('confirmBan', ['userId' => $comment->user->id]) . " class='btn btn-danger btn-xs'><i class='fa fa-ban'></i> Ban User</a> ";
            }
        }
        if ($comment->replies) {
            displayComments($comment->replies, $post);
        }
        echo '</div>';
        echo '</div>';
    }
}
开发者ID:aliaseight,项目名称:laravel-red9k,代码行数:36,代码来源:comments.blade.php

示例2: form

 function form(Form\Form\Form $form)
 {
     $html = '';
     $form->addAttribute('role', 'form');
     $form->addClass('form-horizontal');
     // Elements
     if ($form->hasCsrfToken()) {
         $html .= csrf_field();
     }
     if ($form->hasLegend()) {
         $html .= html('h4', ['class' => Style::MODAL_HEADER_TITLE_CLASS], $form->getLegend());
     }
     $html = html('div', ['class' => Style::MODAL_HEADER_CLASS], $html);
     $body = '';
     foreach ($form->getElements() as $e) {
         /** @var $e \FrenchFrogs\Form\Element\Element */
         $body .= $e->render();
     }
     // body
     $html .= html('div', ['class' => Style::MODAL_BODY_CLASS . ' form-body'], $body);
     // Actions
     if ($form->hasActions()) {
         $actions = '';
         foreach ($form->getActions() as $e) {
             $actions .= $e->render();
         }
         $html .= html('div', ['class' => Style::MODAL_FOOTER_CLASS], $actions);
     }
     if ($form->isRemote()) {
         $form->addClass('form-remote');
     }
     $html = html('form', $form->getAttributes(), $html);
     return $html;
 }
开发者ID:frenchfrogs,项目名称:framework,代码行数:34,代码来源:ConquerModal.php

示例3: form

 function form(Form\Form\Form $form)
 {
     $html = '';
     $form->addAttribute('role', 'form');
     // Elements
     if ($form->hasCsrfToken()) {
         $html .= csrf_field();
     }
     foreach ($form->getElements() as $e) {
         /** @var $e \FrenchFrogs\Form\Element\Element */
         $html .= $e->render();
     }
     // Actions
     if ($form->hasActions()) {
         $html .= '<div class="text-right">';
         foreach ($form->getActions() as $e) {
             $html .= $e->render();
         }
         $html .= "</div>";
     }
     if ($form->isRemote()) {
         $form->addClass('form-remote');
     } elseif ($form->isCallback()) {
         $form->addClass('form-callback');
     }
     $form->addCLass('form-horizontal');
     $html = html('form', $form->getAttributes(), $html);
     if ($form->hasPanel()) {
         $html = $form->getPanel()->setBody($html)->render();
     }
     return $html;
 }
开发者ID:frenchfrogs,项目名称:framework,代码行数:32,代码来源:Inline.php

示例4: getCreate

 /**
  * Responds to requests to GET /books/create
  */
 public function getCreate()
 {
     $view = '<form method = "POST" action="/books/create">';
     $view .= csrf_field();
     $view .= '<input type="text" name="title">';
     $view .= '<input type="submit">';
     $view .= '</form>';
     return $view;
 }
开发者ID:JeanYSu,项目名称:foobooks,代码行数:12,代码来源:BookController.php

示例5: link_to_act

function link_to_act($action, $type, $body, $button_class = 'btn btn-primary')
{
    $csrf = csrf_field();
    return <<<EOT
        <form method="POST" action="{$action}" class="display:inline;">
         <input type='hidden' name='_method' value='{$type}'>
         {$csrf}
         <button type="submit" class="{$button_class}">{$body}</button>
EOT;
}
开发者ID:shegun-babs,项目名称:dakrush,代码行数:10,代码来源:Helpers.php

示例6: create

 /**
  * Show the form for creating a new resource.
  *
  * @return \Illuminate\Http\Response
  */
 public function create()
 {
     $view = '<form method="POST" action="/books/create">';
     $view .= csrf_field();
     # This will be explained more later
     $view .= '<label>Title: <input type="text" name="title"></label>';
     $view .= '<input type="submit">';
     $view .= '</form>';
     return $view;
 }
开发者ID:rebekahheacock,项目名称:foobooks,代码行数:15,代码来源:BookController.php

示例7: getFileupload

    public function getFileupload()
    {
        $postUrl = '/request/fileupload';
        $csrf_field = csrf_field();
        $html = <<<CREATE
            <form action="{$postUrl}" method="POST" enctype="multipart/form-data">
                {$csrf_field}
                <input type="file" name="file"/><br/><br/>
                <input type="submit" value="提交"/>
            </form>
CREATE;
        return $html;
    }
开发者ID:paullbyao,项目名称:learnlaravel5,代码行数:13,代码来源:RequestController.php

示例8: create

    public function create()
    {
        $postUrl = route('post.store');
        $csrf_field = csrf_field();
        $html = <<<CREATE
        <form action="{$postUrl}" method="POST">
            {$csrf_field}
            <input type="text" name="title"><br/><br/>
            <textarea name="content" cols="50" rows="5"></textarea><br/><br/>
            <input type="submit" value="提交"/>
        </form>
CREATE;
        return $html;
    }
开发者ID:Graychen,项目名称:quickstart_laravel,代码行数:14,代码来源:PostController.php

示例9: getFieldsHtml

 public function getFieldsHtml()
 {
     if ($this->_validator) {
         $messages = $this->_validator->messages();
     }
     $html = '';
     foreach ($this->_fields as $field) {
         $html .= $field->getHtml(isset($messages) ? $messages->get($field->getName()) : []);
     }
     if ($this->_token) {
         $html .= csrf_field();
     }
     return $html;
 }
开发者ID:artemBilik,项目名称:laraform,代码行数:14,代码来源:Form.php

示例10: index

 /**
  * Display a listing of the resource.
  *
  * @return \Illuminate\Http\Response
  */
 public function index()
 {
     $model = new TaskStatus();
     $dataGrid = DataGrid::make($model);
     $dataGrid->addColumn(DataGrid::textColumn('name', 'Status Name', ['sortable' => 'asc']));
     if (Gate::allows('hasPermission', [AdminUser::class, "setup.task-status.edit"])) {
         $dataGrid->addColumn(DataGrid::linkColumn('edit', 'Edit', function ($row) {
             return "<a href='" . route('setup.task-status.edit', $row->id) . "'>Edit</a>";
         }));
     }
     if (Gate::allows('hasPermission', [AdminUser::class, "setup.task-status.destroy"])) {
         $dataGrid->addColumn(DataGrid::linkColumn('destroy', 'Destroy', function ($row) {
             return "<form method='post' action='" . route('setup.task-status.destroy', $row->id) . "'>" . "<input type='hidden' name='_method' value='delete'/>" . csrf_field() . '<a href="#" onclick="jQuery(this).parents(\'form:first\').submit()">Destroy</a>' . "</form>";
         }));
     }
     return view('setup.task-status.index')->with('dataGrid', $dataGrid);
 }
开发者ID:mage2,项目名称:project-management-system,代码行数:22,代码来源:TaskStatusController.php

示例11: begin

 public static function begin($action = false, $method = false, array $options = array(), $enctype = false)
 {
     $html = '<form';
     if (!empty($action)) {
         $html .= " action='{$action}'";
     }
     if (!empty($method)) {
         $html .= " method='{$method}'";
     }
     if (!empty($enctype)) {
         $html .= "enctype='multipart/form-data'";
     }
     $html .= self::generateOption($options);
     $html .= '>';
     echo $html;
     echo csrf_field();
     return new ActiveForm();
 }
开发者ID:trongtri0705,项目名称:staff,代码行数:18,代码来源:ActiveForm.php

示例12: open

    /**
     * Open up a new HTML form.
     *
     * @param  array $options
     *
     * @return string
     */
    public static function open($options=[]){
        $method = array_get($options, 'method', 'post');
        $method = strtoupper($method);
        $options['method'] = ($method == 'POST' or in_array($method, self::$fake_methods)) ? 'POST' : 'GET';
        if (isset($options['files'])){
            if ($options['files']===true) {
                $options['enctype'] = 'multipart/form-data';
            }
            unset($options['files']);
        }

        if (!isset($options['action'])) {
            $options['action'] = Request::url();
        }
        $options['accept-charset'] = 'UTF-8';

        return '<form'.self::getHtmlParamsFromOptions($options).'>'.csrf_field().self::getAppendMethod($method);
    }
开发者ID:ananevam,项目名称:wavelaravel,代码行数:25,代码来源:FormBuilder.php

示例13: index

 /**
  * Display a listing of the resource.
  *
  * @return \Illuminate\Http\Response
  */
 public function index()
 {
     $role = new Role();
     $dataGrid = DataGrid::make($role);
     $dataGrid->addColumn(DataGrid::textColumn('name', 'Role Name'));
     $dataGrid->addColumn(DataGrid::textColumn('description', 'Role Description'));
     if (Gate::allows('hasPermission', [AdminUser::class, "admin.role.edit"])) {
         $dataGrid->addColumn(DataGrid::linkColumn('edit', 'Edit', function ($row) {
             return "<a href='" . route('admin.role.edit', $row->id) . "'>Edit</a>";
         }));
     }
     if (Gate::allows('hasPermission', [AdminUser::class, "admin.role.edit"])) {
         $dataGrid->addColumn(DataGrid::linkColumn('destroy', 'Destroy', function ($row) {
             return "<form method='post' action='" . route('admin.role.destroy', $row->id) . "'>" . "<input type='hidden' name='_method' value='delete'/>" . csrf_field() . '<a href="#" onclick="jQuery(this).parents(\'form:first\').submit()">Destroy</a>' . "</form>";
         }));
     }
     return view('admin.user.role.index')->with('dataGrid', $dataGrid);
 }
开发者ID:mage2,项目名称:laravel-ecommerce,代码行数:23,代码来源:RoleController.php

示例14: link_to

function link_to($body, $path, $type)
{
    $csrf = csrf_field();
    if (is_object($path)) {
        $action = '/' . $path->getTable();
        if (in_array($type, ['PUT', 'PATCH', 'DELETE'])) {
            $action .= '/' . $path->getKey();
        }
    } else {
        $action = $path;
    }
    return <<<EOT
    <form method="POST" action="{$action}">
        {$csrf}
        <input type="hidden" name="_method" value="{$type}">
        <button type="submit">{$body}</button>
    </form>
EOT;
}
开发者ID:ronaldvaneede,项目名称:laracasts-projectflyer-series,代码行数:19,代码来源:helpers.php

示例15: form_handle

function form_handle($body, $path, $type)
{
    $csrf = csrf_field();
    if (is_object($path)) {
        $action = '/' . $path->getTable();
        if (in_array($type, ['PUT', 'PATCH', 'DELETE'])) {
            $action .= '/' . $path->getKey();
        }
    } else {
        $action = $path;
    }
    return <<<EOT
\t\t<form method="POST" action="{$action}">
\t\t\t{$csrf}
\t\t\t<input type='hidden' name='_method' value="{$type}" />
\t\t\t<button type="submit">{$body}</button>
\t\t</form>
EOT;
}
开发者ID:svnblame,项目名称:trinketfinds,代码行数:19,代码来源:helpers.php


注:本文中的csrf_field函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。