Bagaimana cara mendapatkan nilai kotak teks dari kirim di php?

This post is with regards to handling forms that have more than one submit button.

Suppose we have an HTML form with a submit button specified like this:

Normally the 'value' attribute of the HTML 'input' tag [in this case "Delete"] that creates the submit button can be accessed in PHP after post like this:

$_POST['action_button'];
?>

We of course use the 'name' of the button as an index into the $_POST array.

This works fine, except when we want to pass more information with the click of this particular button.

Imagine a scenario where you're dealing with user management in some administrative interface.  You are presented with a list of user names queried from a database and wish to add a "Delete" and "Modify" button next to each of the names in the list.  Naturally the 'value' of our buttons in the HTML form that we want to display will be "Delete" and "Modify" since that's what we want to appear on the buttons' faceplates.

Both buttons [Modify and Delete] will be named "action_button" since that's what we want to index the $_POST array with.  In other words, the 'name' of the buttons along cannot carry any uniquely identifying information if we want to process them systematically after submit. Since these buttons will exist for every user in the list, we need some further way to distinguish them, so that we know for which user one of the buttons has been pressed.

Using arrays is the way to go.  Assuming that we know the unique numerical identifier of each user, such as their primary key from the database, and we DON'T wish to protect that number from the public, we can make the 'action_button' into an array and use the user's unique numerical identifier as a key in this array.

Suppose we have an HTML form with a submit button specified like this:_0

Suppose we have an HTML form with a submit button specified like this:_1

Suppose we have an HTML form with a submit button specified like this:_2

Suppose we have an HTML form with a submit button specified like this:_3

Suppose we have an HTML form with a submit button specified like this:_4

Suppose we have an HTML form with a submit button specified like this:_5

Suppose we have an HTML form with a submit button specified like this:_6

Suppose we have an HTML form with a submit button specified like this:_7

Ini mungkin terdengar membingungkan tetapi saya memiliki kotak teks yang merupakan kotak teks nomor sel dan saya ingin ketika panjang maksimal 10 telah tercapai kemudian jalankan kode php yang ada di dalam halaman html yang sama dengan formulir dan kode php ini kemudian akan mendapatkan nilainya . Saya sudah mencoba Javascript dan masalah yang saya alami dengan javasacript adalah sekarang menampilkan data ini sehingga saya memutuskan untuk mengubah ke php karena saya tahu cara menampilkan data sesi php di dalam kotak teks dengan sesuatu seperti



      function checkmax[element] {

          if[element.value.length == 9]{

             var xhr = new XMLHttpRequest[];
             xhr.open['POST', '/server/getPhone.php', true];
             //Send the header 
             xhr.setRequestHeader["Content-type", "application/x-www-form-urlencoded"];

             xhr.onreadystatechange = function[] {//Call a …
_6

jadi saya mencoba melakukan sesuatu seperti ini tetapi dengan javascript tetapi seluruh kode tag hanya ditampilkan di layar ketika saya menjalankan memuat halaman sehingga saya memilih untuk menggunakan php

Harap perhatikan bahwa halaman tersebut adalah HTML dan input dari mana saya ingin mengambil datanya juga dalam html bukan php, skrip fungsi php akan ditulis di dalam halaman html sehingga semua ini akan berada dalam satu halaman bukan itu akan

html-forms html5 javascript php

0 0

Membagikan

Diedit 5 Tahun Lalu oleh Mr. M

  • 6 Kontributor
  • 20 Balasan
  • 5K Tampilan
  • 5 Hari Rentang Diskusi
  • Pos Terbaru Pos Terbaru oleh Mr. M

Jawaban yang Direkomendasikan

Dijawab oleh AssertNull 1.094 dalam

Anda dapat memasukkan apa yang saya ketahui tentang HTML5 ke dalam tabung reaksi dan memiliki banyak ruang tersisa, jadi tidak ada yang berguna untuk dikatakan pada tag itu. TETAPI

Saya tahu sesuatu tentang tiga tag Anda yang lain, jadi saya tetap akan ikut. Ya, pertanyaan Anda membingungkan. Setidaknya …

Dijawab oleh xrjf 213 dalam

Saya setuju bahwa satu-satunya cara yang dapat saya lihat adalah mengirimkan formulir kembali ke server. Sesuatu seperti





  function chkLen[] {
  if[document.getElementById["dCell"].value.length =10]
    document.getElementById["myForm"].submit[]; 
}


Bài mới nhất

Chủ Đề