2011-06-22 85 views
0

我新的PHP和JS,我有這樣的代碼,我一直在堅持,我不能去上班:PHP/JS形式問題

我something.php只是有$variable= $_POST['SUBMIT'] echo $variable

<?php 
$list=$_POST['added']; 
?> 

<html> 
<head> 
    <meta http-equiv="content-type" content="text/html; charset=UTF-8"> 

    <script type='text/javascript' src='http://code.jquery.com/jquery-1.6.js'></script> 

    <link rel="stylesheet" type="text/css" href="/css/normalize.css"> 
    <link rel="stylesheet" type="text/css" href="/css/result-light.css"> 

    <style type='text/css'> 


#display{ 
    width: 500px; 
    height: 250px; 
    overflow: scroll; 
    background-color:white; 
} 

#display div { 
    clear: both; 
} 
#display div span{ 
    float: left; 
    padding: 10px; 
} 

.edit { 
    color: blue; 
} 

.delete { 
    color: red; 
} 



    body {background-color:orange;} 
p {color:orange; 
    size=3; 
} 

    body { 

    background-image: url("http://dev.icalapp.rogersdigitalmedia.com.rogers-test.com/rogers_blackberry_8900.jpg"); 

    background-position: 50% 50%; 

    background-repeat: repeat; 

} 

    </style> 

    <script type='text/javascript'> 
    //<![CDATA[ 
    $(window).load(function(){ 
    $('#add').click(function() { 
    this.innerHTML = 'Add'; 
    var input = $('#addInput'); 
    var display = $('#display'); 
    var form = $('#addForm'); 
    if ($.trim(input.val()).length > 0) { //is there input? 
     var div = $('<div>').append($('<span>', { 
      text: input.val() 
     }), $('<span>', { 
      text: 'delete', 
      class: 'delete' 
     }), $('<span>', { 
      text: 'edit', 
      class: 'edit' 
     })) 
     display.append(div); 
     form.append($('<input>', { 
      value: input.val(), 
      type: 'hidden', 
      name: 'added[]' 
     })); 
     input.val(''); 
     } 
    }) 



    $('.edit').live('click', function(){ 
     $('#add').html('Edit'); 
     var input = $('#addInput'); 
     var index = $(this).parent().index() + 1; 
     input.val($(this).parent().children().get(0).innerHTML); //show value 
     $(this).parent().remove(); //remove it from the list 
     $('#addForm').children().eq(index).remove(); 
    }); 

    $('.delete').live('click', function(){ 
     var index = $(this).parent().index() + 1; 
     $('#addForm').children().eq(index).remove(); 
     $(this).parent().remove(); //remove it from the list 
    }); 




    }); 


    //]]> 
    </script> 

    <title>Admin Phone Setup</title> 
</head> 
<body> 

<STYLE>H2 {FONT-SIZE: 21pt; COLOR: #ff3399}; </STYLE> 
<CENTER> 
<H2>Twilio Admin Setup</H2> 
</CENTER> 


<p id="demo">Enter Phone Numbers</p> 
    <input id="addInput"/> <button id="add">Add</button> 
<div id='display'></div> 
<form action="something.php" id="addForm"> 
    <input type="submit" value="SUBMIT"/> 
</form> 
</body> 
</html> 

我想要做的是一旦一個人添加一串數字到該列表中,然後點擊提交它應該將這些值發送到something.php,以便我可以使用這些值...我真的被卡住了,不知道我是什麼我做錯了...我認爲這可能是我的顯示列表中的變量或一些問題。

+0

什麼不工作? – jeroen

+0

概覽我的建議是嘗試將輸入放置在

標記內,因爲提交表單只發送標記內指定的輸入。 – Ram

+0

因爲你的PHP文件尋找_POST,當打開你的表單(例如)時,添加method =「post」> – Ram

回答

1

1)您的按鈕是未命名的。要獲得按鈕值,你必須分配一個名稱屬性,例如

<input type="submit" name="mysubmitbutton" value="SUBMIT" />

2)在你something.php您正在使用POST陣列,但你的提交表單與GET數據,因爲在你的表單標籤沒有「方法」屬性。此外,它似乎嘗試通過使用它的值作爲索引訪問按鈕值(這不是字;))。您可以選擇(nameing按鈕後) 一)在你的PHP腳本 20b使用$ _GET [ 'mysubmitbutton'])你的表單標籤更改爲

<form ... method="post" ... >
和使用$ _ POST [ 'mysubmitbutton']。

+0

我已經解決了它,但現在問題是它顯示「提交」,當我點擊提交按鈕...所以something.php顯示提交...這是假設顯示我添加到列表中的數字列表.. – Bulvak

+0

迭代你*添加*數組並回顯項目。例如foreach($ _ POST ['added'] as $ item){echo $ item。 '
'; } – hacksteak25