I asked a question earlier today which in a nutshell asks when a user clicks a button on a page -- a pop up modal comes up, which should get a PHP variable value.
Since there is no GET or POST request when popup modal btn is clicked which means I can not get the variable value using above two options
tried the following:
`<a id="myid" data-id="<?php echo $userID ?>">link</a>
<script>
$('#myid').data("id");
</script>`
Now I have the PHP $userID
value in a javascript variable. Which leads me to my question what would be the most efficient way to retrieve the $userID
variable and insert it into a php variable.
Additional Info
I found this question on SO but it is not really applicable to me.
Example Image of what im trying to achieve
LOOP GENERATED PHP LIST
$teacherClass = new TeacherSearch();
$teachers = $teacherClass->showAllTeachers();
if (is_array($teachers)) {
foreach ($teachers as $teacher) {
$src = $teacher['userID'];
<div class="teacher-info">
<p class="teacherLabel">
NAME:
<?php
echo $teacher['name'];
?>
</p>
<p class="teacherLabel">
HEADLINE:
<?php
echo $teacher['headline'];
?>
<p class="teacherLabel">
LOCATION:
<?php
echo $teacher['location']
?>
</p>
<!--BUTTON GOES HERE-->
<a id="myid" data-id="<?php echo $teacher['userID'] ?>" data-toggle="modal" data-target="#myModal">Hire <?php echo $teacher['name'] ?></a>
}//foreach
Example IMG
Modal
<!-- Trigger the modal with a button -->
<!-- Modal -->
<div id="myModal" class="modal fade" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 id="modalTitle" class="modal-title"></h4>
</div>
<div class="modal-body">
Need to perform PHP here with $userID variable
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>