0

I have this form:

<form name="form" action="course_submit.php" onsubmit="return validateForm()" method="post">
...
</form>

And I'd like to add a few json arrays to POST in validateForm() after validation, so that when validateForm() returns true, the updated POST will be sent to course_submit.php. What's the best wya to go about this? Thanks!

Joseph_Renerr
  • 229
  • 1
  • 2
  • 7

1 Answers1

2

Have <input type="hidden" ...> elements inside the form.

Assign the values to those elements.

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
  • Can I do that in the onsubmit() for the form, and have that data added to POST? I wouldn't have guessed it to be so easy. – Joseph_Renerr Apr 15 '21 at 03:22
  • 1
    Your question specifically asked about achieving this effect at that time, so yes. – Quentin Apr 15 '21 at 07:08
  • I appreciate your patience with me. I tested this out, having in the form, and then running document.getElementsByName("test").value = "HELLO"; in the onsubmit() function, but I don't see it in post. Am I misunderstanding? – Joseph_Renerr Apr 15 '21 at 21:16
  • 1
    https://stackoverflow.com/questions/10693845/what-do-queryselectorall-and-getelementsby-methods-return – Quentin Apr 15 '21 at 21:24