https://github.com/melbahja/submy
Submy: JQuery Validation Forms and Ajax Submit Data
https://github.com/melbahja/submy
Last synced: 7 months ago
JSON representation
Submy: JQuery Validation Forms and Ajax Submit Data
- Host: GitHub
- URL: https://github.com/melbahja/submy
- Owner: melbahja
- License: gpl-3.0
- Created: 2017-01-02T23:02:30.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2017-01-07T20:54:14.000Z (almost 9 years ago)
- Last Synced: 2025-01-19T19:48:26.686Z (9 months ago)
- Language: JavaScript
- Size: 56.6 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Submy
Submy: JQuery Validation Forms and Ajax Submit Data# Get Started
- Download Submy.min.js
- Include JQuery and Submy in your page
- Include JQuery v2.1 or higher
- Start coding ... :)## Submy Init
```html
Submy - hello world
submit// $(selector).submy({ options });
$('#login').submy({
submitId: '#loginSubmit', // btn submit id
messageId: '#message', // respond message id
});
```
## Create Your Rules
There are two ways to write your own rules, either by `data-submy=' JSON Format '` in input or in the `options` object by `rules` , you can combine two, provided that there is no conflict of inputs names### Start Example
```html
UK
USA
submit
$('#startExpl').submy({
submitId: '#loginSubmit',
messageId: '#message',
ajax: {
url: 'http://site.com/sub.php',
method: 'POST',
//....
},
done: function(text, st, ob) {alert('done');
console.log(text, st, ob);
}
});
```### Example 2
```html
UK
USA
submit
$('#ex2').submy({
submitId: '#loginSubmit',
messageId: '#message',
fileUpload: true,
rules: {
fullname: {
required: true,
type: "text",
min: 4,
max: 30
},
useremail: {
required: "please add your email",
type: "email",
typeMessage: "please add valid email"
}
},
ajax: {
url: 'http://site.com/submit.php',
//method: 'POST', ajax default method is POST
//....
},
});
```#### submit.php
```php
type = 'danger'; // info , success ...
$res->message = 'email not exists';echo json_encode($res);
```
#### submit.php example 3
```php
alert("hi");';
echo 'test';```
## Submy Options
| Option | Type | Default | Description |
|------------|-------------------|--------------|-----------------------------------------------------------------------------------------------------|
| `submitId` | string | #submit | form submit btn id |
| `messageId` | string | #formMessage | form message id |
| `validOn` | string | submit | valid form on `submit` btn click or form `change` |
| `rules` | object | {} | inputs rules |
| `fileUpload` | boolean | false | file upload in form |
| `charset` | string | UTF-8 | form charset |
| `errConsole` | boolean | true | show submy error, warn , log |
| `showError` | array | [] | default show input error : [] after input , `['before', '#test']`, `['after', '#test']`, `['in', 'test']` |
| `jsonDone` | callback function | false | submy json done function |
| `done` | callback function | false | ajax done |## Submy Rules Options
| Options | Types | Default | Description |
|----------------|-------------------|-------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `required` | boolean or string | false , if true defualt is : this field is required , if type = file : please choose file | input/select/textarea/input file are required ? |
| `type` | string | input type attr | input content types : `file` , `text` , `email`, `url`, `number`, `username`, `checkbox`, `radio` . for validation (date types now not supported , next update Inchaallah in v1.2) |
| `typeMessage` | string | this field is not valid | type option error message |
| `min` | number | | minimum number if type = number , minimum length if type = text |
| `minMessage` | string | minimum length is: {{min}} | minimum number is: {{min}} | min option error message |
| `max` | number | maximum length is: {{max}} | maximum number is: {{max}} | maximum number if type = number , maximum length if type = text |
| `is` | array | [] | run submyIsFunctions : `["equal", "#xInput"]` : check this input value is === #xInput input value |
| `isEqual` | string | error in this field | is equal error message |
| `types` | array | ['*/*'] | determine file mime types ex : `['image/png', 'image/jpeg', 'image/gif']` |
| `typesMessage` | string | file type is not allowed | types options error message |
| `minSize` | number | | file minimum size by bytes |
| `minSizeMessage` | string | minimum file size is: {{min}} | minSize error message |
| `maxSize` | number | | max file size by bytes |
| `maxSizeMessage` | string | maximum file size is: {{max}} | maxSize error message |full documentation is coming
# Support & Bugs
Submit Bug reports on: mohamed@elbahja.me# License
Copyright © Mohamed Elbahja . [GPL-3.0](https://github.com/melbahja/submy/blob/master/LICENSE)