function page()
{
    global $db, $session;
    //lets get a user
    $user = $db->from('users')->where('id', 1);
    $formOptions = array('action' => $_SERVER['PHP_SELF'], 'id' => 'testForm', 'data' => $user, 'files' => true, 'class' => 'form-horizontal', 'sidebar' => true, 'title' => '', 'description' => '');
    $form = new Form($formOptions, $session);
    $sidebar = array('class' => 'warning', 'title' => 'Be careful!', 'body' => 'Be sure you complete all fields');
    $form->setSidebar($sidebar);
    $emailValidation = array('required' => 'true', 'error' => 'Please supply a valid email address');
    $email = array('field' => 'email', 'label' => "Email", 'description' => '', 'validation' => $emailValidation);
    $form->email($email);
    $firstNameValidation = array();
    $firstName = array('field' => 'firstname', 'label' => "First Name", 'description' => '', 'validation' => $firstNameValidation);
    $form->text($firstName);
    $lastName = array('field' => 'lastname', 'label' => "Last Name", 'description' => 'Fill in your last name');
    $form->text($lastName);
    $taName = array('field' => 'descriptionField', 'label' => "Last Name", 'description' => 'Fill in your last name');
    $form->textarea($taName);
    $phoneOptions = array('field' => 'phone', 'label' => "Phone", 'description' => 'Home Phone');
    $form->phone($phoneOptions);
    $checkOptions = array('field' => 'checkTest', 'label' => "Check here", 'description' => 'You authorize everything');
    $form->checkbox($checkOptions);
    $passwordValidation = array('pattern' => '(?=^.{6,}$)((?=.*\\d)|(?=.*\\W+))(?![.\\n])(?=.*[A-Z])(?=.*[a-z]).*$');
    $passwordOptions = array('field' => 'password', 'label' => "Password", 'description' => 'Enter a password at least 6 characters, with at least one symbol and number.', 'validation' => $passwordValidation);
    $form->password($passwordOptions);
    /*
        $dateValidation = array('disabledDays'=>'0,1','disabledDates'=>array("11/23/2015", "12/25/2015"), 'minDate'=>'11/1/2015', 'maxDate'=>'1/30/2016');
        $secondDateValidation = array('disabledDays'=>'0,1','disabledDates'=>array("11/23/2015", "12/25/2015"), 'minDate'=>'11/1/2015', 'maxDate'=>'1/30/2016');
        $dateOptions = array('field'=>'startdate', 'label'=>'Start/Stop Dates', 'description' =>'Enter a start  and stop date', 'validation' => $dateValidation,
            'second_field'=>'enddate',  'second_validation' => $secondDateValidation );
        $form->date($dateOptions);
    
        $timeValidation = array('stepping'=>5,'disabledDays'=>'0,1','disabledDates'=>array("11/23/2015", "12/25/2015"), 'minDate'=>'11/1/2015', 'maxDate'=>'1/30/2016');
        $secondTimeValidation = array('disabledDays'=>'0,1','disabledDates'=>array("11/23/2015", "12/25/2015"), 'minDate'=>'11/1/2015', 'maxDate'=>'1/30/2016');
        $dateOptions = array('field'=>'starttime', 'label'=>'Start/Stop Times', 'description' =>'Enter a start  and stop time', 'validation' => $timeValidation,
            'second_field'=>'endtime',  'second_validation' => $secondTimeValidation );
        $form->time($dateOptions);
    */
    $timeValidation = array('stepping' => 5, 'disabledDays' => '0,1', 'disabledDates' => array("11/23/2015", "12/25/2015"), 'minDate' => '11/1/2015', 'maxDate' => '1/30/2016');
    $secondTimeValidation = array('stepping' => 5, 'disabledDays' => '0,1', 'disabledDates' => array("11/23/2015", "12/25/2015"), 'minDate' => '11/1/2015', 'maxDate' => '1/30/2016');
    $dateOptions = array('field' => 'startdatetime', 'label' => 'Start/Stop Date Times', 'description' => 'Enter a start  and stop date time', 'validation' => $timeValidation, 'second_field' => 'enddatetime', 'second_validation' => $secondTimeValidation);
    $form->datetime($dateOptions);
    $options = array('field' => 'department', 'options' => array(0 => 'Advertising', 1 => "Circulation", 2 => 'Production'), 'label' => 'Department', 'description' => 'Select your department');
    $form->select($options);
    $options = array('field' => 'publications', 'url' => '/ajax/forms/publications.php', 'label' => 'Publication', 'description' => 'Select a publication');
    $form->remoteSelect($options);
    $form->generate();
    //var_dump($this->formScripts);
    //grab any form scripts and append them to the global scripts array
    $GLOBALS['scripts'] = array_merge($GLOBALS['scripts'], $form->formScripts);
}
Example #2
0
 /**
  * Creates an article edit form.
  *
  * @fixme Should be integrated into a template.
  *
  * @param User $user User object, used to show the proper connection links for publications.
  * @return string The form HTML.
  */
 public function form($hidden = false)
 {
     $user = Core::getUser();
     $start = date("d-m-Y H:i", $this->start ? strtotime($this->start) : time());
     $end = date("d-m-Y H:i", $this->end ? strtotime($this->end) : time());
     $class = $hidden ? "hidden" : "";
     $content = Form::open("eventForm_" . $this->id, Config::$kikiPrefix . "/json/event.php", 'POST', $class, "multipart/form-data");
     $content .= Form::hidden("eventId", $this->id);
     $content .= Form::hidden("albumId", $this->albumId);
     $content .= Form::text("cname", $this->cname, "URL name");
     $content .= Form::text("title", $this->title, "Title");
     $content .= Form::datetime("start", $start, "Start");
     $content .= Form::datetime("end", $end, "End");
     $content .= Form::textarea("description", htmlspecialchars($this->description), "Description");
     $content .= Form::text("location", $this->location, "Location");
     $content .= Form::checkbox("featured", $this->featured, "Featured");
     $content .= Form::checkbox("visible", $this->visible, "Visible");
     $this->loadPublications();
     $content .= "<label>Publications</label>";
     foreach ($this->publications as $publication) {
         $content .= "<a href=\"" . $publication->url() . "\" class=\"button\"><span class=\"buttonImg " . $publication->service() . "\"></span>" . $publication->service() . "</a>\n";
     }
     // TODO: Make this generic, difference with social update is the check
     // against an already stored external URL.
     foreach ($user->connections() as $connection) {
         if ($connection->serviceName() == 'Facebook') {
             // TODO: inform user that, and why, these are required.
             if (!$connection->hasPerm('publish_stream')) {
                 continue;
             }
             if (!$connection->hasPerm('create_event')) {
                 continue;
             }
             $content .= Form::checkbox("connections[" . $connection->uniqId() . "]", false, $connection->serviceName(), $connection->name());
         } else {
             if ($connection->serviceName() == 'Twitter') {
                 $content .= Form::checkbox("connections[" . $connection->uniqId() . "]", false, $connection->serviceName(), $connection->name());
                 $content .= Form::text("hashtags", $this->hashtags, "Hashtags");
             }
         }
     }
     $content .= Form::button("submit", "submit", "Opslaan");
     $content .= Form::close();
     return $content;
 }
Example #3
0
 /**
  * Creates an article edit form.
  *
  * @fixme Should be integrated into a template.
  * @todo Traditional Page class is deprecated so we can now remove the $type argument hack and have a Page/Article class both deriving from Post.
  *
  * @param User $user User object, used to show the proper connection links for publications.
  * @param boolean $hidden Hide the form initially.
  * @param string $type Defaults to 'articles'. When set to 'page', form treats this article as a page.
  *
  * @return string The form HTML.
  *
  */
 public function form($hidden = false, $type = 'articles')
 {
     $user = Core::getUser();
     $date = date("d-m-Y H:i", $this->ctime ? strtotime($this->ctime) : time());
     $class = $hidden ? "hidden" : "";
     $sections = array();
     if ($type == 'pages') {
         $sections[0] = 'top-level page';
     }
     $db = Core::getDb();
     $q = $db->buildQuery("select id,title from sections where type='%s' order by title asc", $type);
     $rs = $db->query($q);
     if ($rs && $db->numRows($rs)) {
         while ($oSection = $db->fetchObject($rs)) {
             $sections[$oSection->id] = $oSection->title;
         }
     }
     $content = Form::open("articleForm_" . $this->id, Config::$kikiPrefix . "/json/article.php", 'POST', $class, "multipart/form-data");
     $content .= Form::hidden("articleId", $this->id);
     $content .= Form::hidden("albumId", $this->albumId);
     $content .= Form::select("sectionId", $sections, "Section", $this->sectionId);
     $this->loadPublications();
     $content .= Form::text("title", $this->title, "Title");
     if (!count($this->publications)) {
         $content .= Form::text("cname", $this->cname, "URL name");
     }
     if ($type != 'pages') {
         $content .= Form::datetime("ctime", $date, "Date");
     }
     $class = Config::$clEditor ? "cleditor" : null;
     $content .= Form::textarea("body", preg_replace('~\\r?\\n~', '&#010;', htmlspecialchars($this->body)), "Body", null, 0, $class);
     if ($type != 'pages') {
         $content .= Form::checkbox("featured", $this->featured, "Featured");
     }
     $content .= Form::checkbox("visible", $this->visible, "Visible");
     $content .= "<label>Publications</label>";
     foreach ($this->publications as $publication) {
         $content .= "<a href=\"" . $publication->url() . "\" class=\"button\"><span class=\"buttonImg " . $publication->service() . "\"></span>" . $publication->service() . "</a>\n";
     }
     // TODO: Make this generic, difference with social update is the check
     // against an already stored external URL.
     foreach ($user->connections() as $connection) {
         if ($connection->serviceName() == 'Facebook') {
             // TODO: inform user that, and why, these are required.
             if (!$connection->hasPerm('publish_stream')) {
                 continue;
             }
             $content .= Form::checkbox("connections[" . $connection->uniqId() . "]", false, $connection->serviceName(), $connection->name());
         } else {
             if ($connection->serviceName() == 'Twitter') {
                 $content .= Form::checkbox("connections[" . $connection->uniqId() . "]", false, $connection->serviceName(), $connection->name());
                 $content .= Form::text("hashtags", $this->hashtags, "Hashtags");
             }
         }
     }
     $content .= Form::button("submit", "submit", "Opslaan");
     $content .= Form::close();
     return $content;
 }