2015-11-17 41 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,它發生了 - 所以,大多數是正確的! –