 |
 |
 |
 |

Properties Manager Examples
Conventions used in this document:
- Any text that is in this font is considered code, a literal value, the name of a file, folder, MySQL table, MySQL field, or a value in a MySQL field.
- Any text that is surrounded by angle brackets like <this> means that you should substitute it for your own value.
Example: vconsole/modules/<module>/ means that you should substitute <module> for your own value like invoices for the Manage Invoices module.
- Any text that is surrounded by square brackets like [this] means that it is optional.
Example: check_email($email, $error[, $dnscheck]); means that [, $dnscheck] is optional
- When you see ... in the code font, this means that you can add 1 or more items at that point. Do not actually include ... in your code.
Code Examples. In the examples below, we will give the user a properties interface and then do something with the data.
Example 1. Adding a record using a propertiesmanager formatted action file.
<?php
$pm = array(
array(
'title' => 'New Record',
'image' => 'document_add',
'info' => 'You are adding a record',
),
array(
'tab' => 'General',
'instructions' => 'Fill out the form below',
'fields' => array(
array(
'type' => 'text',
'name' => 'name',
'label' => 'Name',
'labelpos' => 'before',
'pack' => 'nextrow',
'help' => 'Enter a name',
'fielddata' => array(
'attributes' => array(
'size' => 50
)
),
'validate' => array(
'required' => true,
'minlength' => 5,
'maxlength' => 50,
'type' => 'text'
)
),
array(
'type' => 'textarea',
'name' => 'desc',
'label' => 'Description',
'labelpos' => 'before',
'pack' => 'nextrow',
'help' => 'Enter a description',
'fielddata' => array(
'attributes' => array(
'cols' => 50,
'rows' => 5
)
),
'validate' => array(
'required' => true,
'minlength' => 5,
'maxlength' => 255,
'type' => 'text'
)
)
)
),
array(
'tab' => 'Confirmation',
'instructions' => 'Confirm your action',
'fields' => array(
array(
'type' => 'checkbox',
'name' => 'confirm',
'label' => 'Check this box to confirm your action',
'labelpos' => 'after',
'pack' => 'nextrow',
'help' => 'You must check this box to continue.',
'fielddata' => array(
'value' => 1
),
'validate' => array(
'required' => true,
'failmsg' => 'You must check the box to continue.',
)
)
)
)
);
$data = propertiesmanager($pm);
if (is_array($data)) {
$id = db_query( "INSERT INTO `table1` SET
`name` = " . db_quote($data[ 'name']) . ",
`description` = " . db_quote($data[ 'desc']), $dbr);
searchindex($_SESSION[ 'module'], $id);
set_message( 'success', 'The new record was created');
print $OUT[ 'messages'] . "<<>>updateDataTable();";
exit;
} else {
print "<<>>wmdivClose()";
exit;
}
?>
Example 2. Defining calendar events using a propertiesmanager formatted action file.
<?php
$pm = array(
array(
'title' => 'Add Events',
'image' => 'document_add',
'info' => 'You are adding calendar events',
),
array(
'tab' => 'Events',
'instructions' => 'Fill out the form below',
'fields' => array(
array(
'type' => 'choicebuilder',
'name' => 'events',
'label' => 'Events',
'pack' => 'nextrow',
'help' => 'Add up to 10 events here.',
'fielddata' => array(
'defchoices' => 1,
'minchoices' => 1,
'maxchoices' => 10,
'fields' => array(
array(
'type' => 'calendartime',
'name' => 'start',
'label' => 'Event Start',
'labelpos' => 'before',
'validate' => array(
'required' => true
)
),
array(
'type' => 'calendartime',
'name' => 'end',
'label' => 'Event End',
'labelpos' => 'before',
'validate' => array(
'required' => true,
)
),
array(
'type' => 'text',
'name' => 'name',
'label' => 'Event Name',
'labelpos' => 'before',
'validate' => array(
'required' => true,
'maxlength' => 100,
'type' => 'text'
)
)
)
)
)
)
)
);
$data = propertiesmanager($pm);
if (is_array($data)) {
for ($i=1;$i<=$data[ 'events'];$i++) {
$id = db_query( "INSERT INTO `calendar` SET
`start` = " . db_quote($data[ 'start_'.$i]) . ",
`end` = " . db_quote($data[ 'end_'.$i) . ",
`name` = " . db_quote($data[ 'name_'.$i), $dbr);
searchindex($_SESSION[ 'module'], $id);
}
set_message( 'success', $data[ 'events'] . ' new events were entered.');
print $OUT[ 'messages'] . "<<>>updateDataTable();";
exit;
} else {
print "<<>>wmdivClose()";
exit;
}
?>
NEXT: VConsole PHP Reference
COMMENTS There are no comments at this time.
|
|
 |
 |
 |
|