Hướng dẫn how to get input value in php variable without submit - cách lấy giá trị đầu vào trong biến php mà không cần gửi

-2

Mới! Lưu câu hỏi hoặc câu trả lời và sắp xếp nội dung yêu thích của bạn. Tìm hiểu thêm.
Learn more.

Tôi cần lấy giá trị của một trường văn bản và lưu nó vào một biến nhưng không có nút gửi.

Như thế này ở đây: http://streambadge.com/

Như bạn có thể thấy văn bản bạn viết trong bước hai sẽ tự động được thêm vào văn bản đầu ra. Tôi có thể làm cái này như thế nào?

hỏi ngày 17 tháng 1 năm 2014 lúc 17:21Jan 17, 2014 at 17:21

Hướng dẫn how to get input value in php variable without submit - cách lấy giá trị đầu vào trong biến php mà không cần gửi

1

Bạn có thể làm điều đó bằng JavaScript /jQuery (tập lệnh trang web máy khách).

Bản demo trực tiếp: http://jsfiddle.net/5y9mg/51/
http://jsfiddle.net/5Y9mG/51/

HTML:


You will have output here :

Jquery:

$( document ).ready(function() {
         $('input[id="country"]').on('keyup', function() {  // on keyup event in your input field
                $("#needs").append(this.value);// append values from input field
          });
    );

Bạn muốn lưu giá trị này trong biến PHP thì bạn cần gọi AJAX (mà không gửi biểu mẫu của bạn) hoặc bạn cần gửi biểu mẫu.

Đối với Ajax cơ bản, bạn có thể đọc điều này: http://www.tutorialspoint.com/jquery/ajax-jquery-post.htm
http://www.tutorialspoint.com/jquery/ajax-jquery-post.htm

Liên kết jQuery hữu ích để tìm hiểu: Tài liệu API: http://api.jquery.com/
API documentation: http://api.jquery.com/

Cơ bản: http://learn.jquery.com/about-jquery/how-jquery-works/

Đã trả lời ngày 17 tháng 1 năm 2014 lúc 17:27Jan 17, 2014 at 17:27

Hướng dẫn how to get input value in php variable without submit - cách lấy giá trị đầu vào trong biến php mà không cần gửi

Awlad Litonawlad LittonAwlad Liton

9.2682 Huy hiệu vàng26 Huy hiệu bạc52 Huy hiệu Đồng2 gold badges26 silver badges52 bronze badges

5

Sử dụng onchange hoặc onkeyup để phát hiện khi người dùng gõ.

Đã trả lời ngày 17 tháng 1 năm 2014 lúc 17:22Jan 17, 2014 at 17:22

Hướng dẫn how to get input value in php variable without submit - cách lấy giá trị đầu vào trong biến php mà không cần gửi

HalcyonhalcyonHalcyon

56.6K10 Huy hiệu vàng87 Huy hiệu bạc126 Huy hiệu đồng10 gold badges87 silver badges126 bronze badges

5 năm trước

Darren tại Sullivan Dot Net

Tim tại Timpauly Dot Com ¶

Name:
Email:

Keli tại Kmdsz Dot Ro ¶

Arjini tại Mac Dot Com ¶

echo $_POST['username'];
echo 
$_REQUEST['username'];
?>

mattij tại nitro fi no at no dot no ¶

Làm thế nào tôi có thể nhận được giá trị trường đầu vào trong PHP mà không cần gửi?:

PHP $ a = $ _get ["housemodel"]; if ($ a '') {if ($ a == $ model1) {echo ""; } if if ($ a == $ model2) {echo ""; } if if ($ a == $ model3) {echo ""; ...

Làm thế nào để chúng tôi nhận được giá trị hộp văn bản trong một biến PHP mà không cần một nút gửi hoặc nhấp?

trên ('keyUp', function () {// trên sự kiện keyup trong trường đầu vào của bạn $ ("#nhu cầu"). ); Bạn muốn lưu giá trị này trong biến PHP thì bạn cần gọi AJAX (mà không gửi biểu mẫu của bạn) hoặc bạn cần gửi biểu mẫu.

$( document ).ready(function() {
         $('input[id="country"]').on('keyup', function() {  // on keyup event in your input field
                $("#needs").append(this.value);// append values from input field
          });
    );
2

$ _ Trong PHP là gì?: If an external variable name begins with a valid array syntax, trailing characters are silently ignored. For example,

$( document ).ready(function() {
         $('input[id="country"]').on('keyup', function() {  // on keyup event in your input field
                $("#needs").append(this.value);// append values from input field
          });
    );
3 becomes
$( document ).ready(function() {
         $('input[id="country"]').on('keyup', function() {  // on keyup event in your input field
                $("#needs").append(this.value);// append values from input field
          });
    );
4.

PHP $ _POST là một biến siêu toàn cầu PHP được sử dụng để thu thập dữ liệu biểu mẫu sau khi gửi biểu mẫu HTML với Phương thức = "Post". $ _POST cũng được sử dụng rộng rãi để vượt qua các biến.

Biến $$ trong PHP là gì?

PHP | $ vs $$ toán tử $ var_name = "Hello World!"; $ Var_name là một biến bình thường được sử dụng để lưu trữ một giá trị. Nó có thể lưu trữ bất kỳ giá trị nào như Integer, Float, Char, String, v.v. Mặt khác, $$ var_name được gọi là biến tham chiếu trong đó $ var_name là một biến bình thường.

Mẫu HTML (GET và POST)

Khi một biểu mẫu được gửi đến tập lệnh PHP, thông tin từ biểu mẫu đó sẽ tự động cung cấp cho tập lệnh. Có một số cách để truy cập thông tin này, ví dụ: ví dụ:setcookie() function. Cookies are part of the HTTP header, so the SetCookie function must be called before any output is sent to the browser. This is the same restriction as for the header() function. Cookie data is then available in the appropriate cookie data arrays, such as $_COOKIE as well as in $_REQUEST. See the setcookie() manual page for more details and examples.

Lưu ý: Kể lần lượt là Php 7.2.34, 7.3.23 và 7.4.11, tên của cookie đến không còn được mã hóa URL vì lý do bảo mật.: As of PHP 7.2.34, 7.3.23 and 7.4.11, respectively, the names of incoming cookies are no longer url-decoded for security reasons.

Nếu bạn muốn gán nhiều giá trị cho một biến cookie, bạn có thể gán nó dưới dạng một mảng. Ví dụ:

$( document ).ready(function() {
         $('input[id="country"]').on('keyup', function() {  // on keyup event in your input field
                $("#needs").append(this.value);// append values from input field
          });
    );
5

Điều đó sẽ tạo ra hai cookie riêng biệt mặc dù Mycookie bây giờ sẽ là một mảng duy nhất trong tập lệnh của bạn. Nếu bạn muốn chỉ đặt một cookie có nhiều giá trị, hãy xem xét sử dụng serialize () hoặc leasplode () trên giá trị trước.serialize() or explode() on the value first.

Lưu ý rằng cookie sẽ thay thế cookie trước đó cùng tên trong trình duyệt của bạn trừ khi đường dẫn hoặc miền khác nhau. Vì vậy, đối với một ứng dụng giỏ hàng, bạn có thể muốn giữ một quầy và vượt qua điều này. I E.

Ví dụ #4 Ví dụ SetCookie ()setcookie() example

$( document ).ready(function() {
         $('input[id="country"]').on('keyup', function() {  // on keyup event in your input field
                $("#needs").append(this.value);// append values from input field
          });
    );
6

Chấm trong tên biến đến

Thông thường, PHP không làm thay đổi tên của các biến khi chúng được chuyển thành một tập lệnh. Tuy nhiên, cần lưu ý rằng dấu chấm (thời gian, dừng hoàn toàn) không phải là một ký tự hợp lệ trong tên biến PHP. Vì lý do, hãy nhìn vào nó:

$( document ).ready(function() {
         $('input[id="country"]').on('keyup', function() {  // on keyup event in your input field
                $("#needs").append(this.value);// append values from input field
          });
    );
7

Bây giờ, những gì trình phân tích cú pháp nhìn thấy là một biến có tên $ varname, theo sau là toán tử nối chuỗi, theo sau là barestring (tức là chuỗi chưa được trích xuất không khớp với bất kỳ khóa nào đã biết hoặc từ dành riêng) 'ext'. Rõ ràng, điều này không có kết quả dự định.

Vì lý do này, điều quan trọng cần lưu ý là PHP sẽ tự động thay thế bất kỳ dấu chấm nào trong các tên biến đến với dấu gạch dưới.

Xác định các loại biến

Bởi vì PHP xác định các loại biến và chuyển đổi chúng (nói chung) khi cần thiết, không phải lúc nào cũng rõ ràng là loại nhất định nào là bất kỳ lúc nào. PHP bao gồm một số hàm tìm hiểu loại một biến nào là, chẳng hạn như: getType (), is_array (), is_float (), is_int (), is_object () và is_string (). Xem thêm Chương về các loại.gettype(), is_array(), is_float(), is_int(), is_object(), and is_string(). See also the chapter on Types.

HTTP là một giao thức văn bản, hầu hết, nếu không phải tất cả, nội dung đi kèm trong các mảng SuperGlobal, như $ _POST và $ _GET sẽ vẫn còn như chuỗi. PHP sẽ không cố gắng chuyển đổi các giá trị thành một loại cụ thể. Trong ví dụ dưới đây, $ _get ["var1"] sẽ chứa chuỗi "null" và $ _get ["var2"], chuỗi "123".

/index.php?var1=null&var2=123

Thay đổi

Phiên bảnSự mô tả
7.2.34, 7.3.23, 7.4.11 Tên của cookie đến không còn được mã hóa URL vì lý do bảo mật.

Ẩn danh ¶

14 năm trước

$( document ).ready(function() {
         $('input[id="country"]').on('keyup', function() {  // on keyup event in your input field
                $("#needs").append(this.value);// append values from input field
          });
    );
8

$( document ).ready(function() {
         $('input[id="country"]').on('keyup', function() {  // on keyup event in your input field
                $("#needs").append(this.value);// append values from input field
          });
    );
9

Name:
Email:
0

Krydprz tại IIT dot edu ¶

17 năm trước

Name:
Email:
1

Name:
Email:
2

Name:
Email:
3

Name:
Email:
4

Name:
Email:
5

Name:
Email:
6

Name:
Email:
7

Name:
Email:
8

Name:
Email:
9

0

1

2

3

4

5

6

Name:
Email:
0

TMK-PHP tại Infeline Dot org ¶

17 năm trước

8

9

Name:
Email:
0

Ẩn danh ¶

14 năm trước

/index.php?var1=null&var2=123
1

/index.php?var1=null&var2=123
2

Name:
Email:
0

Krydprz tại IIT dot edu ¶

17 năm trước

/index.php?var1=null&var2=123
4

TMK-PHP tại Infeline Dot org ¶

19 năm trước

/index.php?var1=null&var2=123
5

/index.php?var1=null&var2=123
6

/index.php?var1=null&var2=123
7

/index.php?var1=null&var2=123
8

/index.php?var1=null&var2=123
9

Name:
Email:
0

Anisgazis tại Gmail Dot Com ¶

14 năm trước

onchange1

onchange2

onchange3

onchange4

onchange5

onchange6

Name:
Email:
0

Krydprz tại IIT dot edu ¶

17 năm trước

onchange8

onchange9

Name:
Email:
0

TMK-PHP tại Infeline Dot org ¶

19 năm trước

onkeyup1

onkeyup2

onkeyup3

onkeyup4

Name:
Email:
0

Anisgazis tại Gmail Dot Com ¶

3 năm trước

onkeyup6

onkeyup7

Name:
Email:
0

Lennynyktyk tại Yahoo Dot Com ¶

14 năm trước

onkeyup9

echo $_POST['username'];
echo 
$_REQUEST['username'];
?>
0

echo $_POST['username'];
echo 
$_REQUEST['username'];
?>
1

echo $_POST['username'];
echo 
$_REQUEST['username'];
?>
2

echo $_POST['username'];
echo 
$_REQUEST['username'];
?>
3

echo $_POST['username'];
echo 
$_REQUEST['username'];
?>
4

Name:
Email:
0

Krydprz tại IIT dot edu ¶

17 năm trước

echo $_POST['username'];
echo 
$_REQUEST['username'];
?>
6

echo $_POST['username'];
echo 
$_REQUEST['username'];
?>
7

echo $_POST['username'];
echo 
$_REQUEST['username'];
?>
8

Name:
Email:
0

TMK-PHP tại Infeline Dot org ¶

17 năm trước

QUERY_STRING0

QUERY_STRING1

QUERY_STRING2

Name:
Email:
0

TMK-PHP tại Infeline Dot org ¶

14 năm trước

QUERY_STRING4

QUERY_STRING5

Name:
Email:
0

Krydprz tại IIT dot edu ¶

17 năm trước

QUERY_STRING7

QUERY_STRING8

Name:
Email:
0

TMK-PHP tại Infeline Dot org ¶

19 năm trước

http://www.example.com/test.php?id=30

http://www.example.com/test.php?id=31

http://www.example.com/test.php?id=32

Name:
Email:
0

Anisgazis tại Gmail Dot Com ¶

17 năm trước

http://www.example.com/test.php?id=34

http://www.example.com/test.php?id=35

Name:
Email:
0

TMK-PHP tại Infeline Dot org ¶

17 năm trước

http://www.example.com/test.php?id=37

http://www.example.com/test.php?id=38

http://www.example.com/test.php?id=39

Name:
Email:
0

TMK-PHP tại Infeline Dot org ¶

19 năm trước

$( document ).ready(function() {
         $('input[id="country"]').on('keyup', function() {  // on keyup event in your input field
                $("#needs").append(this.value);// append values from input field
          });
    );
01

$( document ).ready(function() {
         $('input[id="country"]').on('keyup', function() {  // on keyup event in your input field
                $("#needs").append(this.value);// append values from input field
          });
    );
02

$( document ).ready(function() {
         $('input[id="country"]').on('keyup', function() {  // on keyup event in your input field
                $("#needs").append(this.value);// append values from input field
          });
    );
03

$( document ).ready(function() {
         $('input[id="country"]').on('keyup', function() {  // on keyup event in your input field
                $("#needs").append(this.value);// append values from input field
          });
    );
04

$( document ).ready(function() {
         $('input[id="country"]').on('keyup', function() {  // on keyup event in your input field
                $("#needs").append(this.value);// append values from input field
          });
    );
05

$( document ).ready(function() {
         $('input[id="country"]').on('keyup', function() {  // on keyup event in your input field
                $("#needs").append(this.value);// append values from input field
          });
    );
06

$( document ).ready(function() {
         $('input[id="country"]').on('keyup', function() {  // on keyup event in your input field
                $("#needs").append(this.value);// append values from input field
          });
    );
07

$( document ).ready(function() {
         $('input[id="country"]').on('keyup', function() {  // on keyup event in your input field
                $("#needs").append(this.value);// append values from input field
          });
    );
08

$( document ).ready(function() {
         $('input[id="country"]').on('keyup', function() {  // on keyup event in your input field
                $("#needs").append(this.value);// append values from input field
          });
    );
09

Name:
Email:
0

Anisgazis tại Gmail Dot Com ¶

19 năm trước

$( document ).ready(function() {
         $('input[id="country"]').on('keyup', function() {  // on keyup event in your input field
                $("#needs").append(this.value);// append values from input field
          });
    );
11

$( document ).ready(function() {
         $('input[id="country"]').on('keyup', function() {  // on keyup event in your input field
                $("#needs").append(this.value);// append values from input field
          });
    );
12

$( document ).ready(function() {
         $('input[id="country"]').on('keyup', function() {  // on keyup event in your input field
                $("#needs").append(this.value);// append values from input field
          });
    );
13

$( document ).ready(function() {
         $('input[id="country"]').on('keyup', function() {  // on keyup event in your input field
                $("#needs").append(this.value);// append values from input field
          });
    );
14

Anisgazis tại Gmail Dot Com ¶

3 năm trước

$( document ).ready(function() {
         $('input[id="country"]').on('keyup', function() {  // on keyup event in your input field
                $("#needs").append(this.value);// append values from input field
          });
    );
15

$( document ).ready(function() {
         $('input[id="country"]').on('keyup', function() {  // on keyup event in your input field
                $("#needs").append(this.value);// append values from input field
          });
    );
16

Name:
Email:
0

Lennynyktyk tại Yahoo Dot Com ¶

19 năm trước

$( document ).ready(function() {
         $('input[id="country"]').on('keyup', function() {  // on keyup event in your input field
                $("#needs").append(this.value);// append values from input field
          });
    );
18

$( document ).ready(function() {
         $('input[id="country"]').on('keyup', function() {  // on keyup event in your input field
                $("#needs").append(this.value);// append values from input field
          });
    );
19

$( document ).ready(function() {
         $('input[id="country"]').on('keyup', function() {  // on keyup event in your input field
                $("#needs").append(this.value);// append values from input field
          });
    );
20

Name:
Email:
0

Anisgazis tại Gmail Dot Com ¶

17 năm trước

$( document ).ready(function() {
         $('input[id="country"]').on('keyup', function() {  // on keyup event in your input field
                $("#needs").append(this.value);// append values from input field
          });
    );
22

$( document ).ready(function() {
         $('input[id="country"]').on('keyup', function() {  // on keyup event in your input field
                $("#needs").append(this.value);// append values from input field
          });
    );
23

$( document ).ready(function() {
         $('input[id="country"]').on('keyup', function() {  // on keyup event in your input field
                $("#needs").append(this.value);// append values from input field
          });
    );
24

$( document ).ready(function() {
         $('input[id="country"]').on('keyup', function() {  // on keyup event in your input field
                $("#needs").append(this.value);// append values from input field
          });
    );
25

$( document ).ready(function() {
         $('input[id="country"]').on('keyup', function() {  // on keyup event in your input field
                $("#needs").append(this.value);// append values from input field
          });
    );
26

TMK-PHP tại Infeline Dot org ¶

14 năm trước

$( document ).ready(function() {
         $('input[id="country"]').on('keyup', function() {  // on keyup event in your input field
                $("#needs").append(this.value);// append values from input field
          });
    );
27

$( document ).ready(function() {
         $('input[id="country"]').on('keyup', function() {  // on keyup event in your input field
                $("#needs").append(this.value);// append values from input field
          });
    );
28

$( document ).ready(function() {
         $('input[id="country"]').on('keyup', function() {  // on keyup event in your input field
                $("#needs").append(this.value);// append values from input field
          });
    );
29

$( document ).ready(function() {
         $('input[id="country"]').on('keyup', function() {  // on keyup event in your input field
                $("#needs").append(this.value);// append values from input field
          });
    );
30

$( document ).ready(function() {
         $('input[id="country"]').on('keyup', function() {  // on keyup event in your input field
                $("#needs").append(this.value);// append values from input field
          });
    );
31

Name:
Email:
0

Krydprz tại IIT dot edu ¶

19 năm trước

$( document ).ready(function() {
         $('input[id="country"]').on('keyup', function() {  // on keyup event in your input field
                $("#needs").append(this.value);// append values from input field
          });
    );
33

$( document ).ready(function() {
         $('input[id="country"]').on('keyup', function() {  // on keyup event in your input field
                $("#needs").append(this.value);// append values from input field
          });
    );
34

$( document ).ready(function() {
         $('input[id="country"]').on('keyup', function() {  // on keyup event in your input field
                $("#needs").append(this.value);// append values from input field
          });
    );
35

$( document ).ready(function() {
         $('input[id="country"]').on('keyup', function() {  // on keyup event in your input field
                $("#needs").append(this.value);// append values from input field
          });
    );
36

$( document ).ready(function() {
         $('input[id="country"]').on('keyup', function() {  // on keyup event in your input field
                $("#needs").append(this.value);// append values from input field
          });
    );
37

$( document ).ready(function() {
         $('input[id="country"]').on('keyup', function() {  // on keyup event in your input field
                $("#needs").append(this.value);// append values from input field
          });
    );
38

$( document ).ready(function() {
         $('input[id="country"]').on('keyup', function() {  // on keyup event in your input field
                $("#needs").append(this.value);// append values from input field
          });
    );
39

Name:
Email:
0

Anisgazis tại Gmail Dot Com ¶

17 năm trước

$( document ).ready(function() {
         $('input[id="country"]').on('keyup', function() {  // on keyup event in your input field
                $("#needs").append(this.value);// append values from input field
          });
    );
41

$( document ).ready(function() {
         $('input[id="country"]').on('keyup', function() {  // on keyup event in your input field
                $("#needs").append(this.value);// append values from input field
          });
    );
42

Name:
Email:
0

Anisgazis tại Gmail Dot Com ¶

5 năm trước

$( document ).ready(function() {
         $('input[id="country"]').on('keyup', function() {  // on keyup event in your input field
                $("#needs").append(this.value);// append values from input field
          });
    );
44

$( document ).ready(function() {
         $('input[id="country"]').on('keyup', function() {  // on keyup event in your input field
                $("#needs").append(this.value);// append values from input field
          });
    );
45

Name:
Email:
0

Làm thế nào tôi có thể nhận được giá trị trường đầu vào trong PHP mà không cần gửi?

PHP $ a = $ _get ["housemodel"]; if ($ a '') {if ($ a == $ model1) {echo ""; } if if ($ a == $ model2) {echo ""; } if if ($ a == $ model3) {echo ""; ...

Làm thế nào để chúng tôi nhận được giá trị hộp văn bản trong một biến PHP mà không cần một nút gửi hoặc nhấp?

trên ('keyUp', function () {// trên sự kiện keyup trong trường đầu vào của bạn $ ("#nhu cầu").);Bạn muốn lưu giá trị này trong biến PHP thì bạn cần gọi AJAX (mà không gửi biểu mẫu của bạn) hoặc bạn cần gửi biểu mẫu. append(this. value);// append values from input field }); ); You want to save this value in a php variable then you need ajax call(without submitting your form) or you need to submit the form.

$ _ Trong PHP là gì?

PHP $ _POST là một biến siêu toàn cầu PHP được sử dụng để thu thập dữ liệu biểu mẫu sau khi gửi biểu mẫu HTML với Phương thức = "Post".$ _POST cũng được sử dụng rộng rãi để vượt qua các biến.a PHP super global variable which is used to collect form data after submitting an HTML form with method="post". $_POST is also widely used to pass variables.

Biến $$ trong PHP là gì?

PHP |$ vs $$ toán tử $ var_name = "Hello World!";$ Var_name là một biến bình thường được sử dụng để lưu trữ một giá trị.Nó có thể lưu trữ bất kỳ giá trị nào như Integer, Float, Char, String, v.v. Mặt khác, $$ var_name được gọi là biến tham chiếu trong đó $ var_name là một biến bình thường.reference variable where $var_name is a normal variable.