Oscar11 Posted January 4, 2014 Share Posted January 4, 2014 I am designing a site where, if the student is under 19, they get transferred to the client page. Where am I going wrong as it's not working. Should I use a checkbox or a radiobox? Many thanks This is my HTML code for the : <form name ="contactform" action="send_form_email.php" method="post"> <br><table width="900" border="0" align="center" cellpadding="3" cellspacing="0"><div align="center"><span class="style18">Student Enquiry Form</span></div> <tr> <td></td> <td align="left"> <input type="radio" class="radio" rel="clientdetails.php"> <?php if($("input[@name=under19]:checked").val()=="private"){attr("action"clientdetails.php");?>php <span class="style8"> The student is under 19</span></td> </tr> This is the PHP code: <?phpif(isset($_POST['email'])) { // CHANGE THE TWO LINES BELOW $email_to = "ftnby@yahoo.com"; $email_subject = "Tuition enquiry form"; }function died($error) { // your error code can go here echo "We're sorry, but there's errors found with the form you submitted.<br /><br />"; echo $error."<br /><br />"; echo "Please go back and fix these errors.<br /><br />"; } // your required code can go here if (empty($_POST["your_first_name"])) {$nameErr = "Name is required";} else {$name = test_input($_POST["name"]);} if (empty($_POST["your_surname"])) {$nameErr = "Name is required";} else {$name = test_input($_POST["name"]);} if (empty($_POST["email"])) {$emailErr = "Email is required";} else {$email = test_input($_POST["email"]);} if (empty($_POST["home_address"])) {$nameErr = "Address is required";} else {$name = test_input($_POST["address"]);} if (empty($_POST["post_code"])) {$nameErr = "Post code is required";} else {$name = test_input($_POST["post_code"]);} if (empty($_POST["landline_number"])) {$numberErr = "Please provide a Landline or Mobile number";} else {$number = test_input($_POST["comment"]);} if (empty($_POST["students_first_name"])) {$nameErr = "Name is required";} else {$name = test_input($_POST["name"]);} if (empty($_POST["students_surname"])) {$nameErr = "Name is required";} else {$name = test_input($_POST["name"]);} if (empty($_POST["subject_required"])) {$nameErr = "Subject is required";} else {$name = test_input($_POST["name"]);} if (empty($_POST["level_of_study"])) {$nameErr = "Level_of_Study is required";} else {$name = test_input($_POST["name"]);} Quote Link to comment Share on other sites More sharing options...
Ch0cu3r Posted January 4, 2014 Share Posted January 4, 2014 (edited) this will never work <?php if($("input[@name=under19]:checked").val()=="private") { attr("action"clientdetails.php"); You cannot mix javascript (JQuery) code together with PHP code. They are completely different languages and both run at completely different times. PHP is ran on the server, but. Javascript runs in the browser long after PHP had parsed the script. You have two options when the checkbox is checked have JQuery submit the form to another page. Or Redirect the user to the other page when PHP processes the form. Edited January 4, 2014 by Ch0cu3r Quote Link to comment Share on other sites More sharing options...
eldan88 Posted January 4, 2014 Share Posted January 4, 2014 Are you using trying to accomplish this with jquery? If so you can add a value to your radio option named "19" and add an if condition of that value has been selected by using PHP only and not jQuery. Quote Link to comment Share on other sites More sharing options...
hansford Posted January 6, 2014 Share Posted January 6, 2014 Use a little jQuery to change the action attribute of the form upon submit. $(document).ready(function() { if($('#age_form').length > 0) { $('#age_form').submit(function() { if($('#youngster:checked').val() == true) { $('#age_form').attr('action','http://127.0.0.1/test_page_3.php'); } else { $('#age_form').attr('action','http://127.0.0.1/test_page_2.php'); } }); } }); Don't forget to add jQuery link in the head of your form: <head> <script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script> </head> Here is a sample form: <form id="age_form" method="post" action=""> Under 19 years of age: <input type="radio" name="age_restriction" id="youngster" value="young" /><br /> 19 years of age or older: <input type="radio" name="age_restriction" value="old" checked /><br /> <input type="submit" value="submit"/> </form> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.