How to submit a form with both optional and required fields to the database.Mysqli and php

I have created a form(Survey form) in php and javascript & mysqli database. The form has many optional and required fields with conditions to hide and show some when checked. But when i submit the form it does not submit and requires me to fill all the fields including the ones i i have not checked.How can i make it submit only the fields i have filled?.

It looks like you have optional fields marked as required. So you would need to remove that from the optional fields.

But is there a way i can force the data to be submitted any?

Because i have nested if statements

That depends on your HTML code.

Which code is refusing to submit the form? That is, is the HTML refusing to submit it, or is the PHP code rejecting it because of missing answers?

If you mark fields as required, even if they are not visible because of some JS code to hide them, they’ll still need to be filled in. Could you remove the “required” flag in JS when you hide the fields?

Ok,it worked when i removed

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.