本文整理汇总了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>';
}
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}
示例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();
}
示例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);
}
示例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);
}
示例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;
}
示例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;
}