File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -547,6 +547,21 @@ function csrf_hash()
547547
548548//--------------------------------------------------------------------
549549
550+ if (! function_exists ('csrf_field ' ))
551+ {
552+ /**
553+ * Generates a hidden input field for use within manually generated forms.
554+ *
555+ * @return string
556+ */
557+ function csrf_field ()
558+ {
559+ return '<input type="hidden" name=" ' . csrf_token () .'" value=" ' . csrf_hash () .'"> ' ;
560+ }
561+ }
562+
563+ //--------------------------------------------------------------------
564+
550565if (! function_exists ('force_https ' ))
551566{
552567 /**
Original file line number Diff line number Diff line change @@ -137,6 +137,15 @@ Miscellaneous Functions
137137
138138 Returns the current CSRF hash value.
139139
140+ .. php :function :: csrf_field ()
141+
142+ :returns: A string with the HTML for hidden input with all required CSRF information.
143+ :rtype: string
144+
145+ Returns a hidden input with the CSRF information already inserted:
146+
147+ <input type="hidden" name="{csrf_token}" value="{csrf_hash}">
148+
140149.. php :function :: force_https ( $duration = 31536000 [, $request = null [, $response = null]] )
141150
142151 :param int $duration: The number of seconds browsers should convert links to this resource to HTTPS.
Original file line number Diff line number Diff line change @@ -57,6 +57,12 @@ and ``csrf_hash()`` functions
5757
5858 <input type="hidden" name="<?= csrf_token() ?>" value="<?= csrf_hash() ?>" />
5959
60+ Additionally, you can use the ``csrf_field() `` method to generate this
61+ hidden input field for you::
62+
63+ // Generates: <input type="hidden" name="{csrf_token}" value="{csrf_hash}" />
64+ <?= csrf_field() ?>
65+
6066Tokens may be either regenerated on every submission (default) or
6167kept the same throughout the life of the CSRF cookie. The default
6268regeneration of tokens provides stricter security, but may result
You can’t perform that action at this time.
0 commit comments