Skip to Content
NFSFU234FormValidation v3 is here — file upload validation, config-driven rules, and more.
v3 (current)getFormDetails

getFormDetails

Reads every field’s current value from a form - inputs, textareas, selects, checkboxes, and radios - keyed by field name (falling back to data-attr-name where name isn’t set). Returns: false \| ErrorMessageInterface \| Record<string, string \| boolean>

ParameterTypeRequiredDefaultDescription
form`string \HTMLFormElement \HTMLDivElement`required
Usage
Example: Retrieve Form Details
const formDetails = nfsfu234FormValidation.getFormDetails('myFormId'); console.log("Form Details: ", formDetails);
Example Form HTML
<form id="myFormId"> <input type="text" name="fieldName1" value="value1" data-attr-name="fieldName1" /> <input type="text" name="fieldName2" value="value2" data-attr-name="fieldName2" /> <input type="checkbox" name="checkboxName" checked data-attr-name="checkboxName" /> <input type="radio" name="radioName" data-attr-name="radioName" /> <textarea name="textareaName" data-attr-name="textareaName">Sample text</textarea> <select name="selectName" data-attr-name="selectName"> <option value="option1" selected>Option 1</option> <option value="option2">Option 2</option> </select> </form>
JavaScript to Retrieve Form Details
const formDetails = nfsfu234FormValidation.getFormDetails('myFormId'); console.log("Form Details: ", formDetails);
Sample Output
{ "fieldName1": "value1", "fieldName2": "value2", "checkboxName": true, "radioName": false, "textareaName": "Sample text", "selectName": "option1" }

Note: If you call the function without having either the 'name' or the 'data-attr-name' attribute, then the key values will be index number of arrays. Find the example below:

Sample Output Without adding the 'name' or the 'data-attr-name' HTML Attribute
{ 0: "value1", 1: "value2", 2: true, 3: false, 4: "Sample text", 5: "option1" }
Last updated on