Jump to content

How do I enable another page to open if checkbox is checked


Oscar11

Recommended Posts

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:

 

<?php

if(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"]);}
    
  

Link to comment
Share on other sites

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 by Ch0cu3r
Link to comment
Share on other sites

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>
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.