NAME
App::ZofCMS::Plugin::FormToDatabase - simple insertion of query into database
SYNOPSIS
In your Main Config file or ZofCMS template:
plugins => [ qw/FormToDatabase/ ],
plug_form_to_database => {
go_field => 'd|foo',
values => [ qw/one two/ ],
table => 'form',
dsn => "DBI:mysql:database=test;host=localhost",
user => 'test',
pass => 'test',
opt => { RaiseError => 1, AutoCommit => 0 },
},
DESCRIPTION
The module is a simple drop in to stick query into database. The module does not provide any parameter checking and is very basic. For anything more advanced check out App::ZofCMS::Plugin::DBI
This documentation assumes you have read App::ZofCMS, App::ZofCMS::Config and App::ZofCMS::Template
MAIN CONFIG FILE OR ZofCMS TEMPLATE FIRST LEVEL KEYS
plug_form_to_database => {
go_field => 'd|foo',
values => [ qw/one two/ ],
table => 'form',
dsn => "DBI:mysql:database=test;host=localhost",
user => 'test',
pass => 'test',
opt => { RaiseError => 1, AutoCommit => 0 },
},
Plugin uses the plug_form_to_database
first-level key in ZofCMS template or your main config file. The key takes a hashref as a value. Values set under this key in ZofCMS template will override values set in main config file. Possible keys/values are as follows.
go_field
go_field => 'd|foo',
Optional. Defaults to: d|form_to_database
. The go_field
key specifies the "go" to the plugin; in other words, if value referenced by the string set under go_field
key the plugin will proceed with stuffing your database, otherwise it will not do anything. Generally, you'd do some query checking with a plugin (e.g. App::ZofCMS::Plugin::FormChecker) with lower priority number (so it would be run first) and then set the value referenced by the go_field
.
The go_field
key takes a string as a value. The string is in format s|key_name
- where s
is the name of the "source". What follows the "source" letter is a pipe (|
) and then they name of the key. The special value of source q
(note that it is lowercase) means "query". That is q|foo
means, "query parameter 'foo'". Other values of the "source" will be looked for inside ZofCMS template hash, e.g. d|foo
means key foo
in ZofCMS template special first-level key {d}
- this is probably where you'd want to check that for.
Example:
# ZofCMS template:
plugins => [ qw/FormToDatabase/ ],
d => { foo => 1 },
plug_form_to_database => {
go_field => 'd|foo',
..... # omited for brevity
},
The example above will always stuff the query data into the database because key foo
under key d
is set to a true value and go_field
references that value with d|foo
.
values
values => [ qw/one two/ ],
Mandatory. The values
key takes an arrayref as a value. The elements of that arrayref represent the names of query parameters that you wish to stick into the database. Under the hood of the module the following is being called:
$dbh->do(
"INSERT INTO $conf{table} VALUES(" . join(q|, |, ('?')x@values) . ');',
undef,
@$query{ @values },
);
Where @values
contains values you passed via values
key and $dbh
is the database handle created by DBI
. If you want something more advanced consider using App::ZofCMS::Plugin::DBI
instead.
table
table => 'form',
Mandatory. Specifies the name of the table into which you wish to store the data.
dsn
dsn => "DBI:mysql:database=test;host=localhost",
Mandatory. Specifies the dsn to use in DBI connect call. See documentation for DBI and DBD::your_database
for proper syntax for this string.
user
user => 'test',
Mandatory. Specifies the user name (login) to use when connecting to the database.
pass
pass => 'test',
Mandatory. Specifies the password to use when connecting to the database.
opt
Optional. Specifies extra options to use in DBI's connect_cached()
call. Defaults to: { RaiseError => 1, AutoCommit => 0 }
SEE ALSO
REPOSITORY
Fork this module on GitHub: https://github.com/zoffixznet/App-ZofCMS
BUGS
To report bugs or request features, please use https://github.com/zoffixznet/App-ZofCMS/issues
If you can't access GitHub, you can email your request to bug-App-ZofCMS at rt.cpan.org
AUTHOR
Zoffix Znet <zoffix at cpan.org> (http://zoffix.com/, http://haslayout.net/)
LICENSE
You can use and distribute this module under the same terms as Perl itself. See the LICENSE
file included in this distribution for complete details.