• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 199
  • Last Modified:

Code Issue

Is there any way to edit this code so the user will get a pop up box if the enter a date other than in the format YYYY-MM-DD for the date_disclo_att field?

I have some javascript code on lines 120-129  but it is not working. Can someone help me out?
<b> <p> <i> To go to the main page <a href="http://tnep-g-psrflow/flow/index.html">click here</a>.</p> </i>


<?php # edit_dqa.php

$page_title = 'Edit a Record';

$con = mysql_connect("localhost","username","password");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("psrflow", $con);

ini_set('display_errors',1); 
error_reporting(E_ALL);


if ( (isset($_GET['id'])) && (is_numeric($_GET['id'])) ) { 
	$id = $_GET['id'];
} elseif ( (isset($_POST['id'])) && (is_numeric($_POST['id'])) ) { 
	$id = $_POST['id'];
} else { // No valid ID, kill the script.
	echo '<h1 id="mainhead">Page Error</h1>
	<p class="error">This page has been accessed in error.</p><p><br /><br /></p>';
	include ('./includes/footer.html'); 
	exit();
}

if (isset($_POST['submitted'])) {

	$errors = array(); 

	if (empty($_POST['pacts'])) {
		$errors[] = 'You forgot to enter your PACTS number. If there is no PACTS # you can enter 0000';
	} else {
		$pt = $_POST['pacts'];
	}
	
	if (empty($_POST['fname'])) {
		$errors[] = 'You forgot to enter the first name.';
	} else {
		$fn = $_POST['fname'];
	}
	
	if (empty($_POST['lname'])) {
		$errors[] = 'You forgot to enter the last name.';
	} else {
		$ln = $_POST['lname'];
	}

		if (empty($_POST['date_sub_crt'])) {
		$errors[] = 'You forgot to enter a date submitted to office!.';
	} else {
		$crt = $_POST['date_sub_crt'];
	}
	
		if (empty($_POST['date_disclo_att'])) {
		$errors[] = 'You forgot to enter the supervisor disclosure date!';
	} else {
		$disc = $_POST['date_disclo_att'];
	}
		
	if (empty($errors)) { 
		
	$query = "UPDATE psrinfo SET pacts='$pt', fname='$fn', lname='$ln', date_sub_crt='$crt', date_disclo_att='$disc' WHERE fid=$id";
	$result = @mysql_query ($query); // Run the query.
		
$EmailAddress = 'email@yahoo.com';	
$Message = "A clerk has entered a 'Date Submitted to supervisor or office'. Please enter/edit this information in PACTS.\n \n PACTS No : ${_REQUEST['pacts']}\n First Name : ${_REQUEST['fname']} \n Last Name : ${_REQUEST['lname']} \n Date Submitted to office : ${_REQUEST['date_sub_crt']} \n Date Dislosed to supervisor : ${_REQUEST['date_disclo_att']} ";	
$Subject  = "A Clerk has Edited a Record.";
$Headers = "From: PODDS@yahoo.com \n"; 

if (mail($EmailAddress, $Subject, $Message, $Headers)) {
				
echo "<p><center><h2>My Office</h2></center></p>";
echo "<p><h3><center>Eastern District</center></h3></p>";
echo "<center>An email has been sent to your supervisor for approval and "; 
 
} else { 
 
echo "This system is not working properly. Please contact IT so they can fix it."; 
 
} 		
		
$url = 'http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']);
if ((substr($url, -1) == '/') OR (substr($url, -1) == '//')) {
$url = substr ($url, 0, -1);
}
$url ='/flow/index.html'; 

header("Location: $url");

exit();

		
	} else { // Report the errors.
	
		echo '<h1 id="mainhead">Error!</h1>
		<p class="error">The following error(s) occurred:<br />';
		foreach ($errors as $msg) { // Print each error.
			echo " - $msg<br />\n";
		}
		echo '</p><p>Please try again.</p><p><br /></p>';
		
	} 

} 

$query = "SELECT pacts, fname, lname, date_sub_crt, date_disclo_att, date_disclo_att FROM psrinfo WHERE fid = " . $_REQUEST['id'];
$result = @mysql_query ($query); // Run the query.

if (mysql_num_rows($result) == 1) { 

	$row = mysql_fetch_array ($result, MYSQL_NUM);
		
?>

<script type="text/javascript"> 
function checkme() {  
  if(!document.forms[0].date_disclo_att.value.match(/\d{4}-\d{1,2}-\d{1,2}/)) { 
		alert("ATTENTION: Please enter your start date in the format yyyy-mm-dd."); 
		document.forms[0].date_of_training_start.focus();   
		return(false); 
		}

else {return true}
</script>
	

<?php

echo '<form action="clerk_edit.php" method="post">
<fieldset><legend><h2> You are editing a record! After submitting this form, your DQA will be notified of the change via email.</h2></legend>

<b>PACTS No:</b> <br><input type="text" name="pacts" size="15" maxlength="30" value="'.$row[0].'" /><br>
<b>First Name:</b> <br><input type="text" name="fname" size="15" maxlength="30" value="'.$row[1].'" /><br />
<b>Last Name:</b> <br><input type="text" name="lname" size="15" maxlength="30" value="'.$row[2].'" /><br />
<b>Submitted to office: </b><br><input type="text" name="date_sub_crt" size="15" maxlength="30" value="'.$row[3].'" /> <br>
<b>Submitted to supervisor: </b><br><input type="text" name="date_disclo_att" size="15" maxlength="30" value="'.$row[4].'" /> <br>
</fieldset>

<div align="left"><input type="submit" name="submit" value="Submit" /></div> 

<input type="hidden" name="submitted" value="TRUE" />
<input type="hidden" name="id" value="' . $id . '" />
</form>';

} else { // Not a valid user ID.
	echo '<h1 id="mainhead">Page Error</h1>
	<p class="error">This page has been accessed in error.</p><p><br /><br /></p>';
}

mysql_close(); // Close the database connection.

?>

Open in new window

0
wantabe2
Asked:
wantabe2
  • 4
  • 3
1 Solution
 
bklyn2001Commented:
this works for me.  instead of !documents..., try

function checkme() {  
  if(document.forms[0].date_disclo_att.value.match(/\d{4}-\d{1,2}-\d{1,2}/) == null) { 

Open in new window

[snip]
0
 
wantabe2Author Commented:
hmmm...still not working. Do I have it in the correct location in the code? I know the code is correct:

<script type="text/javascript">  
function checkme() {  
  if(!document.forms[0].date_disclo_att.value.match(/\d{4}-\d{1,2}-\d{1,2}/) == null) {  
        alert("ATTENTION: Please enter your start date in the format yyyy-mm-dd.");  
        document.forms[0].date_disclo_att.focus();    
        return(false);  
        }

else {return true}
</script>


But do I have it in the correct location?
0
 
bklyn2001Commented:
take out the ! from the if statement
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
wantabe2Author Commented:
Same thing...



<script type="text/javascript">  
function checkme() {  
  if(document.forms[0].date_disclo_att.value.match(/\d{4}-\d{1,2}-\d{1,2}/) == null) {  
        alert("ATTENTION: Please enter your start date in the format yyyy-mm-dd.");  
        document.forms[0].date_disclo_att.focus();    
        return(false);  
        }

else {return true}
</script>
0
 
wantabe2Author Commented:
When I click the submit button I need a box to pop up telling the user to input the date in the format YYYY-MM-DD if it is enetered in any other format...
0
 
wantabe2Author Commented:
???
0
 
bklyn2001Commented:
you need to add a submit handler to your FORM tag:

<form type="submit" ... onsubmit="return checkme()" />

Open in new window

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now