-1

I have a button that I'm using to submit a form (quiz). I also have another button to do this, but it gets built dynamically. Note the workflow of the code below.

Ultimately, I want PHP to know which button was pressed to submit the form. So, I included name="save_progress" in the <button> code below. However, including that automatically submits the form and bypasses the setTimeout() in my javascript. Removing it makes the setTimeout() function properly, but I don't get the save_progress data via $_POST.

Button...

<button class="btn btn-primary btn-block btn-lg" name="save_progress" onclick="save_progress(); return false;">Save Progress</button>

Javascript...

//For saving quiz progress
function save_progress(){
    $('#save_progress_submit_container').modal('show');

    setTimeout(function() {
        submit_quiz();
    }, 1000);
}

//Submitting a quiz
function submit_quiz(){
    $("#answers").submit(); 
}

Any ideas that will work with this workflow? I've already reviewed this (How can I tell which button was clicked in a PHP form submit?) and it doesn't apply here, unfortunately.

gtilflm
  • 1,389
  • 1
  • 21
  • 51
  • *"I've already reviewed this ([How can I tell which button was clicked in a PHP form submit?](https://stackoverflow.com/q/2680160/1415724)) and it doesn't apply here, unfortunately."* - There's php in there, your post doesn't contain any. We don't know if what you have for it is correct. Have you checked for errors via php and looked at the developer console? There's also no HTML neither here. – Funk Forty Niner May 09 '18 at 01:47
  • https://stackoverflow.com/a/10836076/152016 – Niloct May 09 '18 at 01:54
  • `console.log()` your error and tell me what's wrong – Precious Tom May 09 '18 at 03:29

1 Answers1

0

Came up with a better solution overall. I created <input type="hidden" id="submit_type" name="submit_type" value=""> in the form, then simply updated the value using jQuery based on which button was clicked.

For future readers, @Niloct's link in the comments caused me to get a save_progress() is not a function error, but it did prevent the submission.

gtilflm
  • 1,389
  • 1
  • 21
  • 51