|
Book Section

General Section

Other Sites

|
JavaScript Workshop Forums
| View previous topic :: View next topic |
| Author |
Message |
gjcluttrell New member

Joined: 05 Apr 2011 Posts: 1 Location: none
|
Posted: Tue Apr 05, 2011 11:12 am Post subject: Please Help! Code Issues |
|
|
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?
| Code: |
<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.
?>
|
|
|
| Back to top |
|
 |
phil karras Senior Member

Joined: 15 Jul 2002 Posts: 1776 Location: MD
|
Posted: Mon Oct 31, 2011 9:57 am Post subject: |
|
|
Yes I'm sure it can be done. The first thing I would do would be to check for the character '-' in the entered data, if it is not there give an error message.
next I would split on the '-' character & again if not enough items (3) I'd again give the error message.
Next, check the year for being > some year value, or convert it to a string & check that it's length is == 4 & not more or less. If it is NOT 4 then, once again the error message.
You can then also add checks that the month is >0 & <13 and that the day # is > 0 & < 32.
There are other things to check for if you want to get even more involved but that should get you going.
All of this could also be done in JavaScript on the client side BEFORE the page sends anything to the server. That's probably a good idea to reduce the back & forth between the client & server. Anyway, it's the way I would code it. _________________ Phil K
Circle Software Consulting
Test website: http://cs.yrex.com/
Guidelines for Posting: http://www.jsworkshop.com/posting.html
IHBAAA = It Has Been Asked And Answered
KISS: http://www.jsworkshop.com/bb/viewtopic.php?t=508 |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2002 phpBB Group
|
|
(c) 1997-2002 Starling Technologies and
Michael Moncur. Portions (c) Sams Publishing.
|
|
|