CodeCharge Studio
search Register Login  

Visual PHP Web Development

Visually Create Internationalized Web Applications, Web Reports, Calendars, and more.
CodeCharge.com

YesSoftware Forums -> Archive -> GotoCode Archive

 lookup value before insert -CC

Print topic Send  topic

Author Message
konalan
Posted: 05/06/2002, 6:48 PM

Hi,

I have a form that allow people to enter contact information. Due to one contact person can be assigned to many project. User can enter the name in the name textbox and press enter. I would like to lookup the name if the same name is found in the database all contact information will be loaded into the text box likes phone,pager etc. Users can then specify the priority of the contact and insert as a new record.

<?php
/*********************************************************************************
* Filename: addcontact.php
* Generated with CodeCharge 2.0.5
* PHP 4.0 build 11/30/2001
*********************************************************************************/

//-------------------------------
// addcontact CustomIncludes begin

include ("./common.php");
$page_title = "Add/Edit contact";
include("./breadcrumb.php");

// addcontact CustomIncludes end
//-------------------------------

session_start();

//===============================
// Save Page and File Name available into variables
//-------------------------------
$sFileName = "form_contact.php";
//===============================


//===============================
// addcontact PageSecurity begin
check_security(2);
// addcontact PageSecurity end
//===============================

//===============================
// addcontact Open Event begin
// addcontact Open Event end
//===============================

//===============================
// addcontact OpenAnyPage Event start
// addcontact OpenAnyPage Event end
//===============================

//===============================
//Save the name of the form and type of action into the variables
//-------------------------------
$sAction = get_param("FormAction");
$sForm = get_param("FormName");
//===============================

// addcontact Show begin

//===============================
// Perform the form's action
//-------------------------------
// Initialize error variables
//-------------------------------
$scontactErr = "";

//-------------------------------
// Select the FormAction
//-------------------------------
switch ($sForm) {
case "contact":
contact_action($sAction);
break;
}
//===============================

//===============================
// Display page

//===============================
// HTML Page layout
//-------------------------------
?><html>
<head>
<title>intranet</title>
<meta name="GENERATOR" content="YesSoftware CodeCharge v.2.0.5 build 11/30/2001">
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">

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

<body bgcolor="#ffffff" link="#000099" alink="#ff0000" vlink="#000099" text="#000000">
<?php breadCrumb($PATH_INFO ); ?>
<script language="JavaScript">
function new_customer() {
var w = open ('', 'windowName', 'width=700,height=400,titlebar=0');
w.document.open();
w.location.href="form_customer.php";
}
</script>
<br>
<?php contact_show() ?>

</body>
</html>

<?php

// addcontact Show end

//===============================
// addcontact Close Event begin
// addcontact Close Event end
//===============================
//********************************************************************************


//===============================
// Action of the Record Form
//-------------------------------
function contact_action($sAction)
{
//-------------------------------
// Initialize variables
//-------------------------------
global $db;

global $sForm;
global $scontactErr;
global $styles;
$bExecSQL = true;
$sActionFileName = "";
$sWhere = "";
$bErr = false;
$pPKcontact_id = "";
$fldcontact_name = "";
$fldcontact_IC = "";
$fldcust_id = "";
$fldcontact_type_id = "";
$fldcontact_mobile = "";
$fldcontact_office = "";
$fldcontact_pager = "";
$fldcontact_home = "";
$fldcontact_fax = "";
$fldcontact_email = "";
//-------------------------------

//-------------------------------
// contact Action begin
//-------------------------------
$sActionFileName = "contact.php";

//-------------------------------
// CANCEL action
//-------------------------------
if($sAction == "cancel")
{

//-------------------------------
// contact BeforeCancel Event begin
// contact BeforeCancel Event end
//-------------------------------
header("Location: " . $sActionFileName);
}
//-------------------------------


//-------------------------------
// Build WHERE statement
//-------------------------------
if($sAction == "update" || $sAction == "delete")
{
$pPKcontact_id = get_param("PK_contact_id");
if( !strlen($pPKcontact_id)) return;
$sWhere = "contact_id=" . tosql($pPKcontact_id, "Number");
}
//-------------------------------


//-------------------------------
// Load all form fields into variables
//-------------------------------
$fldcontact_name = get_param("contact_name");
$fldcontact_IC = get_param("contact_IC");
$fldcust_id = get_param("cust_id");
$fldcontact_type_id = get_param("contact_type_id");
$fldcontact_mobile = get_param("contact_mobile");
$fldcontact_office = get_param("contact_office");
$fldcontact_pager = get_param("contact_pager");
$fldcontact_home = get_param("contact_home");
$fldcontact_fax = get_param("contact_fax");
$fldcontact_email = get_param("contact_email");

//-------------------------------
// Validate fields
//-------------------------------
if($sAction == "insert" || $sAction == "update")
{
if(!strlen($fldcontact_name))
$scontactErr .= "The value in field Name * is required.<br>";

if(!strlen($fldcust_id))
$scontactErr .= "The value in field Customer * is required.<br>";

if(!strlen($fldcontact_type_id))
$scontactErr .= "The value in field Type * is required.<br>";

if(!is_number($fldcust_id))
$scontactErr .= "The value in field Customer * is incorrect.<br>";

if(!is_number($fldcontact_type_id))
$scontactErr .= "The value in field Type * is incorrect.<br>";

//-------------------------------
// contact Check Event begin
// contact Check Event end
//-------------------------------
if(strlen($scontactErr)) return;
}
//-------------------------------


//-------------------------------
// Create SQL statement
//-------------------------------
switch(strtolower($sAction))
{
case "insert":
//-------------------------------
// contact Insert Event begin

// contact Insert Event end
//-------------------------------
$sSQL = "insert into contact (" .
"contact_name," .
"contact_IC," .
"cust_id," .
"contact_type_id," .
"contact_mobile," .
"contact_office," .
"contact_pager," .
"contact_home," .
"contact_fax," .
"contact_email)" .
" values (" .
tosql($fldcontact_name, "Text") . "," .
tosql($fldcontact_IC, "Text") . "," .
tosql($fldcust_id, "Number") . "," .
tosql($fldcontact_type_id, "Number") . "," .
tosql($fldcontact_mobile, "Text") . "," .
tosql($fldcontact_office, "Text") . "," .
tosql($fldcontact_pager, "Text") . "," .
tosql($fldcontact_home, "Text") . "," .
tosql($fldcontact_fax, "Text") . "," .
tosql($fldcontact_email, "Text") .
")";
break;
case "update":

//-------------------------------
// contact Update Event begin
// contact Update Event end
//-------------------------------
$sSQL = "update contact set " .
"contact_name=" . tosql($fldcontact_name, "Text") .
",contact_IC=" . tosql($fldcontact_IC, "Text") .
",cust_id=" . tosql($fldcust_id, "Number") .
",contact_type_id=" . tosql($fldcontact_type_id, "Number") .
",contact_mobile=" . tosql($fldcontact_mobile, "Text") .
",contact_office=" . tosql($fldcontact_office, "Text") .
",contact_pager=" . tosql($fldcontact_pager, "Text") .
",contact_home=" . tosql($fldcontact_home, "Text") .
",contact_fax=" . tosql($fldcontact_fax, "Text") .
",contact_email=" . tosql($fldcontact_email, "Text");
$sSQL .= " where " . $sWhere;
break;
case "delete":
//-------------------------------
// contact Delete Event begin
// contact Delete Event end
//-------------------------------
$sSQL = "delete from contact where " . $sWhere;
break;
}
//-------------------------------
//-------------------------------
// contact BeforeExecute Event begin
// contact BeforeExecute Event end
//-------------------------------

//-------------------------------
// Execute SQL statement
//-------------------------------
if(strlen($scontactErr)) return;
if($bExecSQL)
$db->query($sSQL);
header("Location: " . $sActionFileName);

//-------------------------------
// contact Action end
//-------------------------------
}

//===============================
// Display Record Form
//-------------------------------
function contact_show()
{
global $db;

global $sAction;
global $sForm;
global $sFileName;
global $scontactErr;
global $styles;

$fldcontact_id = "";
$fldcontact_name = "";
$fldcontact_IC = "";
$fldcust_id = "";
$fldcontact_type_id = "";
$fldcontact_mobile = "";
$fldcontact_office = "";
$fldcontact_pager = "";
$fldcontact_home = "";
$fldcontact_fax = "";
$fldcontact_email = "";
//-------------------------------
// contact Show begin
//-------------------------------
$sFormTitle = "Add/Edit Contact";
$sWhere = "";
$bPK = true;
$scust_idDisplayValue = "[Choose One]";
$scontact_type_idDisplayValue = "[Choose One]";

?>
<font class="ClearFormHeaderFont">Add/Edit Contact</font>

<table class="ClearFormTABLE" cellspacing="1" cellpadding="3" border="0">
<form method="POST" action="<?= $sFileName ?>" name="contact">

<? if ($scontactErr) { ?>
<tr><td class="ClearDataTD" colspan="2"><?= $scontactErr ?></font></td></tr>
<? } ?>
<?

//-------------------------------
// Load primary key and form parameters
//-------------------------------
if($scontactErr == "")
{
$pcontact_id = get_param("contact_id");
}
else
{
$fldcontact_id = strip(get_param("contact_id"));
$fldcontact_name = strip(get_param("contact_name"));
$fldcontact_IC = strip(get_param("contact_IC"));
$fldcust_id = strip(get_param("cust_id"));
$fldcontact_type_id = strip(get_param("contact_type_id"));
$fldcontact_mobile = strip(get_param("contact_mobile"));
$fldcontact_office = strip(get_param("contact_office"));
$fldcontact_pager = strip(get_param("contact_pager"));
$fldcontact_home = strip(get_param("contact_home"));
$fldcontact_fax = strip(get_param("contact_fax"));
$fldcontact_email = strip(get_param("contact_email"));
$pcontact_id = get_param("PK_contact_id");
}
//-------------------------------

//-------------------------------
// Load all form fields

//-------------------------------

//-------------------------------
// Build WHERE statement
//-------------------------------

if( !strlen($pcontact_id)) $bPK = false;

$sWhere .= "contact_id=" . tosql($pcontact_id, "Number");
//-------------------------------
//-------------------------------
// contact Open Event begin
// contact Open Event end
//-------------------------------

//-------------------------------
// Build SQL statement and execute query
//-------------------------------
$sSQL = "select * from contact where " . $sWhere;
// Execute SQL statement
$db->query($sSQL);
$bIsUpdateMode = ($bPK && !($sAction == "insert" && $sForm == "contact") && $db->next_record());
//-------------------------------

//-------------------------------
// Load all fields into variables from recordset or input parameters
//-------------------------------
if($bIsUpdateMode)
{
$fldcontact_id = $db->f("contact_id");
//-------------------------------
// Load data from recordset when form displayed first time
//-------------------------------
if($scontactErr == "")
{
$fldcontact_name = $db->f("contact_name");
$fldcontact_IC = $db->f("contact_IC");
$fldcust_id = $db->f("cust_id");
$fldcontact_type_id = $db->f("contact_type_id");
$fldcontact_mobile = $db->f("contact_mobile");
$fldcontact_office = $db->f("contact_office");
$fldcontact_pager = $db->f("contact_pager");
$fldcontact_home = $db->f("contact_home");
$fldcontact_fax = $db->f("contact_fax");
$fldcontact_email = $db->f("contact_email");
}
//-------------------------------
// contact ShowEdit Event begin
// contact ShowEdit Event end
//-------------------------------
}
else
{
//-------------------------------
// contact ShowInsert Event begin
// contact ShowInsert Event end
//-------------------------------
}
//-------------------------------
// contact Show Event begin
// contact Show Event end
//-------------------------------

//-------------------------------
// Show form field
//-------------------------------
?>
<tr>
<td class="ClearFieldCaptionTD">
Name *
</td>
<td class="ClearDataTD">
<input class="ClearInput" type="text" name="contact_name" maxlength="60" value="<?= tohtml($fldcontact_name) ?>" size="60" >
</td>
</tr>
<tr>
<td class="ClearFieldCaptionTD">
IC
</td>
<td class="ClearDataTD">
<input class="ClearInput" type="text" name="contact_IC" maxlength="14" value="<?= tohtml($fldcontact_IC) ?>" size="14" ></font>
</td>
</tr>
<tr>
<td class="ClearFieldCaptionTD">
Customer *
</td>
<td class="ClearDataTD">
<select class="ClearSelect" name="cust_id">
<?
echo "<option value=\"\">" . $scust_idDisplayValue . "</option>";
$lookup_cust_id = db_fill_array("select cust_id, cust_name from customer order by 2");

if(is_array($lookup_cust_id))
{
reset($lookup_cust_id);
while(list($key, $value) = each($lookup_cust_id))
{
if($key == $fldcust_id)
$option="<option SELECTED value=\"$key\">$value";
else
$option="<option value=\"$key\">$value";
echo $option;
}
}

?></select>
<a href="javascript:new_customer()">click here to insert a new customer</a>
</td>
</tr>
<tr>
<td class="ClearFieldCaptionTD">
Type *
</td>
<td class="ClearDataTD">
<select class="ClearSelect" name="contact_type_id">
<?
echo "<option value=\"\">" . $scontact_type_idDisplayValue . "</option>";
$lookup_contact_type_id = db_fill_array("select contact_type_id, type_long_desc from contact_category order by 2");

if(is_array($lookup_contact_type_id))
{
reset($lookup_contact_type_id);
while(list($key, $value) = each($lookup_contact_type_id))
{
if($key == $fldcontact_type_id)
$option="<option SELECTED value=\"$key\">$value";
else
$option="<option value=\"$key\">$value";
echo $option;
}
}

?></select>
</td>
</tr>
<tr>
<td class="ClearFieldCaptionTD">
HP
</td>
<td class="ClearDataTD">
<input class="ClearInput" type="text" name="contact_mobile" maxlength="8" value="<?= tohtml($fldcontact_mobile) ?>" size="8" >
</td>
</tr>
<tr>
<td class="ClearFieldCaptionTD">
Office
</td>
<td class="ClearDataTD">
<input class="ClearInput" type="text" name="contact_office" maxlength="8" value="<?= tohtml($fldcontact_office) ?>" size="8" >
</td>
</tr>
<tr>
<td class="ClearFieldCaptionTD">
Pager
</td>
<td class="ClearDataTD">
<input class="ClearInput" type="text" name="contact_pager" maxlength="8" value="<?= tohtml($fldcontact_pager) ?>" size="8" >
</td>
</tr>
<tr>
<td class="ClearFieldCaptionTD">
Home
</td>
<td class="ClearDataTD">
<input class="ClearInput" type="text" name="contact_home" maxlength="8" value="<?= tohtml($fldcontact_home) ?>" size="8" >
</td>
</tr>
<tr>
<td class="ClearFieldCaptionTD">
Fax
</td>
<td class="ClearDataTD">
<input class="ClearInput" type="text" name="contact_fax" maxlength="8" value="<?= tohtml($fldcontact_fax) ?>" size="8" >
</td>
</tr>
<tr>
<td class="ClearFieldCaptionTD">
Email
</td>
<td class="ClearDataTD">
<input class="ClearInput" type="text" name="contact_email" maxlength="40" value="<?= tohtml($fldcontact_email) ?>" size="40" >
</td>
</tr>
<tr><td colspan="2" align="right"><? if (!$bIsUpdateMode) { ?>
<input type="hidden" value="insert" name="FormAction">
<input class="ClearButton" type="submit" value="Insert" onclick="document.contact.FormAction.value = 'insert';">
<? } ?>
<? if ($bIsUpdateMode) { ?>
<input type="hidden" value="update" name="FormAction"/>
<input class="ClearButton" type="submit" value="Update" onclick="document.contact.FormAction.value = 'update';">
<input class="ClearButton" type="submit" value="Delete" onclick="document.contact.FormAction.value = 'delete';">
<? } ?>
<input class="ClearButton" type="button" value="Cancel" onclick="history.go( -1 );return true;">
<input type="hidden" name="FormName" value="contact">

<input type="hidden" name="PK_contact_id" value="<?= $pcontact_id ?>">
<input type="hidden" name="contact_id" value="<?= tohtml($fldcontact_id)?>">
</td></tr>
</form>
</table>
<?



//-------------------------------
// contact Close Event begin
// contact Close Event end
//-------------------------------

//-------------------------------
// contact Show end
//-------------------------------
}
//===============================
?>
Nicole
Posted: 05/07/2002, 6:10 AM

Konalan,
I think it makes sense to split the functionality into two forms. On the first one use could enter his name and after submitting the corresponding user_id is to be looked up. In case it is found on the second form use before Show event to look up corresponding user values (address, phone, etc) and fill form fields with them. Otherwise user is to fill the information manually.

   


These are Community Forums for users to exchange information.
If you would like to obtain technical product help please visit http://support.yessoftware.com.

PHP Reports

Visually create Web Reports in PHP, ASP, .NET, Java, Perl and ColdFusion.
CodeCharge.com

Home   |    Search   |    Members   |    Register   |    Login


Powered by UltraApps Forum created with CodeCharge Studio
Copyright © 2003-2004 by UltraApps.com  and YesSoftware, Inc.