{"comment":{"url":"https://api.github.com/repos/Hyurl/jsLib/comments/14804858","html_url":"https://github.com/Hyurl/jsLib/commit/d2fb1e3b07c48a00c0431b17a18e2e3837adaedf#commitcomment-14804858","id":14804858,"user":{"login":"Hyurl","id":16103955,"avatar_url":"https://avatars.githubusercontent.com/u/16103955?v=3","gravatar_id":"","url":"https://api.github.com/users/Hyurl","html_url":"https://github.com/Hyurl","followers_url":"https://api.github.com/users/Hyurl/followers","following_url":"https://api.github.com/users/Hyurl/following{/other_user}","gists_url":"https://api.github.com/users/Hyurl/gists{/gist_id}","starred_url":"https://api.github.com/users/Hyurl/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Hyurl/subscriptions","organizations_url":"https://api.github.com/users/Hyurl/orgs","repos_url":"https://api.github.com/users/Hyurl/repos","events_url":"https://api.github.com/users/Hyurl/events{/privacy}","received_events_url":"https://api.github.com/users/Hyurl/received_events","type":"User","site_admin":false},"position":null,"line":null,"path":"","commit_id":"d2fb1e3b07c48a00c0431b17a18e2e3837adaedf","created_at":"2015-12-05T18:03:31Z","updated_at":"2015-12-05T18:03:31Z","body":"The multiple submitting example, a good one:\r\nThe HTML being this:\r\n<form id=\"example-form\">\r\n    <fieldset class=\"group-data\">\r\n        <input type=\"text\" name=\"name\" placeholder=\"Please input a name!\" />\r\n    </fieldset>\r\n    <fieldset class=\"group-data\">\r\n        <input type=\"text\" name=\"name\" placeholder=\"Please input a name!\" />\r\n    </fieldset>\r\n</form>\r\n\r\nJs being this:\r\n$(function(){\r\n    $('#example-form').ajaxSubmit(\r\n        function(){\r\n            for(var i=0;i<$('input[name=\"name\"]').length;i++){\r\n                if($('input[name=\"name\"]').eq(i).val()==''){\r\n\t\t    alert('Please input a name!');\r\n\t\t    $('input[name=\"name\"]').eq(i).focus();\r\n\t\t    return false;\r\n\t\t}\r\n           }\r\n       },\r\n       function(msg){\r\n           alert('Successfully submit '+msg+' pieces of data!');\r\n       }\r\n    );\r\n});\r\n\r\nPHP being this:\r\n<?php\r\n$name=isset($_POST['name']) ? $_POST['name'] : '';\r\necho $name!='' ? 1 : 0;\r\n?>\r\n\r\nFinally, the result would be \"Successfully submit 2 pieces of data!\".\r\nIf you add an addition property of bool \"true\" into ajaxSubmit() very after function(msg), and set your function(msg){ alert(msg) }, simultaneously set your php echoing as \"The name submitted is $name.\", you will get two alerting messages that shows two different names being submitted.\r\nHowever, if you just wanna submit only one group of data, you don't have to set a tag that named <fieldset> which has a class of \"group-data\", ‘cause you will get a same result without one.\r\nA warm tip, ajax doesn't submit files, so if you wanna submit a file like a picture, you don't use this function, otherwise, the file would not be submitted.\r\n Another one, if you use <fieldset class=\"group-data\"> in your multiple submitting form, you just submit a multiple data form, that means any other input element in this form without such a tag and/or class would not be submitted, neither.\r\nFor deeply knowing the usage, please check the function itself by yourself carefully."}}