exit;
}
// Namespaces to use
use PFBC\Form;
use PFBC\Element;
use PFBC\Validation;
// If form is submitted and correct
if (!empty($_POST) && Form::isValid("assignExaminator", false)) {
    $uid = findUser($_POST['username']);
    // Get current Course
    $course = $user->getCourse($cid);
    if ($uid == -1) {
        Form::setError('assignExaminator', 'Error: Unable to find that user.');
        header("Location: ?view=assignexaminator&cid={$cid}");
        exit;
    } else {
        Form::clearValues('assignExaminator');
    }
    // Add user to examinators
    $course->addExaminator($uid);
    echo '<h3>Success!</h3><a href="?view=course&cid=' . $cid . '"><button class="btn btn-success">Go back</button></a>';
} else {
    $form = new Form("assignExaminator");
    $form->configure(array("action" => "?view=assignexaminator&cid={$cid}"));
    $form->addElement(new Element\HTML('<legend>Assign new examinator</legend>'));
    $form->addElement(new Element\Hidden("form", "assignExaminator"));
    $form->addElement(new Element\Textbox('Username:'******'username', array('validation' => new Validation\RegExp('/^[a-z\\d]{2,64}$/', 'Error: The %element% field must contain a username.'), 'required' => 1, 'longDesc' => 'This user will be added as an examinator to the course')));
    $form->addElement(new Element\Button("Add user"));
    $form->addElement(new Element\Button("Cancel", "button", array("onclick" => "history.go(-1);")));
    $form->render();
}
Example #2
0
$form->addElement(new Element_Button("Login"));
$form->addElement(new Element_Button("Cancel", "button", array(
    "onclick" => "history.go(-1);"
)));
$form->render();');
?>

	</div>
</div>

<?php 
use PFBC\Form;
use PFBC\Element;
$form = new Form("login");
$form->configure(array("prevent" => array("bootstrap", "jQuery", "focus")));
$form->addElement(new Element\HTML('<legend>Login</legend>'));
$form->addElement(new Element\Hidden("form", "login"));
$form->addElement(new Element\Email("Email Address:", "Email", array("required" => 1)));
$form->addElement(new Element\Password("Password:"******"Password", array("required" => 1)));
$form->addElement(new Element\Checkbox("", "Remember", array("1" => "Remember me")));
$form->addElement(new Element\Button("Login"));
$form->addElement(new Element\Button("Cancel", "button", array("onclick" => "history.go(-1);")));
$form->render();
?>

<p><strong>Line 2:</strong> PFBC uses PHP sessions in the validation process, so you'll need to ensure you have session_start(); in your 
webpage - before outputting anything to the browser.  If you forget, you'll be reminded by an error message displayed above your form.</p>

<p><strong>Lines 4-5:</strong> As previously mentioned, PFBC <?php 
echo $version;
?>
use PFBC\Form;
use PFBC\Element;
use PFBC\Validation;
// If form is submitted and correct
if (!empty($_POST) && Form::isValid("selectProjectsToReview")) {
    // Add reviewer to all selected projects
    foreach ($_POST['projects'] as $key => $value) {
        try {
            $project = $course->getProject($value);
            $project->addFeasibleReviewer($GLOBALS['user']->id);
        } catch (Exception $e) {
            // Do nothing, quietly continue
        }
    }
    echo '<h3>Success!</h3><a href="?view=course&cid=' . $cid . '"><button class="btn btn-success">Go back</button></a>';
} else {
    // Add all projects
    $projects = array();
    foreach ($course->getProject(null, false) as $key => $value) {
        $project = $course->getProject($value);
        $projects[$value] = $project->subject;
    }
    $form = new Form("selectProjectsToReview");
    $form->configure(array("action" => "?view=selectprojects&cid={$cid}"));
    $form->addElement(new Element\HTML('<legend>Select projects</legend>'));
    $form->addElement(new Element\Hidden("form", "selectProjectsToReview"));
    $form->addElement(new Element\Checkbox("Projects I can review:", "projects", $projects));
    $form->addElement(new Element\Button("Send"));
    $form->addElement(new Element\Button("Cancel", "button", array("onclick" => "history.go(-1);")));
    $form->render();
}
<p>PFBC has support for 32 form elements: Button, Captcha, Checkbox, Checksort, CKEditor, 
Color, Country, Date, DateTimeLocal, DateTime, Email, File, Hidden, HTML, jQueryUIDate, Month,
Number, Password, Phone, Radio, Range, Search, Select, Sort, State, Textarea, Textbox, Time,
TinyMCE, Url, Week, YesNo.</p>

<p><span class="label label-important">Important</span> In each of the example forms provided, you'll
notice that the form's prevent property is set to an array containing "bootstrap" and "jQuery".  This prevents
the css/js include files from being loaded a second time by PFBC as they're already being included in a header
file.  If your system already includes jQuery or bootstrap, it's recommended that you edit the prevent
property in PFBC/Form.php so you don't have to set it (the prevent property) each time you create a form.</p>

<?php 
$options = array("Option #1", "Option #2", "Option #3");
$form = new Form("form-elements");
$form->configure(array("prevent" => array("bootstrap", "jQuery")));
$form->addElement(new Element\Hidden("form", "form-elements"));
$form->addElement(new Element\HTML('<legend>Standard</legend>'));
$form->addElement(new Element\Textbox("Textbox:", "Textbox"));
$form->addElement(new Element\Password("Password:"******"Password"));
$form->addElement(new Element\File("File:", "File"));
$form->addElement(new Element\Textarea("Textarea:", "Textarea"));
$form->addElement(new Element\Select("Select:", "Select", $options));
$form->addElement(new Element\Radio("Radio Buttons:", "RadioButtons", $options));
$form->addElement(new Element\Checkbox("Checkboxes:", "Checkboxes", $options));
$form->addElement(new Element\HTML('<legend>HTML5</legend>'));
$form->addElement(new Element\Phone("Phone:", "Phone"));
$form->addElement(new Element\Search("Search:", "Search"));
$form->addElement(new Element\Url("Url:", "Url"));
$form->addElement(new Element\Email("Email:", "Email"));
$form->addElement(new Element\Date("Date:", "Date"));
$form->addElement(new Element\DateTime("DateTime:", "DateTime"));
    $subject = $_POST['subject'];
    $deadline = new DateTime($_POST['deadline'] . ' ' . $_POST['deadlineTime']);
    $stage = intval($_POST['stage']);
    // Create Project
    $project = Project::createProject($subject, $deadline, $stage, $cid);
    // Add the project to the course
    $course->addProject($project->id);
    // Add the student to the project
    //$project->addStudent($uid);
    // Add a submission to the Project
    $project->createSubmission();
    echo '<h3>Success!</h3><a href="?view=course&cid=' . $cid . '"><button class="btn btn-success">Go back</button></a>';
} else {
    $form = new Form('createProject');
    $form->configure(array('action' => "?view=createproject&cid={$cid}"));
    $form->addElement(new Element\HTML('<legend>Create new project</legend>'));
    $form->addElement(new Element\Hidden('form', 'createProject'));
    $form->addElement(new Element\Textbox('Subject:', 'subject', array('validation' => new Validation\RegExp('/^[\\p{L} ]{2,64}$/', 'Error: The %element% field must contain only characters and whitespaces and be between 2 and 64 characters.'), 'required' => 1)));
    $form->addElement(new Element\Select('Stage:', 'stage', $stages, array('validation' => new Validation\RegExp('/^[1-5]{1}$/', 'Error: The %element% field is not valid.'), 'required' => 1, 'longDesc' => 'Starting stage of the project')));
    /*  $form->addElement(new Element\Textbox('Student:', 'student', array(
        //TODO The regex should use defined constants to more easily adapt
        //TODO a better regex should be implemented depending on acronym
        'validation' => new Validation\RegExp('/^[a-z\d]{2,64}$/', 'Error: The %element% field must contain a username.'),
        'required' => 1,
        'longDesc' => 'Assign a student to this project with it\'s acronym'
      )));*/
    $form->addElement(new Element\Date('Deadline:', 'deadline', array('required' => 1, 'longDesc' => 'Select a deadline for this project')));
    $form->addElement(new Element\Time('Time:', 'deadlineTime', array('required' => 1, 'longDesc' => 'Select a time for the deadline')));
    $form->addElement(new Element\Button('Create'));
    $form->addElement(new Element\Button('Cancel', 'button', array('onclick' => 'history.go(-1);')));
    $form->render();
	/*Validation errors have been found.  We now need to redirect back to the 
	script where your form exists so the errors can be corrected and the form
	re-submitted.*/
}');
?>

	</div>
</div>	

<p>PFBC supports 9 types of validation rules: AlphaNumeric, Captcha, Date, Email, MaxLength, Numeric, RegExp, Required, and Url.  Here's
how they are applied to elements.</p>

<?php 
$form = new Form("validation");
$form->configure(array("prevent" => array("bootstrap", "jQuery")));
$form->addElement(new Element\Hidden("form", "validation"));
$form->addElement(new Element\Textbox("Require:", "Required", array("required" => 1, "longDesc" => "The required property provides a shortcut for applying the Required class to the element's\n\tvalidation property.  If supported, the HTML5 required attribute will also provide client-side validation.")));
$form->addElement(new Element\Textbox("Max Length:", "MaxLength", array("maxlength" => 10, "shortDesc" => "maximum of 10 characters allowed", "longDesc" => "The maxlength property provides a shortcut for applying the MaxLength class to the element's\n\tvalidation property.  It will also add the maxlength attribute for client-side validation.")));
$form->addElement(new Element\Textbox("Regular Expression:", "RegularExpression", array("validation" => new Validation\RegExp("/pfbc/", "Error: The %element% field must contain following keyword - \"pfbc\"."), "longDesc" => "The RegExp validation class provides the means to apply custom validation to an element.  Its constructor \n\tincludes two parameters: the regular expression pattern to test and the error message to display if the pattern is not matched.")));
$form->addElement(new Element\Email("Email:", "Email", array("longDesc" => "The Email element applies the Email validation rule by default.  If supported, HTML5\n\tvalidation will also be provided client-side.")));
$form->addElement(new Element\Number("Numeric:", "Numeric", array("longDesc" => "The Number element applies the Numeric validation rule by default.  If supported, HTML5\n\tvalidation will also be provided client-side.")));
$form->addElement(new Element\Url("Url:", "Url", array("longDesc" => "The Url element applies the Url validation rule by default.  If supported, HTML5\n\tvalidation will also be provided client-side.")));
$form->addElement(new Element\Date("Date:", "Date", array("longDesc" => "The Date element applies the RegExp validation rule by default - ensuring the following date format YYYY-MM-DD\n\tis adhered to.")));
$form->addElement(new Element\jQueryUIDate("", "Date2", array("longDesc" => "The jQueryUIDate element applies the Date validation rule by default - ensuring the submitted value satisfies \n\t<a href=\"http://us3.php.net/manual/en/datetime.construct.php\">PHP's DateTime class constructor</a>.")));
$form->addElement(new Element\Textbox("AlphaNumeric:", "AlphaNumberic", array("validation" => new Validation\AlphaNumeric(), "longDesc" => "The AlphaNumeric validation class will verify that the element's submitted value contains only letters, \n\tnumbers, underscores, and/or hyphens.")));
$form->addElement(new Element\Captcha("Captcha:", array("longDesc" => "The Captcha element applies the Captcha validation, which uses <a href=\"http://www.google.com/recaptcha\">\n\treCaptcha's anti-bot service</a> to reduce spam submissions.")));
$form->addElement(new Element\Email("Multiple Rules:", "Email2", array("validation" => new Validation\RegExp("/.*@gmail.com\$/", "Error: The %element% field must contain a Gmail address."), "longDesc" => "Multiple validation rules can be attached to an element by passing the validation property an array of validation \n\tclass instances.  This Email element also applies the RegExp validation rule to ensure the supplied email address is from Gmail.")));
$form->addElement(new Element\Button());
$form->addElement(new Element\Button("Cancel", "button", array("onclick" => "history.go(-1);")));
$form->render();
?>
Example #7
0
	<h1>Ajax</h1>
</div>

<p>PFBC provides several properties and methods for facilitating ajax submissions.  To get started, you'll first need to set the ajax property in
the form's configure method.  The ajaxCallback property can also be included in the configure method if you'd like a javascript function to called
after the form's data has been submitted.  In the example below a callback function has been set to extract the latitude/longitude information from a
json response.</p>

<p>The validation process for an ajax submission also differs slightly from that of a standard submission.  If the form's isValid method 
returns false, you will need to invoke the renderAjaxErrorResponse method, which returns a json response containing the appropriate error messages.  
These errors will then be displayed in the form so the user can correct and resubmit.</p>

<?php 
$form = new Form("ajax");
$form->configure(array("prevent" => array("bootstrap", "jQuery"), "ajax" => 1, "ajaxCallback" => "parseJSONResponse"));
$form->addElement(new Element\Hidden("form", "ajax"));
$form->addElement(new Element\HTML('<legend>Using the Google Geocoding API</legend>'));
$form->addElement(new Element\Textbox("Address:", "Address", array("required" => 1)));
$form->addElement(new Element\HTML('<div id="GoogleGeocodeAPIReaponse" style="display: none;">'));
$form->addElement(new Element\Textbox("Latitude/Longitude:", "LatitudeLongitude", array("readonly" => "")));
$form->addElement(new Element\HTML('</div>'));
$form->addElement(new Element\Button("Geocode", "submit", array("icon" => "search")));
$form->render();
?>

<script type="text/javascript">
	function parseJSONResponse(latlng) {
		var form = document.getElementById("ajax");
		if(latlng.status == "OK") {
			var result = latlng.results[0];
			form.LatitudeLongitude.value = result.geometry.location.lat + ', ' + result.geometry.location.lng;
Example #8
0
	"required" => 1
)));
$form->addElement(new Element_Checkbox("", "Remember", array(
	"1" => "Remember me"
)));
$form->addElement(new Element_Button("Login"));
$form->render();');
?>

	</div>
</div>

<?php 
$form = new Form("search");
$form->configure(array("prevent" => array("bootstrap", "jQuery", "focus"), "view" => new View\Search()));
$form->addElement(new Element\Hidden("form", "search"));
$form->addElement(new Element\HTML('<legend>Search</legend>'));
$form->addElement(new Element\Search("", "Search", array("placeholder" => "Search", "append" => '<button class="btn btn-primary">Go</button>')));
$form->render();
?>

<ul class="nav nav-tabs">
	<li class="active"><a href="#php53-4" data-toggle="tab">PFBC <?php 
echo $version;
?>
 (PHP 5 >= 5.3.0)</a></li>
	<li><a href="#php5-4" data-toggle="tab">PFBC <?php 
echo $version;
?>
 (PHP 5)</a></li>
</ul>
Example #9
0
$version = file_get_contents("../version");
?>

<div class="page-header">
	<h1>HTML5</h1>
</div>

<p>PFBC has support for 13 HTML5 form elements: Phone, Search, Url, Email, DateTime, Date, 
Month, Week, Time, DateTimeLocal, Number, Range, and Color.  Each of these fallback to textboxes
in the event that the HTML5 input type isn't supported in the user's web browser.  HTML5 attributes
can also be applied to elements for client-side validation.</p>

<?php 
$form = new Form("html5");
$form->configure(array("prevent" => array("bootstrap", "jQuery")));
$form->addElement(new Element\Hidden("form", "html5"));
$form->addElement(new Element\HTML('<legend>Attributes</legend>'));
$form->addElement(new Element\Textbox("Required Attribute:", "Required", array("required" => 1, "shortDesc" => "Highlights field in red when focussed")));
$form->addElement(new Element\Textbox("Placeholder Attribute:", "Placeholder", array("placeholder" => "my placeholder", "shortDesc" => "Provides example or hint", "longDesc" => "The form's labelToPlaceholder property can be used to convert each element's \n\tlabel to its placeholder.  This strategy keeps your php source cleaner when building forms.  \n\tCheck out the <a href=\"views.php\">Vertical View</a> example to see the labelToPlaceholder \n\tproperty in action.")));
$form->addElement(new Element\Textbox("Pattern Attributes:", "Pattern", array("pattern" => "^pfbc.*", "title" => "Must start with \"pfbc\"", "shortDesc" => "Provides native, client-side validation", "longDesc" => "This input's pattern attribute is set to the following regular expression: ^pfbc.*")));
$form->addElement(new Element\HTML('<legend>Elements</legend>'));
$form->addElement(new Element\Phone("Phone:", "Phone"));
$form->addElement(new Element\Search("Search:", "Search"));
$form->addElement(new Element\Url("Url:", "Url"));
$form->addElement(new Element\Email("Email:", "Email"));
$form->addElement(new Element\DateTime("DateTime:", "DateTime"));
$form->addElement(new Element\Date("Date:", "Date"));
$form->addElement(new Element\Month("Month:", "Month"));
$form->addElement(new Element\Week("Week:", "Week"));
$form->addElement(new Element\Time("Time:", "Time"));
$form->addElement(new Element\DateTimeLocal("DateTime-Local:", "DateTimeLocal"));
}
if ($login->isUserLoggedIn() === false) {
    exit(1);
}
// Test permissions
if (!$user->hasPrivilege("canCreateCourse")) {
    header("Location: ?view=accessdenied");
    exit;
}
// Namespaces to use
use PFBC\Form;
use PFBC\Element;
use PFBC\Validation;
// If form is submitted and correct
if (!empty($_POST) && Form::isValid("createCourse")) {
    $course = Course::createCourse($_POST['name']);
    // Add the course to this user
    $user->addCourse($course->id);
    // Add current user as admin
    $course->addAdmin($_SESSION['user_id']);
    echo '<h3>Success!</h3><a href="?"><button class="btn btn-success">Go back</button></a>';
} else {
    $form = new Form("createCourse");
    $form->configure(array("action" => "?view=createcourse"));
    $form->addElement(new Element\HTML('<legend>Create new course</legend>'));
    $form->addElement(new Element\Hidden("form", "createCourse"));
    $form->addElement(new Element\Textbox("Name:", "name", array("validation" => new Validation\RegExp("/^[\\d\\p{L} ]{2,64}\$/", "Error: The %element% field must contain only characters, numbers and whitespaces and be between 2 and 64 characters."), "required" => 1, "longDesc" => "Name of the course")));
    $form->addElement(new Element\Button("Create"));
    $form->addElement(new Element\Button("Cancel", "button", array("onclick" => "history.go(-1);")));
    $form->render();
}