validation is working when i click submit but the form is also adding when error show
See original GitHub issuewhen i click the button the error messages are showing but its also adding empty values to database.
<script>
$(document)
.ready(function() {
$('.ui.form').form({
inline: true,
on: 'blur',
fields: {
code: {
identifier : 'code',
rules: [
{
type : 'empty',
prompt : 'Please enter course code'
}
]
},
section: {
identifier : 'section',
rules: [
{
type : 'empty',
prompt : 'Please enter section'
},
{
type : 'integer',
prompt : 'Please enter integer number'
}
]
},
coursename: {
identifier : 'coursename',
rules: [
{
type : 'empty',
prompt : 'Please enter coursename'
}
]
},
totalduration: {
identifier : 'totalduration',
rules: [
{
type : 'empty',
prompt : 'Please enter totalduration'
},
{
type : 'integer',
prompt : 'Please enter integer number'
}
]
}
}
})
});
</script>
this part is ajax part of buttons onclick
$("#savecourse").on("click", function() {
var code = $("#code").val();
var section = $("#section").val();
var coursename = $("#coursename").val();
var totalduration = $("#totalduration").val();
$.ajax({
type: "POST",
url: "course_add.php",
data: ({coursecode:code,coursesection:section,ccoursename:coursename,duration:totalduration}),
success: function(data) {
window.alert("course added successfully.");
window.location.reload(true);
}
});
});
and this part is the form.
<form class="ui form">
<div class="two fields">
<div class="field">
<label>Course Code</label>
<input name="code" id="code" type="text">
</div>
<div class="field">
<label>Section</label>
<input name="section" id="section" type="text" >
</div>
</div>
<div class="two fields">
<div class="field">
<label>Course Name</label>
<input name="coursename" id="coursename" type="text" >
</div>
<div class="field">
<label>Total Duration</label>
<input name="totalduration" id="totalduration" type="text">
</div>
</div>
<button class="ui submit button" id="savecourse">Save Course</button>
<div class="ui error message"></div>
</form>
i tried making div the buttons but doesnt change anything.
Issue Analytics
- State:
- Created 7 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Form Validation Works But Still Submits When User Input The ...
My problem is that the validation works fine: Users get an alert that the phone number they provided has been used but my...
Read more >Client-side form validation - Learn web development | MDN
Before submitting data to the server, it is important to ensure all required form controls are filled out, in the correct format. This...
Read more >Building a template-driven form - Angular
This tutorial shows you how to create a template-driven form. The control elements in the form are bound to data properties that have...
Read more >Validation message not restricting form from submitting
When user is on interface corresponding to link 1 i.e. he clicks on link Form 1 and he clicks on Submit button without...
Read more >Handling Validation Errors in Forms - Up Your A11y
Approach 1: Provide a clear list of errors when 'submit' is clicked · Perform validation on all inputs when the button is clicked...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hi @cemezgn,
You can do something like that in your click event:
The following is a standard reply.
Thank you for posting, but although it’s a valid usage question, we’ve limited GitHub Issues to bug reports and feature requests, keeping the board more manageable for maintainers; see the contributing guidelines for more information on what kind of posts should find themselves into the GitHub Issues board.
To get answers or feedback that might allow you to repost this issue, please use one of our other support resources:
The problem is caused by your “click” event on the button. It’s not validating anything; it’s just grabbing all the form’s values and sending them using AJAX.
You can check the validity of the form’s values by using the behaviors described in the documentation: http://semantic-ui.com/behaviors/form.html#/settings