Form Validation

Feels free to drop any suggestions of what should be put in to the next release of SLiMS.

Moderators: wynerst, buitenzorg812, purwoko, sutriadi, ido, Dicarve, ridorido

Post Reply
Annu
Posts: 36
Joined: 12 Oct 2012, 14:38
Location: Islamabad
Contact:

Form Validation

Post by Annu » 31 Jan 2013, 11:43

I need to validate text and numeric fields in various forms in different modules. Can any body help how to add validation @simbio classes

User avatar
buitenzorg812
Posts: 830
Joined: 20 Sep 2011, 14:18
Location: Jakarta, Indonesia
Contact:

Re: Form Validation

Post by buitenzorg812 » 31 Jan 2013, 17:33

is it possible to change validation through mysql? i mean, field which has to be text set as text and so on.

Annu
Posts: 36
Joined: 12 Oct 2012, 14:38
Location: Islamabad
Contact:

Re: Form Validation

Post by Annu » 01 Feb 2013, 13:42

buitenzorg812 wrote:is it possible to change validation through mysql? i mean, field which has to be text set as text and so on.
Field types in MySQL is already set but I need to validate the form on Submit. How can I do this. I've gone through validate.js that contains some functions regarding isNumber and others field types. How to use them I don't know. So please help me in this regard.

Annu
Posts: 36
Joined: 12 Oct 2012, 14:38
Location: Islamabad
Contact:

Re: Form Validation

Post by Annu » 18 Feb 2013, 12:55

Annu wrote:
buitenzorg812 wrote:is it possible to change validation through mysql? i mean, field which has to be text set as text and so on.
Field types in MySQL is already set but I need to validate the form on Submit. How can I do this. I've gone through validate.js that contains some functions regarding isNumber and others field types. How to use them I don't know. So please help me in this regard.
Done through Code

User avatar
buitenzorg812
Posts: 830
Joined: 20 Sep 2011, 14:18
Location: Jakarta, Indonesia
Contact:

Re: Form Validation

Post by buitenzorg812 » 20 Feb 2013, 16:19

Annu wrote:Done through Code
great news then :). if you have time, please share with us here how you manage to handle the problem. at least in later time, someone with similar matter can learn from your point of view. thank you verymuch, annu :).

Annu
Posts: 36
Joined: 12 Oct 2012, 14:38
Location: Islamabad
Contact:

Re: Form Validation

Post by Annu » 21 Feb 2013, 15:15

We can have many validation checks Right After the given code

Code: Select all

    $title = trim(strip_tags($_POST['title']));
+    $edition = trim($dbs->escape_string(strip_tags($_POST['edition'])));

Code: Select all

    // check form validity
    if (empty($title)) {
        utility::jsAlert(__('Title can not be empty'));
        exit();
    }
As I want to check the Edition Field as Numeric so after the above code add the following code and thats it

Code: Select all

if (!is_numeric($edition))
	{
       	utility::jsAlert(__('Please Enter Numeric Value for Edition'));
		$edition.focus();
	    exit();
	}

Post Reply