VSource Web Solutions About Us  |  News  |  Contact Info  |  Network  |  Policies  |  Login  |  Support  |  Forum  |  (866) 346-9327


Online Demo



   
 
Search Documentation Search Documentation
 
   

Properties Manager Examples

   
 
Table Of Contents - Collapse

NEXT: VConsole PHP Reference
 
   

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',
  ),
  // General Tab
  array(
    'tab' => 'General',
    'instructions' => 'Fill out the form below',
    'fields' => array(
      // Name field
      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'
        )
      ),
      // Description Field
      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'
        )
      )
    )
  ),
  // Confirmation Tab
  array(
    'tab' => 'Confirmation',
    'instructions' => 'Confirm your action',
    'fields' => array(
      // Confirmation Checkbox
      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)) { // We got data
  // Insert the data
  $id = db_query("INSERT INTO `table1` SET
    `name` = " . db_quote($data['name']) . ",
    `description` = " . db_quote($data['desc']), $dbr);
 
  // Index the record for searches
  searchindex($_SESSION['module'], $id);
 
  // Set a message for the user
  set_message('success', 'The new record was created');
 
  // OK, now output the message to
  // the user and update the data table.
  print $OUT['messages'] . "<<>>updateDataTable();";
  exit;
 
} else {
  // User pressed the cancel button
  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',
  ),
  // Events Tab
  array(
    'tab' => 'Events',
    'instructions' => 'Fill out the form below',
    'fields' => array(
      // Choicebuilder Field
      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(
            // Start Date / Time
            array(
              'type' => 'calendartime',
              'name' => 'start',
              'label' => 'Event Start',
              'labelpos' => 'before',
              'validate' => array(
                'required' => true
              )
            ),
            // End Date / Time
            array(
              'type' => 'calendartime',
              'name' => 'end',
              'label' => 'Event End',
              'labelpos' => 'before',
              'validate' => array(
                'required' => true,
              )
            ),
            // Name
            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)) { // We got 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);

    // Index the record for searches
    searchindex($_SESSION['module'], $id);
  }
 
  // Set a message for the user
  set_message('success', $data['events'] . ' new events were entered.');
 
  // OK, now output the message to
  // the user and update the data table.
  print $OUT['messages'] . "<<>>updateDataTable();";
  exit;
 
} else {
  // User pressed the cancel button
  print "<<>>wmdivClose()";
  exit;
}
?>

NEXT: VConsole PHP Reference


COMMENTS
 

There are no comments at this time.

Post Your Comment
 
Your Name*
Your Email Address* (Not Shown)
Your Comment (HTML OK)*
Enter the characters that you see here
Get New Image
*required fields