2015-11-17 27 views
0

我努力完成我的项目的最后一块 - 我有一个是通过在格式YYYY日期时间选择器填充的文本/ MM/DD HH:MMPHP进行urlencode jQuery的字符串

我需要将此值传递给URL字符串,然后将其发送到数据库表。

由于I''m使用模式,以收集我需要我有一个jQuery脚本改变提交按钮我HREF标签的附加信息:

$(document).on('click','#myModal<?php echo $v['id']; ?> .modal-footer a', function(e) 
      { 
       e.preventDefault(); 
       //function to update HREf attribute with values from modal screen 
       var uri = <?php urlencode('2016/01/01/ 21:00')?> 
       //$('#divert_until_<?php echo $v['id']; ?>').text(); 

       window.location.href=window.location.href= $(this).attr('href') + '&to=' + $('#divert_to_<?php echo $v['id']; ?> option:selected').text() + '&type= ' + $('#divert_type_<?php echo $v['id']; ?> option:selected').text() + '&until= ' + uri; 

      }); 

目前,我收到的所有信息(ID ,TO和TYPE),但UNTIL没有任何结果。上面我试图将固定字符串'2016/01/01 21:00'保存到数据库。

这里是我的代码来捕获的网址:

if(isset($_GET['action']) && $_GET['action']=='add_divert') { 

if(!isset($_GET['id']) || !is_numeric($_GET['id'])) { 
    $_SESSION['notification'] = array('type'=>'bad','msg'=>$lang['ADMIN_INVALID_ID']); 
    redirect(ROOT_URL.'stores.php?search='.$_REQUEST['search'].$pg.$st.$fl); 
} 

$db = db_connect(); 
if($db->update('stores',array('divert_enabled'=>1,'divert_type'=>($_GET['type']),'divert_until'=>($_GET['until']),'divert_to'=>($_GET['to'])),$_GET['id'])) { 
    $_SESSION['notification'] = array('type'=>'good','msg'=>'Divert notice added to destination.'); 
} else { 
    $_SESSION['notification'] = array('type'=>'bad','msg'=>'Could not add a divert notice to the destination.'); 
} 
redirect(ROOT_URL.'stores.php?search='.$_REQUEST['search'].$pg.$st.$fl); 
} 

我已经尝试了一些变化,但我只是转圈圈。

最后,我需要从('#divert_until_<?php echo $v['id']; ?>').text()

由于重试的日期时间字符串!

+0

什么你的问题? –

+0

如何将日期时间值从文本框传递给接受查询接受的格式的URL –

回答

0

我不好,用的.text代替.val

最终代码:

$(document).on('click','#myModal<?php echo $v['id']; ?> .modal-footer a', function(e) 
    { 
    e.preventDefault(); 
    //function to update HREf attribute with values 

    var until_str = $('#divert_until_' + <?php echo $v['id']; ?>).val(); 
    var uri = encodeURI(until_str); 

    window.location.href=window.location.href= $(this).attr('href') + '&to=' + $('#divert_to_<?php echo $v['id']; ?> option:selected').text() + '&type= ' + $('#divert_type_<?php echo $v['id']; ?> option:selected').text() + '&until=' + uri; 

    }); 
0

使用JavaScript函数编码值encodeURI然后发送此。

在您接收的php服务器上使用urldecode php函数获取原始值。

+0

谢谢,我已经成功地将一个固定字符串编码成urlencoding,但只是忽略了一些现在可以防止该文本框值的东西从正确发送。 –

+0

嗨,我看到我的答案没有解决您的问题。请不要接受它,因为它不好的做法,并可能误导其他人访问您的问题类似的问题。可以接受你自己的答案。 – shanmuga

+0

嗯,这是EncodeURI,并改变为.val,它发生了 - 所以,大多数是正确的! –