Build hidden fields

How to use the build_hidden_fields() function.

Submitted by harmlessgoat22 on 26 Apr 2008, 02:25

Build hidden fields

Introduction
If you have an HTML form you may have some fields that you want to send. For this there are hidden input fields, that look like this:
Code: Select all
<input type="hidden" name="field_name" value="The field value" />

phpBB3 offers a function to create a list of hidden fields easily by passing an associative array. The function is called build_hidden_fields() and it can be found in [var]includes/functions.php[/url].

How to use it
Usage is extremely simple, you simply pass an array, like so:
Code: Select all
build_hidden_fields(array(
   'name1'     => 'Value of name1',
   'name2'     => 'Value of name2',
));


That alone doesn't do very much though, it needs to be assigned as a template variable. So you do:
Code: Select all
$template->assign_vars(array(
   'S_HIDDEN_FIELDS'   => build_hidden_fields(array(
      'name1'     => 'Value of name1',
      'name2'     => 'Value of name2',
   )),
));

So, now you can use {S_HIDDEN_FIELDS} in your template. It's usually added directly before the submit button.

How to use it with confirm_box()
phpBB also has a confirm_box() function, which is used to display a confirm box (surprise!). This function takes a $s_hidden_fields argument, so you can pass your hidden fields to it. Here is an example:
Code: Select all
confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array(
   'page'   => $page,
   'action'   => 'delete',
)));


Summary
As you can tell, build_hidden_fields() is a very simple yet useful function built into phpBB 3.0.

As ends every article of mine, if you have any questions, ask in the forums, if anything is unclear, PM me and I will update the article.
 

Changelog:

by igorw on 26 Apr 2008, 14:37: Rewritten a bit

License:

All articles in the knowledge base are licensed under the phpbbmodders beerware-nc license.

Back to category


Knowledge Base index