简体   繁体   English

将php变量传递给模式

[英]Passing a php variable to a modal

Hi I have a calendar and when I click on the date it opens a modal window where you can add an event to the calendar however to do so I need the date that was clicked on to be passed to the modal so I can add it to my database once the user clicks submit. 嗨,我有一个日历,当我单击日期时,它会打开一个模态窗口,您可以在其中向日历添加事件,但是要这样做,我需要将单击的日期传递给模态,以便将其添加到用户单击提交后,我的数据库。

As of right now Im doing this by echoing my modal codes for each even so if you look at my source I have 31 modals but Im trying to, by simply passing the date as a variable, reduce it to one modal. 截至目前,Im都通过回显每个模式代码来做到这一点,即使您查看我的源代码,我也有31个模式,但Im试图通过简单地将日期作为变量传递,将其简化为一个模式。

This is the code for my modal: 这是我的模态代码:

I wasnt able to format it to show here for some reason so I posted it here: http://paste.ee/p/NKlVY 由于某种原因,我无法格式化它以显示在这里,所以我在这里发布了它: http : //paste.ee/p/NKlVY

And this is how I call it: 这就是我所说的:

$sCalTblRows .= '<td class="'.$sClass.'" id=""><a data-toggle="modal" data-date="'.$eventdate.'" href="#myModal">'.$iCurrentDay.'<br></br><br></br></td>';

What would I need to add or change so I can use one modal for all the dates of the month? 我需要添加或更改什么,才能对一个月的所有日期使用一个模式?

I'm not sure if I understand well your problem but you probably have to use javascript. 我不确定是否能很好地理解您的问题,但您可能必须使用javascript。 Actually It can't work 其实不行

You should have one modal, and when the client choose a date, put this date in the modal in Javascript or jQuery. 您应该有一个模式,当客户选择一个日期时,将此日期放在Javascript或jQuery中的模式中。

Example in jQuery (not tested but this is the logic): jQuery中的示例(未经测试,但这是逻辑):

$("td.yourtdclass a" ).on("click", function() {
    var choosen_date = $(this).attr('data-date');
    $('.modal-body').html(choosen_date);
});

Since we have not much informations about your code I can't help more but here is the logic you need ;) 由于我们没有太多有关您的代码的信息,所以我们无济于事,但这是您需要的逻辑;)

EDIT: 编辑:

For your example: 例如:

html input: html输入:

 <input id="event-data" type="hidden" name="date" value="" />

jQuery: jQuery的:

$( "td.yourtdclass a" ).on("click", function() {
   var choosen_date = $(this).attr('data-event');
   $('#event-data').val(choosen_date);
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM