phpBB

Development Wiki

Difference between revisions of "Function.add form key"

From phpBB Development Wiki

m
m
 
(4 intermediate revisions by 3 users not shown)
Line 3: Line 3:
 
==Description==
 
==Description==
 
#<pre>void add_form_key (String $form_name)</pre>
 
#<pre>void add_form_key (String $form_name)</pre>
This functions adds a secret token to any form, this token can be checked after submission with the [[Check_form_key|check_form_key]] function to ensure that the received data is the same as the submitted.
+
This functions adds a secret token to any form, a token which should be checked after submission with the [[Check_form_key|check_form_key]] function to ensure that the received data is the same as the submitted.
  
: <div class="toc" style="padding:10px;">'''Note''': This function expects that the {S_FORM_TOKEN} template variable is present in the template that is used for the selected page!</div>
+
: <div class="toc" style="padding:10px;">'''Note''': This function expects that the {S_FORM_TOKEN} template variable is present in the template file being used!</div>
  
 
==Parameters==
 
==Parameters==
Line 20: Line 20:
 
To add the form token you only have to call the function.
 
To add the form token you only have to call the function.
 
<php>$form_key = 'my_form';
 
<php>$form_key = 'my_form';
add_from_key($form_key);</php>
+
add_form_key($form_key);</php>
  
 
===Example #2 Usage with check_form_key===
 
===Example #2 Usage with check_form_key===
Line 37: Line 37:
 
[[Category:Functions]]
 
[[Category:Functions]]
  
[[ja:Add_form_key]]
+
[[ja:Function.add_form_key]]

Latest revision as of 05:14, 15 March 2010

add_form_key -- Add a secret token to the form.

Description

  1. void add_form_key (String $form_name)

This functions adds a secret token to any form, a token which should be checked after submission with the check_form_key function to ensure that the received data is the same as the submitted.

Note: This function expects that the {S_FORM_TOKEN} template variable is present in the template file being used!

Parameters

Parameter Usage
form_name The name of the form; has to match the name used in check_form_key, otherwise no restrictions apply.

Examples

Example #1 Add a form token

To add the form token you only have to call the function.

$form_key 'my_form';
add_form_key($form_key);

Example #2 Usage with check_form_key

Basic add_form_key usage with the check_form_key function.

$form_key 'my_form';
add_form_key($form_key);

if (!
check_form_key($form_key))
{
    
$errors[] = $user->lang['FORM_INVALID'];
}

See Also

check_form_key