Discussion on Form Class - AJAX, Validation, jQuery & Bootstrap


bitshape supports this item


10 comments found.

Not clear to me from your table.php example how to manage post of form to mysql DB via php.

I was expecting a simple way to specify the posting page called on form post success, for example:

$form = new form(‘myform’, ‘POST’, ‘myform_post.php’);

but there is no parameter to specify the page used to process the form POSTs.

Under if ($form->wasPosted()) {

...is there a simple way to pass the form array to another php page to process it? Such as:


This would make it very easy to understand and use for ‘non-programming’ people like me who primarily use forms to post data to a mysql table.

Hi there. the table.php example file does not deal with a Database table, it shows how to use the ‘

’ form layout.

You raise an important issue though. How do you make use of the form on multiple “pages”. I’m working on an example file that discusses this in the new version.

I actually did not realize that a lot of people don’t use a PHP Framework, which uses one single index.php file where you can easily put there form somewhere where it is accessible from multiple ‘pages’.

If you don’t have that, there is one neat solution. Create a forms directory somewhere in your websites directory. then in there, create a loginform.php file.

In the file, create your form: $form = new form(‘myform’, ‘POST’, ‘some_page.php’); //add some form elements

//then return the form return $form;

Now, in any of your other pages, you can include the form into a variable. //random_page.php $form = include(‘forms/loginform.php’);

Now of course, if you don’t use server-side validation, you can simply get your form values from the $_POST superglobal without needing access to the $form object you created.

To answer your question, is there a way to pass the form to another .php page?

Yes, one neat way is to serialize the form into the session. //start session, one time, ideally at the top of your script. session_start();

$_SESSION[‘form’] = serialize($form);

header(‘location: http://mysite.com/myform_post.php')

now, on that myform_post.php you can get the form by doing: $form = unserialize($_SESSION[‘form’]); //and remove it unset($_SESSION[‘form’]);

However, I will address these issues in detail on the next version which will be ready hopefully today or tomorrow.

I hope this helped, I literally just woke up so I’m a bit tired so excuse any spelling mistakes!

I’m releasing version 1.2.0 now which addresses your issue among other improvements.

I forgot to tell you, but I suppose you were notified by the 1.2 update. It addresses your issue. Look at examples/integration.php in 1.2.

Hope that helps, cheers.

There should be a demo. That seems to be the standard now. Tough to tell the “feel” of this w/o one…and there are so many other scripts that have them. I’m interested, but wouldn’t buy without confirmation from a demo.

I’ll see if I can’t get a demo up. Perhaps I’ll do a video as well.

I’m working on my new website (afflicto.net) it will have a demo very soon! :)

Demo is up! http://afflicto.net/demo/neatforms – I’ts being updated regularly and it’s almost done :) I’m releasing 1.3 as well soon.

Look fwd to demo

Yeah only the first two sections under ‘examples’ are actually available. The other ones don’t exist.

Huge update on the website. I changed it around a bit too, hopefully should be easier to navigate now as well. http://afflicto.net/demo/neatforms#intro

Version 1.3 has been uploaded & approved :)

Does this have csfr protection?

No, it doesn’t. I could and probably should implement that though.


I have your html layout utility, does this can be integrated into?

or I should use it separately?


This Form Class does not yet have csrf protection I’m sorry. I will implement this as soon as possible though!

thanks. its really important feature, i hope you will implement soon. best regards

You’re right, it is. I’ll try to implement it in the next few days :)

I have now added CSRF protection, expect an update within the next few days, sorry for the wait everyone!

Update is live, for those who didn’t get the notification.

If I could, I’d rate this 10 stars.

Awesome work man! Very, very nice to have in the tulebox (yeah, tulebox, see what I did there?) ..

I just wish you’d write some more libraries :-P

That’s a good idea. I originally wanted to implement something like this but forgot to.

I’m about to begin writing version 2.0, which will be re-written almost from scratch. It will address this issue among many other improvements.

Great man! If you ever need any help to get it out faster, let me know! I’m thinking about making a collection class for this though, extending the Element class, to be able to group up elements and deal with the scenario above..

Guess you never got to implement this? :-)

Request for feature: Right now I can only add html elements. It would be great if I could add tables, css, html just like I would add html element. I have lot of custom css I want to insert around my html elements and I am unable to do it.

You could probably add custom elements yourself. Just extend the abstract “afflicto\form\element” class and change it’s display, displayLabel and displayHelp methods and output what you want.

As far as css, you can set the style attribute of any element by doing: $form->username->attr(‘style’, ‘color: red;’);

Assuming the $form has a property ‘username’ which is some form element (afflicto\form\element).

You can of course add a css file to your website, then refer to the form by setting an id on your form.

$form->attr(“id”, “myform”);

Hope that helps.

Hi This may sounds like a stupid question, I would like to know if checking for username availability in mysql db for example is something I can do with your class? I see that your plugin has ajax method, is it possible to post data to another page and return values to your class?

No, that’s currently not possible. You can try and implement it though, add a validator in the ‘validators.php’ file and one in the ‘validators.js’ file.

The validators in php can take arguments, might work. You might need to do some other things too, depends on how flexible you’ll like it to be.

I have a nice idea on how to implement it, by giving the php neatform class access to your database via PDO.

Anyway, I don’t know when I’ll get to add this, sorry!

any idea on v2 release date?

I’ve been thinking about that lately. I’ll keep you updated.