Form validation for dynamic PHP formsValidate decimal numbers in JavaScript - IsNumeric()How to validate an email address in JavaScript?How can I prevent SQL injection in PHP?How to validate an email address using a regular expression?Deleting an element from an array in PHPHow do you parse and process HTML/XML in PHP?Reference — What does this symbol mean in PHP?What's the proper value for a checked attribute of an HTML checkbox?How does PHP 'foreach' actually work?Why shouldn't I use mysql_* functions in PHP?

Using a found spellbook as a Sorcerer-Wizard multiclass

Trapping Rain Water

Do simulator games use a realistic trajectory to get into orbit?

Arriving at the same result with the opposite hypotheses

What's up with this leaf?

Find the Factorial From the Given Prime Relationship

Compiling c files on ubuntu and using the executable on Windows

How can I most clearly write a homebrew item that affects the ground below its radius after the initial explosion it creates?

How Can I Tell The Difference Between Unmarked Sugar and Stevia?

If you had a giant cutting disc 60 miles diameter and rotated it 1000 rps, would the edge be traveling faster than light?

Why only the fundamental frequency component is said to give useful power?

Soft question: Examples where lack of mathematical rigour cause security breaches?

What's the largest optical telescope mirror ever put in space?

Can a black dragonborn's acid breath weapon destroy objects?

Was there a priest on the Titanic who stayed on the ship giving confession to as many as he could?

Where does "0 packages can be updated." come from?

How to officially communicate to a non-responsive colleague?

Movie about a boy who was born old and grew young

Russian equivalents of "no love lost"

What risks are there when you clear your cookies instead of logging off?

Frame failure sudden death?

How do I write "Show, Don't Tell" as a person with Asperger Syndrome?

How to chain Python function calls so the behaviour is as follows

Is it a problem if <h4>, <h5> and <h6> are smaller than regular text?



Form validation for dynamic PHP forms


Validate decimal numbers in JavaScript - IsNumeric()How to validate an email address in JavaScript?How can I prevent SQL injection in PHP?How to validate an email address using a regular expression?Deleting an element from an array in PHPHow do you parse and process HTML/XML in PHP?Reference — What does this symbol mean in PHP?What's the proper value for a checked attribute of an HTML checkbox?How does PHP 'foreach' actually work?Why shouldn't I use mysql_* functions in PHP?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








0















I'm creating a dynamic form that asks users to pick certain dates and tag a weight to that specific date. The user is free to add up to 12 inputs using a new row button.



I need to validate that form and make sure the user doesnt select the same date input from the select box and that the weight inputs across all added date inputs total to 100. Im not sure what to use for the validation part.



So far, I can only make sure the forms are not empty when attempting to submit.



Here is my html and JS code for the dynamic form



HTML:




<form method="post" action="viewInventory.php" id="insert_form">
<div class="col-lg-12">
<div class="panel panel-default">
<div class="panel-body">
<div class="table-repsonsive">
<table class="table table-borderless" id="item_table">
<tr>
<th>Month</th><br>
<th>Weight</th>
</tr>
<tr>
<input class = 'form-control' type = 'hidden' name = 'example' value = 8>
<td><select name="month[]" class="form-control item_unit" required><option value="" disabled>Select Product</option><option value="01">January</option><option value="02">February</option><option value="03">March</option><option value="04">April</option><option value="05">May</option><option value="06">June</option><option value="07">July</option><option value="08">August</option><option value="09">September</option><option value="10">October</option><option value="11">November</option><option value="12">December</option></select></td>
<td><input type="number" name="weight[]" class="form-control item_name" required /></td>
<td><button type="button" name="add" class="btn btn-success btn-sm add">+</button></td>
</tr>
</table>
</div>
</div>
</div>
</div>

<div class="col-lg-12">
<div align="center">
<a href="#confirm" data-target="#confirm" data-toggle="modal"><button type="button" class="btn btn-success">Submit</button></a>
</div>
</div>

<!-- // modal -->
<div id="confirm" class="modal fade" role="dialog">
<div class="modal-dialog">
<div class="modal-content">

<div class="modal-header">
<h4>Notice</h4>
<button type="button" class="close" data-dismiss="modal">&times;</button>
</div>

<div class="modal-body">
<div class="text-center">
<p>
<h6>Confirm Job Order?</h6>

</p>
</div>
<div class="modal-footer">
<input type="submit" id="submit" name="choose" class="btn btn-success" value="Continue" />
<button type="button" class="btn btn-default btn-outline-secondary" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
</div>

</form>


And my JS:



<script type="text/javascript">
$(document).ready(function()

$(document).on('click', '.add', function()
var html = '';
html += '<tr>';
html += '<td><select name="month[]" class="form-control item_unit"><option value="">Select Month</option><option value="01">January</option><option value="02">February</option><option value="03">March</option><option value="04">April</option><option value="05">May</option><option value="06">June</option><option value="07">July</option><option value="08">August</option><option value="09">September</option><option value="10">October</option><option value="11">November</option><option value="12">December</option></select></td>';
html += '<td><input type="number" name="weight[]" class="form-control item_name" required /></td>';
html += '<td><button type="button" name="remove" class="btn btn-danger btn-sm remove">x</button></td></tr>';
$('#item_table').append(html);
);

$(document).on('click', '.remove', function()
$(this).closest('tr').remove();
);

);
</script>


The user shouldn't be able to continue unless the total weights equal to 100 and if there are no duplicate entries in the selection boxes.










share|improve this question

















  • 1





    Which part specifically has you stuck? Are you performing the validation in JavaScript, PHP, or both? Are you asking how to read the values from your select elements? What did you try and how did it not work?

    – David
    Mar 24 at 16:33











  • @David its the reading of elements + the validation. I'm not sure what i should use for this. Maybe Jquery or JS. Sorry, I'm really clueless on what i need to do

    – Gabby Cervantes
    Mar 24 at 16:35











  • We can appreciate that you're finding it overwhelming, but it's important to keep questions here specific. If the first thing you're looking to do is read the values with jQuery, then start with a jQuery selector for your elements. Something like: $('select[name="month[]"]') This should select your select elements. You can loop over the results, examine the values, perform your logic, etc.

    – David
    Mar 24 at 16:42

















0















I'm creating a dynamic form that asks users to pick certain dates and tag a weight to that specific date. The user is free to add up to 12 inputs using a new row button.



I need to validate that form and make sure the user doesnt select the same date input from the select box and that the weight inputs across all added date inputs total to 100. Im not sure what to use for the validation part.



So far, I can only make sure the forms are not empty when attempting to submit.



Here is my html and JS code for the dynamic form



HTML:




<form method="post" action="viewInventory.php" id="insert_form">
<div class="col-lg-12">
<div class="panel panel-default">
<div class="panel-body">
<div class="table-repsonsive">
<table class="table table-borderless" id="item_table">
<tr>
<th>Month</th><br>
<th>Weight</th>
</tr>
<tr>
<input class = 'form-control' type = 'hidden' name = 'example' value = 8>
<td><select name="month[]" class="form-control item_unit" required><option value="" disabled>Select Product</option><option value="01">January</option><option value="02">February</option><option value="03">March</option><option value="04">April</option><option value="05">May</option><option value="06">June</option><option value="07">July</option><option value="08">August</option><option value="09">September</option><option value="10">October</option><option value="11">November</option><option value="12">December</option></select></td>
<td><input type="number" name="weight[]" class="form-control item_name" required /></td>
<td><button type="button" name="add" class="btn btn-success btn-sm add">+</button></td>
</tr>
</table>
</div>
</div>
</div>
</div>

<div class="col-lg-12">
<div align="center">
<a href="#confirm" data-target="#confirm" data-toggle="modal"><button type="button" class="btn btn-success">Submit</button></a>
</div>
</div>

<!-- // modal -->
<div id="confirm" class="modal fade" role="dialog">
<div class="modal-dialog">
<div class="modal-content">

<div class="modal-header">
<h4>Notice</h4>
<button type="button" class="close" data-dismiss="modal">&times;</button>
</div>

<div class="modal-body">
<div class="text-center">
<p>
<h6>Confirm Job Order?</h6>

</p>
</div>
<div class="modal-footer">
<input type="submit" id="submit" name="choose" class="btn btn-success" value="Continue" />
<button type="button" class="btn btn-default btn-outline-secondary" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
</div>

</form>


And my JS:



<script type="text/javascript">
$(document).ready(function()

$(document).on('click', '.add', function()
var html = '';
html += '<tr>';
html += '<td><select name="month[]" class="form-control item_unit"><option value="">Select Month</option><option value="01">January</option><option value="02">February</option><option value="03">March</option><option value="04">April</option><option value="05">May</option><option value="06">June</option><option value="07">July</option><option value="08">August</option><option value="09">September</option><option value="10">October</option><option value="11">November</option><option value="12">December</option></select></td>';
html += '<td><input type="number" name="weight[]" class="form-control item_name" required /></td>';
html += '<td><button type="button" name="remove" class="btn btn-danger btn-sm remove">x</button></td></tr>';
$('#item_table').append(html);
);

$(document).on('click', '.remove', function()
$(this).closest('tr').remove();
);

);
</script>


The user shouldn't be able to continue unless the total weights equal to 100 and if there are no duplicate entries in the selection boxes.










share|improve this question

















  • 1





    Which part specifically has you stuck? Are you performing the validation in JavaScript, PHP, or both? Are you asking how to read the values from your select elements? What did you try and how did it not work?

    – David
    Mar 24 at 16:33











  • @David its the reading of elements + the validation. I'm not sure what i should use for this. Maybe Jquery or JS. Sorry, I'm really clueless on what i need to do

    – Gabby Cervantes
    Mar 24 at 16:35











  • We can appreciate that you're finding it overwhelming, but it's important to keep questions here specific. If the first thing you're looking to do is read the values with jQuery, then start with a jQuery selector for your elements. Something like: $('select[name="month[]"]') This should select your select elements. You can loop over the results, examine the values, perform your logic, etc.

    – David
    Mar 24 at 16:42













0












0








0








I'm creating a dynamic form that asks users to pick certain dates and tag a weight to that specific date. The user is free to add up to 12 inputs using a new row button.



I need to validate that form and make sure the user doesnt select the same date input from the select box and that the weight inputs across all added date inputs total to 100. Im not sure what to use for the validation part.



So far, I can only make sure the forms are not empty when attempting to submit.



Here is my html and JS code for the dynamic form



HTML:




<form method="post" action="viewInventory.php" id="insert_form">
<div class="col-lg-12">
<div class="panel panel-default">
<div class="panel-body">
<div class="table-repsonsive">
<table class="table table-borderless" id="item_table">
<tr>
<th>Month</th><br>
<th>Weight</th>
</tr>
<tr>
<input class = 'form-control' type = 'hidden' name = 'example' value = 8>
<td><select name="month[]" class="form-control item_unit" required><option value="" disabled>Select Product</option><option value="01">January</option><option value="02">February</option><option value="03">March</option><option value="04">April</option><option value="05">May</option><option value="06">June</option><option value="07">July</option><option value="08">August</option><option value="09">September</option><option value="10">October</option><option value="11">November</option><option value="12">December</option></select></td>
<td><input type="number" name="weight[]" class="form-control item_name" required /></td>
<td><button type="button" name="add" class="btn btn-success btn-sm add">+</button></td>
</tr>
</table>
</div>
</div>
</div>
</div>

<div class="col-lg-12">
<div align="center">
<a href="#confirm" data-target="#confirm" data-toggle="modal"><button type="button" class="btn btn-success">Submit</button></a>
</div>
</div>

<!-- // modal -->
<div id="confirm" class="modal fade" role="dialog">
<div class="modal-dialog">
<div class="modal-content">

<div class="modal-header">
<h4>Notice</h4>
<button type="button" class="close" data-dismiss="modal">&times;</button>
</div>

<div class="modal-body">
<div class="text-center">
<p>
<h6>Confirm Job Order?</h6>

</p>
</div>
<div class="modal-footer">
<input type="submit" id="submit" name="choose" class="btn btn-success" value="Continue" />
<button type="button" class="btn btn-default btn-outline-secondary" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
</div>

</form>


And my JS:



<script type="text/javascript">
$(document).ready(function()

$(document).on('click', '.add', function()
var html = '';
html += '<tr>';
html += '<td><select name="month[]" class="form-control item_unit"><option value="">Select Month</option><option value="01">January</option><option value="02">February</option><option value="03">March</option><option value="04">April</option><option value="05">May</option><option value="06">June</option><option value="07">July</option><option value="08">August</option><option value="09">September</option><option value="10">October</option><option value="11">November</option><option value="12">December</option></select></td>';
html += '<td><input type="number" name="weight[]" class="form-control item_name" required /></td>';
html += '<td><button type="button" name="remove" class="btn btn-danger btn-sm remove">x</button></td></tr>';
$('#item_table').append(html);
);

$(document).on('click', '.remove', function()
$(this).closest('tr').remove();
);

);
</script>


The user shouldn't be able to continue unless the total weights equal to 100 and if there are no duplicate entries in the selection boxes.










share|improve this question














I'm creating a dynamic form that asks users to pick certain dates and tag a weight to that specific date. The user is free to add up to 12 inputs using a new row button.



I need to validate that form and make sure the user doesnt select the same date input from the select box and that the weight inputs across all added date inputs total to 100. Im not sure what to use for the validation part.



So far, I can only make sure the forms are not empty when attempting to submit.



Here is my html and JS code for the dynamic form



HTML:




<form method="post" action="viewInventory.php" id="insert_form">
<div class="col-lg-12">
<div class="panel panel-default">
<div class="panel-body">
<div class="table-repsonsive">
<table class="table table-borderless" id="item_table">
<tr>
<th>Month</th><br>
<th>Weight</th>
</tr>
<tr>
<input class = 'form-control' type = 'hidden' name = 'example' value = 8>
<td><select name="month[]" class="form-control item_unit" required><option value="" disabled>Select Product</option><option value="01">January</option><option value="02">February</option><option value="03">March</option><option value="04">April</option><option value="05">May</option><option value="06">June</option><option value="07">July</option><option value="08">August</option><option value="09">September</option><option value="10">October</option><option value="11">November</option><option value="12">December</option></select></td>
<td><input type="number" name="weight[]" class="form-control item_name" required /></td>
<td><button type="button" name="add" class="btn btn-success btn-sm add">+</button></td>
</tr>
</table>
</div>
</div>
</div>
</div>

<div class="col-lg-12">
<div align="center">
<a href="#confirm" data-target="#confirm" data-toggle="modal"><button type="button" class="btn btn-success">Submit</button></a>
</div>
</div>

<!-- // modal -->
<div id="confirm" class="modal fade" role="dialog">
<div class="modal-dialog">
<div class="modal-content">

<div class="modal-header">
<h4>Notice</h4>
<button type="button" class="close" data-dismiss="modal">&times;</button>
</div>

<div class="modal-body">
<div class="text-center">
<p>
<h6>Confirm Job Order?</h6>

</p>
</div>
<div class="modal-footer">
<input type="submit" id="submit" name="choose" class="btn btn-success" value="Continue" />
<button type="button" class="btn btn-default btn-outline-secondary" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
</div>

</form>


And my JS:



<script type="text/javascript">
$(document).ready(function()

$(document).on('click', '.add', function()
var html = '';
html += '<tr>';
html += '<td><select name="month[]" class="form-control item_unit"><option value="">Select Month</option><option value="01">January</option><option value="02">February</option><option value="03">March</option><option value="04">April</option><option value="05">May</option><option value="06">June</option><option value="07">July</option><option value="08">August</option><option value="09">September</option><option value="10">October</option><option value="11">November</option><option value="12">December</option></select></td>';
html += '<td><input type="number" name="weight[]" class="form-control item_name" required /></td>';
html += '<td><button type="button" name="remove" class="btn btn-danger btn-sm remove">x</button></td></tr>';
$('#item_table').append(html);
);

$(document).on('click', '.remove', function()
$(this).closest('tr').remove();
);

);
</script>


The user shouldn't be able to continue unless the total weights equal to 100 and if there are no duplicate entries in the selection boxes.







php forms validation






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 24 at 16:29









Gabby CervantesGabby Cervantes

1




1







  • 1





    Which part specifically has you stuck? Are you performing the validation in JavaScript, PHP, or both? Are you asking how to read the values from your select elements? What did you try and how did it not work?

    – David
    Mar 24 at 16:33











  • @David its the reading of elements + the validation. I'm not sure what i should use for this. Maybe Jquery or JS. Sorry, I'm really clueless on what i need to do

    – Gabby Cervantes
    Mar 24 at 16:35











  • We can appreciate that you're finding it overwhelming, but it's important to keep questions here specific. If the first thing you're looking to do is read the values with jQuery, then start with a jQuery selector for your elements. Something like: $('select[name="month[]"]') This should select your select elements. You can loop over the results, examine the values, perform your logic, etc.

    – David
    Mar 24 at 16:42












  • 1





    Which part specifically has you stuck? Are you performing the validation in JavaScript, PHP, or both? Are you asking how to read the values from your select elements? What did you try and how did it not work?

    – David
    Mar 24 at 16:33











  • @David its the reading of elements + the validation. I'm not sure what i should use for this. Maybe Jquery or JS. Sorry, I'm really clueless on what i need to do

    – Gabby Cervantes
    Mar 24 at 16:35











  • We can appreciate that you're finding it overwhelming, but it's important to keep questions here specific. If the first thing you're looking to do is read the values with jQuery, then start with a jQuery selector for your elements. Something like: $('select[name="month[]"]') This should select your select elements. You can loop over the results, examine the values, perform your logic, etc.

    – David
    Mar 24 at 16:42







1




1





Which part specifically has you stuck? Are you performing the validation in JavaScript, PHP, or both? Are you asking how to read the values from your select elements? What did you try and how did it not work?

– David
Mar 24 at 16:33





Which part specifically has you stuck? Are you performing the validation in JavaScript, PHP, or both? Are you asking how to read the values from your select elements? What did you try and how did it not work?

– David
Mar 24 at 16:33













@David its the reading of elements + the validation. I'm not sure what i should use for this. Maybe Jquery or JS. Sorry, I'm really clueless on what i need to do

– Gabby Cervantes
Mar 24 at 16:35





@David its the reading of elements + the validation. I'm not sure what i should use for this. Maybe Jquery or JS. Sorry, I'm really clueless on what i need to do

– Gabby Cervantes
Mar 24 at 16:35













We can appreciate that you're finding it overwhelming, but it's important to keep questions here specific. If the first thing you're looking to do is read the values with jQuery, then start with a jQuery selector for your elements. Something like: $('select[name="month[]"]') This should select your select elements. You can loop over the results, examine the values, perform your logic, etc.

– David
Mar 24 at 16:42





We can appreciate that you're finding it overwhelming, but it's important to keep questions here specific. If the first thing you're looking to do is read the values with jQuery, then start with a jQuery selector for your elements. Something like: $('select[name="month[]"]') This should select your select elements. You can loop over the results, examine the values, perform your logic, etc.

– David
Mar 24 at 16:42












0






active

oldest

votes












Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55325982%2fform-validation-for-dynamic-php-forms%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55325982%2fform-validation-for-dynamic-php-forms%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현