[英]PHP: Output submitted form text into hidden input field for submission again
[英]FORM input text to output text as specific link
我有一張表格,效果很好。 但是我想這樣轉換用戶輸入:
文本框:“用戶在此處寫一些東西。” ->單擊提交,現在將文本添加到表中的SQL數據庫中,但是現在已附加了HREF鏈接。 輸出” 用戶在這里寫一些東西。
讓我演示給你看:
<td nowrap="nowrap" align="right">*Brukernavn:</td>
<td><input type="text" name="brukernavn" value="" size="24" /></td>
</tr>
當用戶單擊提交時,我希望文本如下所示:
<a href="update.php?oppdaterID=<?php echo $row_persondata2['id']; ?>"> "USERS INPUT"
這是完整的代碼:
<?php require_once('Connections/pc.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
$insertSQL = sprintf("INSERT INTO pcbua (time, `navn`, brukernavn, `Type PC`, ServiceTAG, Kommentar, bruker, gruppe) VALUES (NOW(), %s, %s, %s, %s, %s, %s, %s)",
GetSQLValueString($_POST['navn'], "text"),
GetSQLValueString($_POST['brukernavn'], "text"),
GetSQLValueString($_POST['Type_PC'], "text"),
GetSQLValueString($_POST['ServiceTAG'], "text"),
GetSQLValueString($_POST['Kommentar'], "text"),
GetSQLValueString($_POST['bruker'], "text"),
GetSQLValueString($_POST['gruppe'], "text"));
mysql_select_db($database_pc, $pc);
$Result1 = mysql_query($insertSQL, $pc) or die(mysql_error());
}
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<body>
<p>Felt med * må fylles ut!</p>
<form action="<?php echo $editFormAction; ?>" method="post" name="form1" id="form1">
<table align="left">
<tr valign="baseline">
<td nowrap="nowrap" align="right">*Navn:</td>
<td><input type="text" name="navn" value="" size="24" />
</td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">*Brukernavn:</td>
<td><input type="text" name="brukernavn" value="" size="24" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">*PC-Modell:</td>
<td><select name="Type_PC">
<option value="" <?php if (!(strcmp("", 1))) {echo "selected=\"selected\"";} ?>></option>
<option value="Surface Pro 3" <?php if (!(strcmp("Surface Pro 3", 1))) {echo "selected=\"selected\"";} ?>>Surface Pro 3</option>
<option value="Lenovo 530W" <?php if (!(strcmp("Lenovo 530W", 1))) {echo "selected=\"selected\"";} ?>>Lenovo 530W</option>
<option value="Lenovo X220" <?php if (!(strcmp("Lenovo X220", 1))) {echo "selected=\"selected\"";} ?>>Lenovo X220</option>
<option value="MAC" <?php if (!(strcmp("MAC", 1))) {echo "selected=\"selected\"";} ?>>MAC</option>
</select></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">*Serienummer:</td>
<td><input type="text" name="ServiceTAG" value="" size="24" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">*Gruppe:</td>
<td><input type="text" name="gruppe" value="" size="24" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">Kommentar</td>
<td><input type="text" name="Kommentar" size="24" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">*Bruker</td>
<td><select name="bruker">
<option value="<?php global $current_user;
get_currentuserinfo();
echo '' . $current_user->user_login . "\n";?>" <?php if (!(strcmp("test", "ikke denne"))) {echo "selected=\"selected\"";} ?>>AutoMode</option>
</select>
</td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right"> </td>
<td><input type="submit" value="Tilknytt bruker" /></td>
</tr>
</table>
<input type="hidden" name="MM_insert" value="form1" />
</form>
<p>
<body>
</body>
</html>
像這樣:
if(isset($_POST['brukernavn'])){
echo "<a href='update.php?oppdaterID=".$_POST['brukernavn']."'>your link here</a>";
}
嘗試使用javascript
$(document).ready(function() { $("#mybutton").click(function(){ var val = $('#brukernavn').val(); $('#mydiv').html('<a href="update.php?oppdaterID='+val+'"> USERS INPUT</a>'); }); });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <td nowrap="nowrap" align="right">*Brukernavn:</td> <td><input type="text" name="brukernavn" id="brukernavn" value="" size="24" /></td> <td><input type="button" id="mybutton" name="click" value="click" /></td> </tr> <div id="mydiv"></div>
如果使用的是POST方法,則可以使用$ _POST ['brukernavn']在鏈接內顯示用戶輸入,如下所示:
<a href="update.php?oppdaterID=<?php echo $row_persondata2['id']; ?>"><?php echo $_POST['brukernavn']; ?></a>
您可以使用如下所示的javascript函數:
<script type="text/javascript">
function buildUrl() {
var str;
var myInput=document.getElementById("brukernavn");
str = myInput.value;
// and here you can build your URL using the variable str
}
</script>
不要忘記添加onclick =“ buildUrl();” 在您的提交按鈕中。 並在輸入文本中添加一個id屬性,以便可以識別它:
<td><input type="text" name="brukernavn" id="brukernavn" value="" size="24" /></td>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.