2015-05-07 31 views
0

這可能已經是另一個問題的副本,但我無法找到它。HTML操作ID獲取方法

我在形式的行動:

<form id="bug-form" action="/AST_14/Bugg.ly2/index.php/bug/update/" method="post"> 

現在我的系統的工作方式是每一個「錯誤」需要更新的,有自己的錯誤號的,通常這會走上結束錯誤ID以允許用戶更新所述Bug。

我在Yii中創建了一些json代碼來顯示bug ID和編輯。 問題是,當我點擊編輯。它轉到頁面上沒有窗體上的ID。我需要一些方法讓該ID移到表單中。

這裏是我對錶單的所有代碼。

<!--PAGE --> 

<div data-role="page" id="Reg"> 
<header role="banner" data-role="header" id="header" style="height:45px; z- index:1"> <a data-icon="back" data-role="button" data-rel="back" class="ui-btn- left backToAdmin">Back</a> </header> 

<!--Initial Home Screen Logo--> 
<section data-role="content" class="constrain headerLogo" > </section> 

<!--Main Content in Center of Screen--> 
<section data-role="content" class="sectionContent constrain"> 

    <!--960 Grid Root [responsive web design plugin]--> 
    <div class="container_16" data-theme="a"> 
    <div class="grid_16"> 
    <div class="gridMarginsLeft"> 
     <ul id="viewProps" data-role="listview" data-inset="true" data-theme="a" data-icon="false" class=""> 
     <li data-role="list-divider" data-theme="a"><span class="icon-data fontIcons"></span><span class="coloumnHeaders">Update</span></li> 
     <li data-role="list-divider" data-theme="a"> 


<form id="bug-form" action="/AST_14/Bugg.ly2/index.php/bug/update/" method="post"> 
<p class="note">Fields with <span class="required">*</span> are required.</p> 


<div class="row"> 
     <label for="Bug_bugname">Bugname</label>  <textarea rows="6" cols="50" name="Bug[bugname]" id="Bug_bugname">1</textarea>   </div> 

<div class="row"> 
    <label for="Bug_BugType">Bug Type</label>  <input name="Bug[BugType]" id="Bug_BugType" type="text" value="1">   </div> 

<div class="row"> 
    <label for="Bug_Bugaddress">Bugaddress</label>  <input size="60" maxlength="255" name="Bug[Bugaddress]" id="Bug_Bugaddress" type="text" value="1">   </div> 

<div class="row"> 
    <label for="Bug_description">Description</label>  <textarea rows="6" cols="50" name="Bug[description]" id="Bug_description">1</textarea>   </div> 

<div class="row"> 
    <label for="Bug_admin_id">Admin</label>  <input name="Bug[admin_id]" id="Bug_admin_id" type="text" value="1">   </div> 

<div class="row"> 
    <label for="Bug_status">Status</label>  <input size="3" maxlength="3" name="Bug[status]" id="Bug_status" type="text" value="1">   </div> 

<div class="row"> 
    <label for="Bug_type">Type</label>  <input size="20" maxlength="20" name="Bug[type]" id="Bug_type" type="text" value="1">   </div> 

<div class="row"> 
    <label for="Bug_vendors_id">Vendors</label>  <input name="Bug[vendors_id]" id="Bug_vendors_id" type="text" value="1">   </div> 

<div class="row buttons"> 
    <input type="submit" name="yt0" value="Save"> </div> 

</form> 




     </li> 
     </ul> 
    </div> 
    </div> 
</div> 

回答

1

添加一個隱藏的輸入形式。我的身份證是變量名$ id:

form id="bug-form" action="/AST_14/Bugg.ly2/index.php/bug/update/" method="post"> 

<input type="hidden" name="id" value="$id" /> 

</form> 

要將該ID放入URL路徑中,請將$ id追加到操作路徑中。

form id="bug-form" action="/AST_14/Bugg.ly2/index.php/bug/update/$id" method="post"> 
+0

這會那麼URL更改爲 '形式ID = 「錯誤形式」 行動= 「/ AST_14/Bugg.ly2/index.php文件/錯誤/更新/ BUGIDHERE」 方法= 「郵報」>' –

+0

看更新..... – Misunderstood

+0

非常感謝! –

0

在表單中添加一個隱藏的輸入字段標記,並將該id作爲其值。

<input type="hidden" id="bug_id" name="bug_id" value="$id" />

而且使用JavaScript/jQuery代碼來改變你的動作URL(這裏我用的jQuery):

$(文件)。就緒(函數(){

$('#bug-form').submit(function(){ 

    //append your bug id to the action url 
    var updateUrl = $(this).attr('action') +$('#bug_id').val(); 

    //update your action url of the form 
    $(this).attr('action',updateUrl); 
    }); 

});