-2

I am using jquery to get the state of the toggle, I want to send that variable to my controller using twig, this is what I had done

    <form method="post" enctype="multipart/form-data">
Sync: <br><div class="toggle-switch toggle-switch--green">
<input type="checkbox" class="toggle-switch__checkbox" id="togBtn" value='{{switchstatus}}' name = "sync">
<i class="toggle-switch__helper"></i></div><br>
<input type="submit" value="Update">

In Jquery

var switchStatus = false;
$("#togBtn").on('change', function() {
if ($(this).is(':checked')) {
    switchStatus = $(this).is(':checked');
}
else {
   switchStatus = $(this).is(':checked');
}
console.log(switchStatus);
$.ajax({
type: "POST",
url: 'name.html.twig',
data: switchStatus
});
});

I am getting value as empty

How do I pass my value of switchStatus in jquery to value option in twig HTML?

  • 1
    Possible duplicate of https://stackoverflow.com/questions/13840429/what-is-the-difference-between-client-side-and-server-side-programming – 04FS May 06 '19 at 08:47
  • I dont understand, you want to pass from twig to jquery **or** from jquery to db? – Nikos M. May 06 '19 at 08:47

1 Answers1

1

You need to send information to the PHP script via jQuery AJAX, the PHP script to sanitize user input/ do user check ups and then save the information into the database.

Maximus Light
  • 411
  • 3
  • 9