Presets, adding to a plugin

From e107 Wiki
Jump to: navigation, search

e107 Wiki: English | Русский | Deutsch | Français | Magyar | Português | Български | Česky | Nederlands | Ελληνικά | Italiano | Norske | Polska | Slovenščina | Español | Svenska | Translate: Wiki | Page

logo_wiki.png

Current Release 1.0.4 | e107.org | Download | Changelog | Forum | Plugins | Themes | RSS Feed of Latest Changes | Atom Feed of Latest Changes


How to write a plugin
Main page > I : First Aid > II : Development > III : Administration > IV : How To's > V : Plugin Writing > VI : Theming & Shortcodes


Presets allow the admin to save a template of their form results - so each time they create a new entry their own default settings are used.

To add a preset to your admin config page, enter the following code, replacing the array values with your own.

Before require_once(e_ADMIN."auth.php") add:

Code: sample preset code
require_once(e_HANDLER."preset_class.php");
$pst = new e_preset;
$pst->form = array("myform"); // name of the form that will have it's values saved.
$pst->page = array("download.php?create"); // display preset options on which page(s).
$pst->id = array("admin_downloads"); // unique name(s) of the preset

After require_once(e_ADMIN."auth.php") add the following line:

Code: sample preset code
$pst->save_preset(); 

Before the tag add the following:

Code: sample preset code
$preset = $pst->read_preset("admin_downloads"); // read preset values into array
extract($preset); 

So, in the example above, the preset called "admin_downloads" is saved and extracted.

Please note that your form elements must have default values in the form of either $name or $_POST['name'].

<input type='text' name='myname' value='$myname' />

or

<input type='text' name='myname' value='".$_POST['myname']."' />