mosbth / cform Goto Github PK
View Code? Open in Web Editor NEWA PHP-class to create, render and validate submitted HTML-forms.
Home Page: http://dbwebb.se/cform
License: GNU General Public License v3.0
A PHP-class to create, render and validate submitted HTML-forms.
Home Page: http://dbwebb.se/cform
License: GNU General Public License v3.0
If a user would input harmful code there is no check for it.
At https://github.com/mosbth/cform/blob/v2/src/HTMLForm/CForm.php#L182
If a form element is required a * is added to it. Enable to skip the *.
This method is rather complex, reengineer it, move parts of creating the resulting HTML into each subclass to ease testing and development.
Write som how-to-use-guide in english.
Add tests to make it easier to do regression test and to ease development of each form element by getting a simple way of testing each element.
Enable CForm to be installed using composer.
Make a testfile displaying how HTML5 form elements are supported.
Verify that file upload works.
Implement a check to avoid CSRF attacks by storing a key in session.
List CForm on packagist.
Update code to be as PSR-2.
This is what I get when using a rule that does not exist ->
Fatal error: Class 'Mos\HTMLForm\Exception' not found in /var/www/kmom4/vendor/mos/cform/src/HTMLForm/CFormElement.php on line 351
Looks like the Exception class is not in the right namespace. Expected error and namespace should be like below.
// CFormElement.php line 350
if (!isset($tests[$rule])) {
throw new \Exception("Validation of form element failed, no such validation rule exists: $rule");
}
I changed Exception() to \Exception() and it should now work.
Add on some unittest with phpunit, to get going.
Its currently not possible to have more than one form per page.
Add namespaces and require PHP 5.4.
Use buildsystem travis.
When using CForm without a session, error messages will appear. Improve by either make a control in the constructor that the session is started, or silently fail for session features.
I look at the v2 branch since this seems to be served using composer.
I try to validate a form without any callback specified. This will never return true because lines 563-566 in CForm::check(..) always yield $ret = $callbackStatus
which defaults to null ( see line 415).
The following (see code example) therefor never enters the success block.
$status = $form->check();
if ($status === true) {...
success: redirect...
} else if($status===false){...
}
I suggest to change the initialization in line 415 from
$callbackStatus = null;
to
$callbackStatus = true;
which gives the expected behavior.
same as in the guide http://dbwebb.se/kunskap/anvand-cform-tillsammans-med-anax-mvc
but without callbacks,
class FormsController extends CApplicationBasic {
public function indexAction() {
$form = $this->di->get('form');
$form = $form->create([], [
'name' => [
'type' => 'text',
'label' => 'Name of contact person:',
'required' => true,
'validation' => ['not_empty'],
],
'email' => [
'type' => 'text',
'required' => true,
'validation' => ['not_empty', 'email_adress'],
],
'phone' => [
'type' => 'text',
'required' => true,
'validation' => ['not_empty', 'numeric'],
],
'submit' => [
'type' => 'submit',
],
'submit-fail' => [
'type' => 'submit',
],
]);
// Check the status of the form
$status = $form->check();
if ($status === true) {
// What to do if the form was submitted?
$form->AddOUtput("<p><i>Form was submitted and the callback method returned true.</i></p>");
$this->redirectTo('');
} else if ($status === false) {
// What to do when form could not be processed?
$form->AddOutput("<p><i>Form was submitted and the Check() method returned false.</i></p>");
}
$this->di->theme->setTitle("Test the Form");
$this->di->views->add('default/content', [
'content' => $form->getHTML()
]);
}
}
Error is:
Classfile 'CLydia' does not exists.
#0 [internal function]: myAutoloader('CLydia')
#1 [internal function]: spl_autoload_call('CLydia')
#2 /apache2/htdocs/dataDB/vendor/mos/cform/src/HTMLForm/CFormElement.php(37): is_callable('CLydia::Instanc...')
Line 37 in CFormElement and the _construct()
public function __construct($name, $attributes = [])
{
$this->attributes = $attributes;
$this['name'] = $name;
//$this['key'] = $name;
//$this['name'] = isset($this['name']) ? $this['name'] : $name;
// Use character encoding from lydia if available, else use UTF-8 OBSOLETE, remove this.
if (is_callable('CLydia::Instance()')) {
$this->characterEncoding = CLydia::Instance()->config['character_encoding'];
} else {
$this->characterEncoding = 'UTF-8';
}
}
Do not save input of type password in the session.
Integrate with scrutinizer and use code coverage.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.