I have a loop in php that for each item, a link that opens a lightbox is generated. How can I pass data related to the current iteration (such as the userid) in such a way that I can use it in the lightbox and the form submission?
<?php
foreach ($results as $viewUser)
{
if ($viewUser)
{
echo '<a class="change-email" href="#">Change Email</a>';
}
}
}
?>
<script>
$(function(){
$(".change-email").click(function(){
$.fancybox({
'href' : '#change-email-dialog',
'width' : '200px',
'height' : 'auto',
'autoScale' : true,
'transitionIn' : 'fade',
'transitionOut' : 'fade',
'type' : 'inline',
'modal' : false,
'afterShow' : function () {
}
});
});
});
</script>
<div id="change-email-dialog">
<form id="change-email-form" class="table" method="POST" action="<?php echo site_url('customerservice/changeEmail').'user='.$viewUser->getBusID(); ?>">
<ul class="table-row">
<li class="table-cell">New Email</li>
<li class="table-cell"><input type="text" name="newEmail" /></li>
</ul>
<ul class="table-row">
<li class="table-cell">Notify Contract Entry?</li>
<li><input type="checkbox" checked="checked" name="notify" /></li>
</ul>
<ul class="table-row">
<li><input name="userSearchSubmit" type="submit" value="Save" /></li>
</ul>
</form>
</div>
.clickfrom the javascript, add a parameter such asfunction(id)and then when echoing the link, addonclick=\"function(" . $myid . "\"