将php变量传递给模式 [英] Passing a php variable to a modal

查看:57
本文介绍了将php变量传递给模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个日历,当我单击日期时,它会打开一个模态窗口,您可以在其中向日历添加事件,但是要这样做,我需要将单击的日期传递给模态,这样我就可以用户单击提交"后,将其添加到我的数据库中.

截至目前,Im都通过对每个模式代码都回显我的模态代码来执行此操作,因此,即使您查看我的源代码,我也有31个模态,但是Im试图通过简单地将日期作为变量传递,将其简化为一个模态./p>

这是我的模态代码:

由于某种原因,我无法格式化它以便显示在这里,所以我将其张贴在这里: http://paste. ee/p/NKlVY

这就是我所说的:

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

我需要添加或更改什么,以便我可以对一个月的所有日期使用一个模式?

解决方案

我不确定我是否很好理解您的问题,但您可能必须使用javascript.其实不行

您应该有一个模式,当客户选择一个日期时,将此日期放在Javascript或jQuery中的模式中.

jQuery中的示例(未经测试,但这是逻辑):

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

由于我们没有太多有关您的代码的信息,所以我无能为力,但这是您需要的逻辑;)

以您的示例为例:

html输入:

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

jQuery:

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

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.

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

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. 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.

Example in jQuery (not tested but this is the logic):

$("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:

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

jQuery:

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

这篇关于将php变量传递给模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆