I have added Custom Form in Content Editor and it does work adds new item to the list but I'm just not finding a way how to add validation to the form.
This is the HTML INPUT
<p><label>First Name* <input name="firstname" id="firstname" type="text" required></label></p>
<p><label>Last Name* <input name="lastname" id="lastname" type="text" required></label></p>
<p><label>Phone* <input name="phone" id="phone" type="text" required></label></p>
<p><label>Email* <input name="email" id="email" type="email" placeholder="[email protected]" required></label></p>
<p><label> <input name="checkbox" id="checkbox" type="checkbox">Use all entry</label></p>
<p><button onClick="save(); return false;">Save</button></p>
This is JQUERY/JAVASCRIPT
<script type="text/javascript">
function save() {
var siteUrl = 'https://sharepoint.com/';
var fname = $('#firstname').val();
var lname = $('#lastname').val();
var phone = $('#phone').val();
var email = $('#email').val();
var clientContext = new SP.ClientContext(siteUrl);
var oList = clientContext.get_web().get_lists().getByTitle('Information');
var itemCreateInfo = new SP.ListItemCreationInformation();
this.oListItem = oList.addItem(itemCreateInfo);
oListItem.set_item('Title', firstname);
oListItem.set_item('LastName', lastname)
oListItem.set_item('Phone', phone);
oListItem.set_item('Email', email);
oListItem.update();
clientContext.load(oListItem);
clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));
}
function onQuerySucceeded()
{
alert('The user was created successfully');
}
//This is clearing out the values of employee fields if the checkbox is not checked
var checkEmp = $('#checkbox').val();
if(checkEmp == false){
$('#firstname').val('');
$('#lastname').val('');
$('#phone').val('');
$('#email').val('');
}
function onQueryFailed(sender, args)
{
alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
}
</script>