Jump to content

Recommended Posts

Below is code from a page that was developed using dreamweaver, php, mysql, and some javascript. The form validations work with the data entry form, but I want to validate the form when it is updated also. A lot of this code was written by another individual and/or autogenerated with dreamweaver. Could someone look at it to see if there is a way to get the ... onSubmit="return CheckRequiredFields()" form action to work?

 

<form action="<?php echo $editFormAction; ?>" method="POST" name="frmChangeProposalInfo" id="frmChangeProposalInfo" onSubmit="return CheckRequiredFields()">

 

 

 

<?php

//Connection statement

require_once('../../../Connections/PropDB.php');

 

//Aditional Functions

require_once('../../../includes/functions.inc.php');

 

// build the form action

$editFormAction = $HTTP_SERVER_VARS['PHP_SELF'] . (isset($HTTP_SERVER_VARS['QUERY_STRING']) ? "?" . $HTTP_SERVER_VARS['QUERY_STRING'] : "");

 

$varCID = $HTTP_GET_VARS['CID'];

$varYRS = $HTTP_GET_VARS['YRS'];

$varPID = $HTTP_GET_VARS['PID'];

 

if ((isset($HTTP_POST_VARS["MM_update"])) && ($HTTP_POST_VARS["MM_update"] == "frmChangeProposalInfo")) {

$updateSQL = sprintf("UPDATE Projects SET SentDate=%s, ProbPercent=%s, Amount=%s, TMorFixed=%s, AwardDate=%s, ProjectMgr=%s, BusID=%s, Outcome=%s, SFKOptions=%s, QA=%s, DataEnteredBy=%s, Title=%s, StatusDate=%s WHERE $varCID=CID and $varYRS=YRS and $varPID=PID",

GetSQLValueString($HTTP_POST_VARS['SentDate'], "date"),

GetSQLValueString($HTTP_POST_VARS['ProbPercent'], "int"),

GetSQLValueString($HTTP_POST_VARS['Amount'], "double"),

GetSQLValueString($HTTP_POST_VARS['TMorFixed'], "int"),

GetSQLValueString($HTTP_POST_VARS['AwardDate'], "date"),

GetSQLValueString($HTTP_POST_VARS['ProjectMgr'], "text"),

GetSQLValueString($HTTP_POST_VARS['BusinessArea'], "text"),

GetSQLValueString($HTTP_POST_VARS['Status'], "int"),

GetSQLValueString($HTTP_POST_VARS['SKFOptions'], "int"),

GetSQLValueString(isset($HTTP_POST_VARS['QA']) ? "true" : "", "defined","1","0"),

GetSQLValueString($HTTP_POST_VARS['DataEnteredBy'], "text"),

GetSQLValueString($HTTP_POST_VARS['Title'], "text"),

GetSQLValueString($HTTP_POST_VARS['StatusDate'], "date"));

 

$Result1 = $PropDB->Execute($updateSQL) or die($PropDB->ErrorMsg());

$updateGoTo = "/11_Accounting/ActiveProposalList/Forms/frmDisplayChangeProposalInfo.php";

if (isset($HTTP_SERVER_VARS['QUERY_STRING'])) {

$updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?";

$updateGoTo .= $HTTP_SERVER_VARS['QUERY_STRING'];

}

KT_redir($updateGoTo);

}

 

// begin Recordset

$varCID__ChangeProposalInfo = '-1';

if (isset($HTTP_GET_VARS['CID'])) {

$varCID__ChangeProposalInfo = $HTTP_GET_VARS['CID'];

}

$varYRS__ChangeProposalInfo = '-1';

if (isset($HTTP_GET_VARS['YRS'])) {

$varYRS__ChangeProposalInfo = $HTTP_GET_VARS['YRS'];

}

$varPID__ChangeProposalInfo = '-1';

if (isset($HTTP_GET_VARS['PID'])) {

$varPID__ChangeProposalInfo = $HTTP_GET_VARS['PID'];

}

$query_ChangeProposalInfo = sprintf("SELECT *, DATE_FORMAT(SentDate, '%%m/%%d/%%Y') AS Sdate, DATE_FORMAT(AwardDate, '%%m/%%d/%%Y') AS Adate, DATE_FORMAT(StatusDate, '%%m/%%d/%%Y') AS Statdate FROM Projects WHERE CID = %s and YRS = %s and PID = %s", $varCID__ChangeProposalInfo,$varYRS__ChangeProposalInfo,$varPID__ChangeProposalInfo);

$ChangeProposalInfo = $PropDB->SelectLimit($query_ChangeProposalInfo) or die($PropDB->ErrorMsg());

$totalRows_ChangeProposalInfo = $ChangeProposalInfo->RecordCount();

// end Recordset

 

// begin Recordset

$query_ProjectManagers = "SELECT * FROM Engineers WHERE Engineers.Active=1 ORDER BY Engineers.`EngineerName`";

$ProjectManagers = $PropDB->SelectLimit($query_ProjectManagers) or die($PropDB->ErrorMsg());

$totalRows_ProjectManagers = $ProjectManagers->RecordCount();

// end Recordset

 

// begin Recordset

$query_BusinessArea = "SELECT * FROM BusinessGroups";

$BusinessArea = $PropDB->SelectLimit($query_BusinessArea) or die($PropDB->ErrorMsg());

$totalRows_BusinessArea = $BusinessArea->RecordCount();

// end Recordset

 

// begin Recordset

$varCID__ClientList = '-1';

if (isset($HTTP_GET_VARS['CID'])) {

$varCID__ClientList = $HTTP_GET_VARS['CID'];

}

$query_ClientList = sprintf("SELECT * FROM ClientNumber WHERE ClientNo = %s", $varCID__ClientList);

$ClientList = $PropDB->SelectLimit($query_ClientList) or die($PropDB->ErrorMsg());

$totalRows_ClientList = $ClientList->RecordCount();

// end Recordset

//PHP ADODB document - made with PHAkt 2.7.1?>

<html>

<head>

 

<script language="JavaScript" type="text/JavaScript">

<!--VALIDATIONS

<!--

<!--Copyright 2003 Bontrager Connection, LLC

//Code obtained from http://WillMaster.com/

function CheckRequiredFields() {

var errormessage = new String();

// Put field checks below this point.

if(WithoutSelectionValue(document.frmChangeProposalInfo.ClientName))

{ errormessage += "\n\nPlease select the Client Name from the dropdown list."; }

if(WithoutContent(document.frmChangeProposalInfo.Title.value))

{ errormessage += "\n\nPlease enter a Project Title in the \"Project Title\" field."; }

if(WithoutSelectionValue(document.frmChangeProposalInfo.ProjectMgr))

{ errormessage += "\n\nPlease select a Project Manager from the dropdown list."; }

if(WithoutSelectionValue(document.frmChangeProposalInfo.BusinessArea))

{ errormessage += "\n\nPlease select the Business Area from the dropdown list."; }

if(WithoutContent(document.frmChangeProposalInfo.DataEnteredBy.value))

{ errormessage += "\n\nPlease enter a your initials in the \"Data Entered By\" field."; }

// Need to enter validation here for the numerical field Amount

if(ValidNumber(document.frmChangeProposalInfo.Amount))

{ errormessage += "\n\nPlease enter a valid number in the \"Amount\" field."; }

 

if(NoneWithCheck(document.frmChangeProposalInfo.TMorFixed))

{ errormessage += "\n\nPlease click one radio button under TM or Fixed?."; }

// Need to enter validation for two date fields here

if(ValidateDate(document.frmChangeProposalInfo.SentDate))

{ ; }

else

{ errormessage += "\n\nPlease enter a valid SENT DATE. The date format for the SENT DATE is: mm/dd/yyyy"; }

 

if(ValidateDate(document.frmChangeProposalInfo.AwardDate))

{ ; }

else

{ errormessage += "\n\nPlease enter a valid AWARD DATE. The date format for the AWARD DATE is: mm/dd/yyyy"; }

 

// Need to enter validation for the Probability field here

if(ValidProb(document.frmChangeProposalInfo.ProbPercent))

{ errormessage += "\n\nPlease enter a valid number in the \"Probability\" field."; }

if(NoneWithCheck(document.frmChangeProposalInfo.SKFOptions))

{ errormessage += "\n\nPlease click one radio button under SKF Option."; }

if(NoneWithCheck(document.frmChangeProposalInfo.Status))

{ errormessage += "\n\nPlease click one radio button under Status."; }

 

// Need to enter validation for date field here

if(ValidateDate(document.frmChangeProposalInfo.AwardDate))

{ ; }

else

{ errormessage += "\n\nPlease enter a valid AWARD DATE. The date format for the AWARD DATE is: mm/dd/yyyy"; }

 

// Put field checks above this point.

if(errormessage.length > 2) {

alert('NOTE:' + errormessage);

return false;

}

return true;

}

// end of function CheckRequiredFields()

 

 

function WithoutContent(ss) {

if(ss.length > 0) { return false; }

return true;

}

 

//function NoneWithContent(ss) {

//for(var i = 0; i < ss.length; i++) {

// if(ss.value.length > 0) { return false; }

// }

//return true;

//}

 

function NoneWithCheck(ss) {

for(var i = 0; i < ss.length; i++) {

if(ss.checked) { return false; }

}

return true;

}

 

//function WithoutCheck(ss) {

//if(ss.checked) { return false; }

//return true;

//}

 

function WithoutSelectionValue(ss) {

for(var i = 0; i < ss.length; i++) {

if(ss.selected) {

if(ss.value.length) { return false; }

}

}

return true;

}

 

// Validation test area

 

function ValidNumber(ss){

 

var digits="0123456789"

var temp

 

if (ss.value=="") {

return true

}

for (var i=0;i<ss.value.length;i++){

temp=ss.value.substring(i,i+1)

if (digits.indexOf(temp)==-1){

return true

}

}

return false;

}

 

function ValidProb(ss){

 

var digits="0123456789"

var temp

 

if (ss.value=="") {

return true

}

for (var i=0;i<ss.value.length;i++){

temp=ss.value.substring(i,i+1)

if (digits.indexOf(temp)==-1){

return true

}

if (ss.value>100){

return true

}

}

return false;

}

 

//-->

// Date Validation Function Test Area

/**

* DHTML date validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)

*/

// Declaring valid date character, minimum year and maximum year

var dtCh= "/";

var minYear=1900;

var maxYear=2100;

 

function isInteger(s){

var i;

for (i = 0; i < s.length; i++){

// Check that current character is number.

var c = s.charAt(i);

if (((c < "0") || (c > "9"))) return false;

}

// All characters are numbers.

return true;

}

 

function stripCharsInBag(s, bag){

var i;

var returnString = "";

// Search through string's characters one by one.

// If character is not in bag, append to returnString.

for (i = 0; i < s.length; i++){

var c = s.charAt(i);

if (bag.indexOf© == -1) returnString += c;

}

return returnString;

}

 

function daysInFebruary (year){

// February has 29 days in any year evenly divisible by four,

// EXCEPT for centurial years which are not also divisible by 400.

return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );

}

function DaysArray(n) {

for (var i = 1; i <= n; i++) {

this = 31

if (i==4 || i==6 || i==9 || i==11) {this = 30}

if (i==2) {this = 29}

}

return this

}

 

function isDate(dtStr){

var daysInMonth = DaysArray(12)

var pos1=dtStr.indexOf(dtCh)

var pos2=dtStr.indexOf(dtCh,pos1+1)

var strMonth=dtStr.substring(0,pos1)

var strDay=dtStr.substring(pos1+1,pos2)

var strYear=dtStr.substring(pos2+1)

strYr=strYear

if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)

if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)

for (var i = 1; i <= 3; i++) {

if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)

}

month=parseInt(strMonth)

day=parseInt(strDay)

year=parseInt(strYr)

if (pos1==-1 || pos2==-1){

//alert("The date format for the Sent Date and the Award Date should be: mm/dd/yyyy")

return false

}

if (strMonth.length<1 || month<1 || month>12){

//alert("Please enter a valid month for the Sent Date and/or the Award Date")

return false

}

if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){

//alert("Please enter a valid day for the Sent Date and/or the Award Date")

return false

}

if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){

//alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear +" for the Sent Date and the Award Date")

return false

}

if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){

//alert("Please enter a valid date for the Sent Date and the Award Date")

return false

}

return true

}

 

function ValidateDate(ss){

var dt=ss

if (isDate(dt.value)==false){

dt.focus()

return false

}

return true

}

 

// end validate date test area

//-->

</script>

 

 

<title>Update Proposal Information</title>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<link href="/Styles/Styles.css" rel="stylesheet" type="text/css">

</head>

 

<body>

<form action="<?php echo $editFormAction; ?>" method="POST" name="frmChangeProposalInfo" id="frmChangeProposalInfo" onSubmit="return CheckRequiredFields()">

<div id="Layer1" style="position:absolute; left:2px; top:3px; width:152px; height:34px; z-index:1;">

<div align="center"><font size="2"><a href="../Switchboard_01.php">Click

Here to Return to the Switchboard</a></font></div>

</div>

<p class="PageHeading">UPDATE PROPOSAL NUMBER INFORMATION</p>

<div align="center">

<table width="753" border="0" cellspacing="2" cellpadding="2">

<!--DWLayoutTable-->

<tr>

<td height="49" valign="top" class="FormLabel">Client Number:</td>

<td colspan="8" valign="middle" class="FormText"><span class="FormLabel"><font size="2"><?php echo $ChangeProposalInfo->Fields('CID'); ?></font></span> - <span class="FormLabel"><font size="2"><?php echo $ChangeProposalInfo->Fields('YRS'); ?></font></span> - <span class="FormLabel"><font size="2"><?php echo $ChangeProposalInfo->Fields('PID'); ?></font></span></td>

</tr>

<tr>

<td width="141" height="49" valign="top" class="FormLabel"> Client Name:</td>

<td colspan="8" align="left" valign="middle"><p class="FormText"><font color="#000066" size="2"><strong><?php echo $ClientList->Fields('ClientName'); ?></strong></font> </p>

</td>

</tr>

<tr>

<td height="32" valign="top" class="FormLabel">Project Title:</td>

<td colspan="8" valign="middle"><input name="Title" type="text" id="Title2" value="<?php echo $ChangeProposalInfo->Fields('Title'); ?>" size="60">

</td>

</tr>

<tr>

<td height="36" valign="top" class="FormLabel">Project Manager:</td>

<td colspan="2" valign="middle"><select name="ProjectMgr" size="1" id="ProjectMgr" title="<?php echo $ChangeProposalInfo->Fields('ProjectMgr'); ?>">

<option value="-1" <?php if (!(strcmp(-1, $ChangeProposalInfo->Fields('ProjectMgr')))) {echo "SELECTED";} ?>>Select

Project Manager</option>

<?php

while(!$ProjectManagers->EOF){

?>

<option value="<?php echo $ProjectManagers->Fields('Initials')?>"<?php if (!(strcmp($ProjectManagers->Fields('Initials'), $ChangeProposalInfo->Fields('ProjectMgr')))) {echo "SELECTED";} ?>><?php echo $ProjectManagers->Fields('EngineerName')?></option>

<?php

$ProjectManagers->MoveNext();

}

$ProjectManagers->MoveFirst();

?>

</select>

</td>

<td width="73" valign="" class="FormLabel">Business Area: </td

>

<td colspan="3" valign="top"><select name="BusinessArea" size="1" id="BusinessArea" title="<?php echo $ChangeProposalInfo->Fields('BusID'); ?>">

<option value="-1" <?php if (!(strcmp(-1, $ChangeProposalInfo->Fields('BusID')))) {echo "SELECTED";} ?>>Select Business Area</option>

<?php

while(!$BusinessArea->EOF){

?>

<option value="<?php echo $BusinessArea->Fields('BusinessArea')?>"<?php if (!(strcmp($BusinessArea->Fields('BusinessArea'), $ChangeProposalInfo->Fields('BusID')))) {echo "SELECTED";} ?>><?php echo $BusinessArea->Fields('BusinessArea')?></option>

<?php

$BusinessArea->MoveNext();

}

$BusinessArea->MoveFirst();

?>

</select>

</td>

<td width="95" valign="middle" nowrap><div align="right"><span class="FormLabel">QA? </span> </div>

</td>

<td width="36" valign="middle"><input name="QA" type="checkbox" id="QA2" value="<?php echo $ChangeProposalInfo->Fields('QA'); ?>">

</td>

</tr>

<tr>

<td height="36" valign="top" class="FormLabel">Data Entered By<br>

(initials only):</td>

<td width="42" valign="middle"> <input name="DataEnteredBy" type="text" id="DataEnteredBy2" value="<?php echo $ChangeProposalInfo->Fields('DataEnteredBy'); ?>" size="6">

</td>

<td width="157"> </td>

<td></td>

<td width="87"> </td>

<td width="12"> </td>

<td width="54"> </td>

<td></td>

<td></td>

</tr>

<tr>

<td height="33" colspan="9" valign="top"><hr>

</td>

</tr>

<tr>

<td height="33" valign="middle" class="FormLabel">Amount: </td>

<td colspan="2" valign="middle"> <p>

<input name="Amount" type="text" id="Amount" value="<?php echo $ChangeProposalInfo->Fields('Amount'); ?>" size="12">

</p></td>

<td colspan="3" rowspan="2" valign="top" bordercolor="#990033" class="FormLabel"><p><u>TM

or Fixed?</u> </p> <p align="left">

<label>

<input <?php if (!(strcmp($ChangeProposalInfo->Fields('TMorFixed'),"1"))) {echo "CHECKED";} ?> type="radio" name="TMorFixed" value="1">

Time and Materials</label>

<br>

<label>

<input <?php if (!(strcmp($ChangeProposalInfo->Fields('TMorFixed'),"2"))) {echo "CHECKED";} ?> type="radio" name="TMorFixed" value="2">

Fixed Price</label>

<br>

</p>

</td>

<td> </td>

<td> </td>

<td> </td>

</tr>

<tr>

<td height="39"></td>

<td> </td>

<td> </td>

<td> </td>

<td></td>

<td></td>

</tr>

<tr>

<td height="28" colspan="9" valign="top"><hr>

</td>

</tr>

<tr>

<td height="34" valign="top" class="FormLabel">Date Proposal Sent (mm/dd/yyyy):</td>

<td colspan="2" valign="middle"><input name="SentDate" type="text" id="SentDate2" value="<?php echo $ChangeProposalInfo->Fields('Sdate'); ?>">

</td>

<td colspan="2" rowspan="3" valign="top" class="FormLabel"><p><u> SKF Option</u></p> <p align="left">

<label>

<input <?php if (!(strcmp($ChangeProposalInfo->Fields('SFKOptions'),"1"))) {echo "CHECKED";} ?> type="radio" name="SKFOptions" value="1">

SKF Client</label>

<br>

<label>

<input <?php if (!(strcmp($ChangeProposalInfo->Fields('SFKOptions'),"2"))) {echo "CHECKED";} ?> type="radio" name="SKFOptions" value="2">

SKF Internal</label>

<br>

<label>

<input <?php if (!(strcmp($ChangeProposalInfo->Fields('SFKOptions'),"3"))) {echo "CHECKED";} ?> type="radio" name="SKFOptions" value="3">

SKF Referral</label>

<br>

<label>

<input <?php if (!(strcmp($ChangeProposalInfo->Fields('SFKOptions'),"4"))) {echo "CHECKED";} ?> type="radio" name="SKFOptions" value="4">

Not Applicable</label>

<br>

</p>

</td>

<td colspan="4" rowspan="3" valign="top" class="FormLabel"><p><u>Status

as of:

<input name="StatusDate" type="text" id="StatusDate" value="<?php echo $ChangeProposalInfo->Fields('Statdate'); ?>">

</u></p> <p align="left">

<label>

<input <?php if (!(strcmp($ChangeProposalInfo->Fields('Outcome'),"1"))) {echo "CHECKED";} ?> type="radio" name="Status" value="1">

Active</label>

<br>

<label>

<input name="Status" type="radio" value="2" <?php if (!(strcmp($ChangeProposalInfo->Fields('Outcome'),"2"))) {echo "CHECKED";} ?>>

Won</label>

<br>

<label>

<input <?php if (!(strcmp($ChangeProposalInfo->Fields('Outcome'),"3"))) {echo "CHECKED";} ?> type="radio" name="Status" value="3">

Lost</label>

<br>

<label>

<input <?php if (!(strcmp($ChangeProposalInfo->Fields('Outcome'),"4"))) {echo "CHECKED";} ?> type="radio" name="Status" value="4">

Cancelled</label>

<br>

</p>

</td>

</tr>

<tr>

<td height="64" valign="top" class="FormLabel"><p>Anticipated<br>

Award Date<br>

(mm/dd/yyyy): </p>

</td>

<td colspan="2" valign="middle"><u>

<input name="AwardDate" type="text" id="AwardDate" value="<?php echo $ChangeProposalInfo->Fields('Adate'); ?>">

</u> </td>

</tr>

<tr>

<td height="34" valign="top" class="FormLabel">Probability (%):</td>

<td colspan="2" valign="middle"><input name="ProbPercent" type="text" id="ProbPercent2" value="<?php echo $ChangeProposalInfo->Fields('ProbPercent'); ?>">

</td>

</tr>

</table>

</div>

<p align="center">

<input name="Submit" type="submit" value="Submit">

</p>

<p align="center"> </p>

<div align="center">

<input type="hidden" name="MM_update" value="frmChangeProposalInfo">

</div>

</form>

</body>

</html>

<?php

$ChangeProposalInfo->Close();

 

$ProjectManagers->Close();

 

$BusinessArea->Close();

 

$ClientList->Close();

?>

 

Link to comment
https://forums.phpfreaks.com/topic/1981-update-form-validation/
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.