Avatar of wantabe2
wantabe2Flag for United States of America

asked on 

PHP or Jscript Required Field

Is there any way for me to make the "employee" field on lines 87-91 be a required field? This is actually a test & if it is filled out without the user choosing an option from the question on line 87 it will not work correctly....

I'm thinking I'll need some kind of javascript code in addition the the existing PHP code but am not familair with jscript...can someone help me out? Basically, I just need a pop up box to apear prompting the user to enter something in the "Who's your employee?" field if they clcik on the first question on line 104 & have not chose anything  on line 87. Thanks
<html>  

<head>
<body style="background-image:url(FadedBG.png); background-repeat:no-repeat; background-attachment:fixed; background-position:center;">
<html>
<head>
<title> PCRA </title>
</head>
</html>

<?php
ini_set('display_errors',1);
error_reporting(E_ALL);

if( isset($_POST) && !empty($_POST) )
{
     $host	= "localhost";
     $user	= "uname";
     $pw	= "password";
     $db	= "pcra";
          
     $conn = mysql_connect( $host, $user, $pw )
     or die( "Error! Unable to connect to database server: <br/>" . mysql_error() );

     $rs = mysql_select_db( $db, $conn )
     or die( "Error! Unable to connect to database:  <br/>" . mysql_error() );
          
	foreach($_POST as $key=>$value)
	{
		${$key}=mysql_real_escape_string($value);
	}
	
     $strSQL = "INSERT INTO offender_test
     	( fname, lname, pacts, tdate, employee, question1, question2, question3 )
     	VALUES
     	( '" . $fname . "', '" .$lname . "', '" . $tdate . "', '" . $employee . "', '" . $question1 . "', '" . $question2 . "', '" . $question3 . "' )";
	 	 	 
   


	 switch($_REQUEST['employee']) { 
case "Employee1":
$Email = "employee1@yahoo.org";
break;
case "Employee2":
$Email = "employee2@yahoo.org";
break;
default:
echo "Error, no employee selected!!!";
break;  
}

$Message = "The below has successfully completed the PCRA test.\n \nTest Date : ${_REQUEST['tdate']}\nOffender Name : ${_REQUEST['fname']} ${_REQUEST['lname']} \nemployee : ${_REQUEST['employee']} \n\nQuestion 1 : I will allow nothing to get in the way of me getting what I want......(Answer ${_REQUEST['question1']}) \n\nQuestion 2 : I find myself blaming society and external circumstances for the problems I have had in life......(Answer ${_REQUEST['question2']}) ";
$Subject  = "An Person Has Finished The PCRA Test";
$Headers = "From: PCRA@google.com \n"; 

 	if (mail($Email, $Subject, $Message, $Headers)) 
						


	if (!mysql_query( $strSQL, $conn )){
     	echo( "Unable to save data to database: <br/>" . mysql_error() . "<br/>" . $strSQL . "</span><br/>" );
     }
     else{
     	header( "Location: submitted.html" );
		exit;
     }
	 	 
}


?>

<form method="post" action="thetest.php">

<table width="95%" border="4">

<b><u> <h2>PCRA Section</h2></b></u>
<tr>
<td><b>First Name:</b> <br><input type="text" name="fname" size="20" maxlength="30"  /><br> </td>
<td><b>Last Name: </b><br><input type="text" name="lname" size="20" maxlength="30" /><br></td>
<td><b>Date</b><br><input  name = "tdate" id="todaysDate" value="<?php echo(date("Y-m-d")); ?>">  <br></td>
</tr>

<tr>
<td>
<b>Who's Your employee?<br> 
<select name="employee"> 
<option value=""></option>
<option value="Employee1">Employee1</option>
<option value="Employee2">Employee2</option>
</select> </td>

</tr>

<table width="95%" border="5">
<b><br><h5>Directions: The following items, if answered honestly, are designed to help you better understand your thinking and behavior. Please take the time to complete each of the 80 items on this inventory using the four-point scale defined below:</h5></b>
<b><h5>4 = Strongly Agree</b><br>
<b>3 = Agree</b><br>
<b>2 = Uncertain</b><br>
<b>1 = Disagree</b><br><br>

<tr>
<td><b>1. I will allow nothing to get in the way of me getting what I want......<br> <select name="question1" />  
<option value=""></option>
<option value="4">4</option>
<option value="3">3</option>
<option value="2">2</option>
<option value="1">1</option>
</select>
</tr>

<tr>
<td><b>2. I find myself blaming society and external circumstances for the problems I have had in life......<br> <select name="question2" />  
<option value=""></option>
<option value="4">4</option>
<option value="3">3</option>
<option value="2">2</option>
<option value="1">1</option>
</select>
</tr>

<tr>
<td><b>3. Change can be scary......<br> <select name="question3" />  
<option value=""></option>
<option value="4">4</option>
<option value="3">3</option>
<option value="2">2</option>
<option value="1">1</option>
</select>
</tr>

<tr>
</tr>

<td>
<input type="submit" value="SUBMIT TEST"/>
</td>
</form>

</body>
</html>

Open in new window

PHPJScriptJavaScript

Avatar of undefined
Last Comment
Sudhindra A N
ASKER CERTIFIED SOLUTION
Avatar of Sudhindra A N
Sudhindra A N
Flag of India image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
JavaScript
JavaScript

JavaScript is a dynamic, object-based language commonly used for client-side scripting in web browsers. Recently, server side JavaScript frameworks have also emerged. JavaScript runs on nearly every operating system and in almost every mainstream web browser.

127K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo