How to use PHP redux?
[registervistor.html]
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 | <p> Userid: <input type="text" name="userid" size="20" maxlength="80" value="" /> </p> <p> Password: <input type="password" name="password" size="20" maxlength="80" value="" /> </p> <p> Name: <input type="text" name="name" size="20" maxlength="40" value="" /> </p> <p> Gender: <input type="radio" name="gender" value="Male">Male <input type="radio" name="gender" value="Female">Female </p> <p> <!-- Write codes to add in the dropdown lists for birthday --> Birthday: <select name="Day"> \t<option selected="">Please Select</option> \t<option value="1">01</option> \t<option value="2">02</option> \t<option value="3">03</option> \t<option value="4">04</option> \t<option value="5">05</option> \t<option value="6">06</option> \t<option value="7">07</option> \t<option value="8">08</option> \t<option value="9">09</option> \t<option value="10">10</option> \t<option value="11">11</option> \t<option value="12">12</option> \t<option value="13">13</option> \t<option value="14">14</option> \t<option value="15">15</option> \t<option value="16">16</option> \t<option value="17">17</option> \t<option value="18">18</option> \t<option value="19">19</option> \t<option value="20">20</option> \t<option value="21">21</option> \t<option value="22">22</option> \t<option value="23">23</option> \t<option value="24">24</option> \t<option value="25">25</option> \t<option value="26">26</option> \t<option value="27">27</option> \t<option value="28">28</option> \t<option value="29">29</option> \t<option value="30">30</option> \t<option value="31">31</option> </select> <select name="Month"> \t<option selected="">Please Select</option> \t<option value="January">January</option> \t<option value="February">February</option> \t<option value="March">March</option> \t<option value="April">April</option> \t<option value="May">May</option> \t<option value="June">June</option> \t<option value="July">July</option> \t<option value="August">August</option> \t<option value="September">September</option> \t<option value="October">October</option> \t<option value="November">November</option> \t<option value="December">December</option> </select> <input type="number" min="1960" max="2014" name="Year" size="4" maxlength="4" value="Year" /> </p> <p><center>[wp_ad_camp_2]</center></p><p> Categories: <input type="checkbox" name="categories[]" value="Appetising Starters!">Appetising Starter <input type="checkbox" name="categories[]" value="Main Courses!">Main Course <input type="checkbox" name="categories[]" value="Refreshing Drink!">Refreshing Drink <input type="checkbox" name="categories[]" value="Yummy Desserts!">Yummy Dessert </p> |
我想在与用户使用PHP Redux输入数据的表单相同的页面上显示错误消息,但我不知道该怎么做。 我希望这些代码显示在registervistor.html中,而不是vistorprofile.php中。 有人可以帮我吗?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 | <?php if (!empty($_POST['name'])){ $name = $_POST['name']; } else { $name = NULL; echo"<p> You forgot to enter your name! </p>"; } if (!empty($_POST['userid'])) { $userid=$_POST['userid']; } else { $userid = NULL; echo"<p> You forgot to enter your user ID! </p>"; } if (!empty($_POST['password'])){ $password = $_POST['password']; } else { $password = NULL; echo"<p><center>[wp_ad_camp_3]</center></p><p> You forgot to enter your password! </p>"; } if (!empty($_POST['gender'])){ $gender = $_POST['gender']; } else { $gender = NULL; echo"<p> You forgot to enter your gender! </p>"; } // A null in birth date keeps appearing even if the details are key in // if (!empty($_POST['Day'])){ $Day = $_POST['Day']; } else { $Day = NULL; echo"<p> You forgot to enter your birth date! </p>"; } if (!empty($_POST['Month'])){ $Month = $_POST['Month']; } else { $Month = NULL; echo"<p> You forgot to enter your birth month! </p>"; } if (is_numeric($_POST['Year'])){ $Year = $_POST['Year']; } else { $Year = NULL; echo"<p> You forgot to enter your birth year! </p>"; } if (isset($_POST['categories'])){ $categories = $_POST['categories']; } else { $categories = NULL; echo"<p> You forgot to indicate your categories! </p>"; } if ($userid && $password && $name && $gender && $Day && $Month && $Year && $categories) { echo"$name, thank you for registering with us!"; echo"You have entered the following details:"; echo"UserID: $userid"; echo"Gender: $gender"; echo"Birthday: $Day / $Month / $Year"; echo"Categories:"; foreach ($categories as $value){ echo"$value"; } echo"<p> Please Click Here to continue viewing the recipes! </p>"; } else { echo"<p> Please Click Here to go back to fill in the form again! </p>"; } echo""; ?> |
我建议您使用jquery表单验证:
http://jqueryvalidation.org/documentation/
在html文件中运行php内容,详细信息:
如何在html文件中运行php脚本?
但是您可以使用jquery / ajax表单提交,.html文件中的表单以及php文件中的所有验证:
PHP的jQuery Ajax POST示例
的HTML
1 2 3 4 5 6 | <form id="foo"> <label for="bar">A bar</label> <input id="bar" name="bar" type="text" value="" /> <input type="submit" value="Send" /> </form> |
Java脚本
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 | // Variable to hold request var request; // Bind to the submit event of our form $("#foo").submit(function(event){ // Abort any pending request if (request) { request.abort(); } // setup some local variables var $form = $(this); // Let's select and cache all the fields var $inputs = $form.find("input, select, button, textarea"); // Serialize the data in the form var serializedData = $form.serialize(); // Let's disable the inputs for the duration of the Ajax request. // Note: we disable elements AFTER the form data has been serialized. // Disabled form elements will not be serialized. $inputs.prop("disabled", true); // Fire off the request to /form.php request = $.ajax({ url:"/form.php", type:"post", data: serializedData }); // Callback handler that will be called on success request.done(function (response, textStatus, jqXHR){ // Log a message to the console console.log("Hooray, it worked!"); }); // Callback handler that will be called on failure request.fail(function (jqXHR, textStatus, errorThrown){ // Log the error to the console console.error( "The following error occurred:"+ textStatus, errorThrown ); }); // Callback handler that will be called regardless // if the request failed or succeeded request.always(function () { // Reenable the inputs $inputs.prop("disabled", false); }); // Prevent default posting of form event.preventDefault(); }); |
在PHP文件中
1 2 3 | // You can access the values posted by jQuery.ajax // through the global variable $_POST, like this: $bar = $_POST['bar']; |
(从最后一个链接复制粘贴)
希望对您有所帮助。