Witam,
Zrobiłem sobie formularz z dodawaniem pól po kliknięciu na przycisk z obsługą:
<?php
require_once '../inc/config.inc.php';//konfiguracja
require_once "../lang/$lang.lang.php";//plik językowy
require_once '../inc/allfunctions.inc.php';
require_once '../inc/db.config.php';
$PHP_SELF = getnamefile();
if (!($conn=mysql_connect($db_hostname, $db_username, $db_password))) { print("$LANG[db_connect_error]"); error_log("$LANG[db_connect_error]", 3, "../log/db.log"); }
print("$LANG[db_select_error]"); error_log("$LANG[db_select_error]", 3, "../log/db.log"); }
$FORM = <<<FOTM
<head>
<script type="text/javascript">
<!--
function dodaj_element(kontener){
var znacznik = document.createElement('input');
znacznik.setAttribute('type', 'text');
znacznik.setAttribute('name', 'answer');
znacznik.className = 'input';
var kontener = document.getElementById(kontener);
kontener.appendChild(znacznik);
}
//-->
</script>
<style type="text/css">
<!--
input.input { display: block; }
-->
</style>
</head>
<body>
<form action="$PHP_SELF" method="post">
Lvl:<input type="text" name="lvl_id" /><br>
Question:<br>
<textarea name="question" rows="5" cols="20">
</textarea><br>
<div id="answers">
Answers:<br><input type="text" name="answer" class="input"/>
</div>
<div>
<input type="button" value="Dodaj odpowiedź" onclick="dodaj_element('answers');" />
</div>
<input type="hidden" name="IsSent" value="Yes" />
<button type="submit">Wyślij</button>
</form>
</body
FOTM;
If(IsSet($_POST['IsSent']) && $_POST['IsSent'] == 'Yes'){ If (IsSet($_POST['lvl_id']) && IsSet($_POST['answer']) && IsSet($_POST['question'])){
$query1 = "INSERT INTO Answers (ID, ID_lvl, Answer) VALUES('NULL', '$lvl_id', '$answer');";
$query2 = "INSERT INTO Levels (ID, ID_lvl, Question) VALUES('NULL', '$lvl_id','$question');";
}
else{
echo "$LANG[db_query_success]"; echo "<form action=\"$PHP_SELF\" method=\"post\"> <button type=\"submit\">Z powrotem</button>
</form>";
}
}
else{
echo "$LANG[db_query_success]"; echo "<form action=\"$PHP_SELF\" method=\"post\"> <button type=\"submit\">Z powrotem</button>
</form>";
}
}
}
else {
}
?>
Problemem jest to, że obsługuje tylko pierwsze pole niestety.
Jak to zrobić, aby obsłużył wszystkie pola?
Podgląd:
http://www.stw.net23.net/googleme_experime...ions.insert.phpPozdrawiam,
mlawnik
Ten post edytował mlawnik 22.06.2010, 14:51:11