简体   繁体   English

如何将文本框的值分配给变量?

[英]How do I assign the value of a textbox to a variable?

How do I assign the value of a textbox to a variable? 如何将文本框的值分配给变量?

Here is my form: 这是我的表格:

<form id="" method="post" action="photo_upload.php" enctype="multipart/form-data">
<table align="center" cellpadding="0" cellspacing="0" border="0" width="650px">
  <tr>
  <td colspan="7">
  <input type="text" id="albumName" name="albumName" value="jaghamachi"/>  
  </td>
  </tr>
  <tr>
  <td width="50px" align="center"/>
  <td align="center" width="100px">Upload Pics::</td>
  <td align="center" width="50px"/>
  <td align="center" width="200px">
      <input type="file" id="file" name="file"/>
  </td>
  <td align="center" width="50px"/>
  <td align="center" width="100px">
      <input type="submit" name="submit" id="submit" value="submit" class="button" style="width: 100px;" />
  </td>
  <td align="center" width="50px"/>   
  <tr>
  <td height="16px"/>
  </tr>
  </table>
  </form>
<?php
// here i want a code similar to string str = Text1.Text like in .net;
//i want a code smthng like this 
//$value= albumName.value; how to do it?? here albumName is the textbox type in above form
?>

How can it be done, without using javascript or jquery? 不使用javascript或jquery怎么办?

You can do it like this: 您可以这样做:

$albumName = $_POST['albumName'];

Here: 这里:

  • $albumName is the variable name containing value of text box named albumName $albumName是变量名称,其中包含名为albumName的文本框的值
  • $POST is the form method POST eg <form method="POST" $POST是表单方法POST例如<form method="POST"

Note 1: For that to work, it is assumed that you submit the form first. 注意1:为此,假定您首先提交表单。

Note 2: To submit to same page, set action attribute of <form> tag to empty 注意2:要提交到同一页面,请将<form>标记的action属性设置为空

您唯一可以做的就是发布表单,以及$_POST的值

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM