テキスト フィールドをフォームに動的に追加していますが、これらの値を mysql データベースに保存できるようにする必要があります。動的に作成されたフィールドがない場合、これを行うことができます。ここにコードがあります -
<!DOCTYPE HTML>
<html>
<head>
<title> Company Value form </title>
<script language = "javascript">
function addTextField(){
var element = document.createElement("input");
element.setAttribute("name", "i");
element.setAttribute("value", "sample value");
element.setAttribute("size", 30);
var twitter = document.getElementById("twitterusernames");
twitter.appendChild(element);
}
</script>
</head>
<body>
<h1> Enter the values </h1>
<form method = "post" name = "config_form" action = "message.php">
<table border = "1px" >
<tr> <td>
<b> Twitter </b> <br/> <br/>
FeatureId: <input type = "text" name = "FeatureId"> <br/>
Image: <input type = "text" name = "Image"> <br/>
LabelEn: <input type = "text" name = "LabelEn"> <br/>
LabelFr: <input type = "text" name = "LabelFr"> <br/>
URL: <input type = "text" name = "URL"> <br/>
TwitterUserNames: <input type = "text" name = "TwitterUserName" size = "50">
<input type = "button" value = "Add" onclick = "addTextField()"/>
<span id="twitterusernames"> </span>
<br/>
Minimum Count: <input type = "text" name = "MinimumCount"> <br/>
Refresh Count: <input type = "text" name = "RefreshCount"> <br/>
EmptyMessage English: <input type = "text" name = "EmptyMessageEnglish"> <br/>
EmptyMessage French: <input type = "text" name = "EmptyMessageFrench"> <br/>
Widget: <input type = "text" name = "Widget"> <br/>
Email Share Text: <input type = "text" name = "EmailShareText"> <br/>
</td> </tr>
</table>
<input type="submit" value="Submit">
</form>
</body>
</html>
そしてPHPコード:
<?php
include 'database.php';
$Twitter = array(
'FeatureId' => $_POST["FeatureId"],
'Image' => $_POST["Image"],
'LabelEn' => $_POST["LabelEn"],
'LabelFr' => $_POST["LabelFr"],
'URL' => $_POST["URL"],
'TwitterUserName' => $_POST["TwitterUserName"],
'MinimumCount' => $_POST["MinimumCount"],
'RefreshCount' => $_POST["RefreshCount"],
'EmptyMessageEnglish' => $_POST["EmptyMessageEnglish"],
'Widget' => $_POST["Widget"],
'EmailShareText' => $_POST["EmailShareText"]
);
$crud = new database();
$insert = $crud -> insert($Twitter);
if ($insert) {
echo "Success";
}
else {
echo "Values were not inserted into the database";
}
?>