peddel Posted September 19, 2008 Share Posted September 19, 2008 Well i got this form that has a variable amount of fields depending on what the user did in previous forms. Thing is i now want to submit this form ONLY when all fields are filled in. Is there a way to check all available form fields one by one without knowing the exact ID/name of that field. So i can run trough the fields and just check if its filled or not, as long as its not filled i send a false. When all fields are filled ill send a true. I used some php to scroll trough the cells to send the info to some variables using this code, maybe there's some code existing in javascript that does the same? foreach ($_POST as $fld => $val) { unset($_SESSION[$fld]); $_SESSION[$fld] = $val; } Link to comment https://forums.phpfreaks.com/topic/124910-solved-running-trough-form-fields-without-knowing-name-of-the-fields-in-advance/ Share on other sites More sharing options...
JasonLewis Posted September 19, 2008 Share Posted September 19, 2008 If you give your form tag an ID, like so: <form id="form1" method="post" action=""> Then you can use some javascript like so: function checkFields(){ var fields = document.getElementById("form1").elements; for(var i = 0; i < fields.length; i++){ if(fields[i].value == ''){ return false; } } return true; } Link to comment https://forums.phpfreaks.com/topic/124910-solved-running-trough-form-fields-without-knowing-name-of-the-fields-in-advance/#findComment-645436 Share on other sites More sharing options...
peddel Posted September 19, 2008 Author Share Posted September 19, 2008 Thx for solving my problem =) Link to comment https://forums.phpfreaks.com/topic/124910-solved-running-trough-form-fields-without-knowing-name-of-the-fields-in-advance/#findComment-645441 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.