建立我的第一个网站,但无法弄清楚这最后一位。 我RSVP形式有以下用户输入:1)一些客人在下拉选择菜单2)客人的姓名3)文本区域。 用户选择的号码后,客人姓名文本框动态显示的姓名输入。 一旦一切完成后,用户点击RSVP和PHP代码写入到文本文件。
问题:客户编号和文本区域写入罚款,但动态的客户名称框不获取传递到PHP。
我应该如何解决这个问题? 被乱投医。 任何帮助深表感谢。
<script> //--add numbers to the dropdown select menu and append the options to select--// $(function() { var $select = $("#selectguest"); for (i=1;i<=10;i++) { $select.append($('<option></option>').val(i).html(i)) } }); </script> <script type='text/javascript'> //--makes Next button responsive to number of guest input--// function addFields(){ // Number of inputs to create var number = document.getElementById("selectguest").value; // Container <div> where dynamic content will be placed var container = document.getElementById("guest_names"); // Clear previous contents of the container while (container.hasChildNodes()) { container.removeChild(container.lastChild); } for (i=0;i<number;i++){ // Append a node with a random text container.appendChild(document.createTextNode("Guest" + (i+1))); // Create an <input> element, set its type and name attributes var input = document.createElement("input"); input.type = "text"; input.name = "guestnames_' + i +'"; container.appendChild(input); // Append a line break container.appendChild(document.createElement("br")); } } </script>
<?php date_default_timezone_set("America/Vancouver"); //Make sure the file exists. touch('rsvp.txt'); //Check the length of the comments file. if ( filesize('rsvp.txt') < 50000 ) { //Get the user's message. $date = date('l, F jS Y, h:i:s A'); $guests = substr($_POST['guest_number'], 0, 2); $guests = htmlentities($guests); $guestnames = substr($_POST['guestnames'], 0, 20); $guestnames = htmlentities($guestnames); // Limit it to 2,000 characters. $message = substr($_POST['message'], 0, 2000); //Convert special characters to HTML entities. $message = htmlentities($message); //Append message to the RSVP file. $f = fopen('rsvp.txt', 'a'); fwrite($f, "\r\n$date\r\n$guests\r\n$guestnames\r\n$message\r\n"); fclose($f); } //Jump back to whichever page. header("refresh:3; index.html"); ?>
<form class="RSVPform" action="rsvp.php" method="post"> <div> <p>Please select the number of guests and enter their names. Once you're ready, click RSVP and you're all set!</p><br> <center>Number of Guests: <select id="selectguest" name="guest_number" onChange="addFields()"></select><br><div id="guest_names" name="guest_names"/></div><br><hr><p align="left"><font size=2>Have dietary preferences? Tell us in the message box below.</font></p><textarea id="text" placeholder="Leave a message for the bride & groom!" name="message" id="guest_message" rows="5" cols="48"></textarea><button type="submit" id="RSVP">RSVP</button></center> </div> </form>