?
Solved

Combine two HTML field values to inport into a table

Posted on 2008-10-21
6
Medium Priority
?
721 Views
Last Modified: 2013-12-13
Hello All

I am trying (and failing) to build a webform with several HTML Text Input fields. Once the fields have been filled in, I need to combine all of the values into one big string so I can import it into a table using sql. All of the values need to be put into one field in the table, in some sort of order if possible.

I need all of the fields contents combining and inserting into updatedb.updatetxt as per the code sample.

<table class="style1">
                                <td class="style2">
                                    Full Name:&nbsp;</td>
                                <td>
                                    <input type='text' value='' id=$fname>&nbsp;</td>
                                <td>
                                    Start Date:</td>
                                <td>
                                   <input type='text' value='' id="sdate">&nbsp;</td> 
                            </tr>
                            <tr>
                                <td class="style2">
                                    Job Title:&nbsp;</td>
                                <td>
                                    <input type='text' value='' id="jtitle">&nbsp;</td>
                                <td>
                                    Telephone Number:</td>
                                <td>
                                    <input type='text' value='' id="tnumb"></td>
                            </tr>
                            <tr>
                                <td class="style2">
                                    Site Name:</td>
                                <td>
                                    <input type='text' value='' id="sname">&nbsp;</td>
                                <td>
                                    Position:</td>
                                <td> 
                                    <input type='text' value='' id="position">&nbsp;</td>
                           </tr>
                           <tr>
                                <td class="style2">
                                    Copy from user:</td>
                                <td>
                                    <input type='text' value='' id="tuser">&nbsp;</td>
                          </tr>
                       </table>
                      <br>
				       <b>Desktop Requirements:</b><br><br> 
				        <table class="style1">
                            <td class="style2">
                                Requires windows logon?</td>
                            <td>
                                <input type='checkbox' value='' id="winlogon">&nbsp;</td>
                            <td>
                                Requires Microsoft Office?</td>
                            <td>
                                <input type='checkbox' value='' id="msoffice">&nbsp;</td>
                        </table>
                    
                    
				<!-- hidden fields that store session vars -->
				  <input type="hidden" id="updatedb.updatetxt" value=???????????>

Open in new window

0
Comment
Question by:MikeSel
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 

Expert Comment

by:royalyoda
ID: 22765705
You should incorporate all the input tags in a form tag like

<form name="foo" action="doSomething.php" method="post">

<!--
Put your input tags here

-->

</form>

Catch this form at your doSomething.php and then combine all the values of input tags. Hope this helps.
0
 
LVL 8

Expert Comment

by:MatthiasVance
ID: 22765716
Why aren't you using a form that gets submitted? You can easily integrate the posted values into a SQL statement (by using PHP).

Kind regards,

Matthias Vance
0
 
LVL 4

Author Comment

by:MikeSel
ID: 22765794
I am building a custom form into a pre existing system.. Then form is passed to a php file

<form id="logcallform" action="php/xmlhttp/logcall.submit.php">

However, this looks very complex, and I doubt I will be able to modify it at this level.

It would be easier if I could push all the values through at once.

I have attached the logcall.submit file
<?
 
	include("itsm/portal/common.php");
	//-- This script will loop through posted vars find all those with
	//-- opencall_ and updatedb_
 
	//-- if required opencall fields (like priority) are not passed in will use session default as defined in self serv config
	$arrOpencallValues = Array();
	$arrUpdatedbValues = Array();
	$arrExtendedTables = Array();
 
	//-- loop through posted vars and id each question
	foreach ($HTTP_GET_VARS as $key => $val)
	{
		//-- check if we need to split data
		if(strpos($val,ANSWER_SPLIT)!==false)$val = str_replace(ANSWER_SPLIT," and ",$val);
 
		//echo $key . " : " . $val . "<br./>";
		if (strpos($key,"extbl_")===0)
		{
			//-- we want to store info into an extended table (in hnlt element has id="extbl_tablname_.colname"
			$arrInfo = explode("extbl_",$key,2);
			$strTableAndColName = $arrInfo[1];
 
			$arrTblInfo = explode("__",$strTableAndColName,2);
 
			$strExtTable = $arrTblInfo[0];
			$strExtCol = $arrTblInfo[1];
 
			echo $strExtTable . " : " . $strExtCol;
 
			if(!isset($arrExtendedTables[$strExtTable]))$arrExtendedTables[$strExtTable] = Array();
			$arrExtendedTables[$strExtTable][$strExtCol] = stripslashes($val);
		}
		else if(strpos($key,"opencall_")!==false)
		{
			$arrInfo = explode("_",$key,2);
			$colName = $arrInfo[1];
			$arrOpencallValues[$colName] = stripslashes($val);
		}
		else if (strpos($key,"updatedb_")!==false)
		{
			//-- check opencall priority option
			$arrInfo = explode("_",$key,2);
			$colName = $arrInfo[1];
			$arrUpdatedbValues[$colName] = stripslashes($val);
		}
		else
		{
			//-- something else
		}
	}
 
	//-- CHECK PRIORITY
	//-- if priority is set to [Use Customer SLA] then set it to cust
	if(($arrOpencallValues['priority']=="[Use Customer SLA]")&&($_SESSION['userdb_priority']!=""))
	{
		$arrOpencallValues['priority'] = $_SESSION['userdb_priority'];
	}
	else if($arrOpencallValues['priority']=="")
	{
		//-- priority is empty so set to session priority (if blank use userdb)
		if($_SESSION['config_sla']!="")		
		{
			//-- use config sla
			$arrOpencallValues['priority'] = $_SESSION['config_sla'];
		}
		else
		{
			//-- use userdb
			$arrOpencallValues['priority'] = $_SESSION['userdb_priority'];
		}
	}
 
	//-- if logstatus= Incoming OR Logged then handle else assume ok
	if($arrOpencallValues['status']=="Incoming")
	{
		$arrOpencallValues['status'] = CS_INCOMMING;
	}
	else if ($arrOpencallValues['status']=="Logged")
	{
		//-- if have an owner set to unaccepted else unassigned
		$useStatus = ($arrOpencallValues['owner']!="")?CS_UNACCEPTED:CS_UNASSIGNED;
		$arrOpencallValues['status'] = $useStatus;
	}
 
 
	//-- create helpdesk session
	$hdConn = new CSwHDsession($_SESSION['connector_instance']);
	if(!$hdConn->open_hd_connection())
	{
		echo $hdConn->LastError;
		exit;
	}
 
	//-- start log call
	if(!$hdConn->StartCallCreate())
	{
		echo $hdConn->LastError;
		exit;
	}
 
	//--
	//-- send call values
	foreach ($arrOpencallValues as $column_name => $column_value)
	{
		$hdConn->sendtextfield($column_name,$column_value);
	}
 
	//-- send updatedb values
	foreach ($arrUpdatedbValues as $column_name => $column_value)
	{
		$hdConn->sendtextfield("updatedb.".$column_name,$column_value);
	}
 
	//-- commit
	$result = $hdConn->CommitCallAction();
	if(!$result)
	{
		echo $hdConn->LastError;
		exit;
	}
 
 
	$intRespByEpoch = $hdConn->GetReturnValue("respondbyx");
	$intFixByEpoch = $hdConn->GetReturnValue("fixbyx");
 
	$fixbydate = SwFormatCustomerTimestampValue($intFixByEpoch,$_SESSION['config_datetimefmt']);
	$respondbydate =SwFormatCustomerTimestampValue($intRespByEpoch,$_SESSION['config_datetimefmt']);
	$new_callref = $hdConn->GetReturnValue("callref");
	$callref_num = substr($new_callref,1,8);
 
	if(isset($callref_num))
	{
		//-- insert ci relationship
		if(gv('opencall_equipment')!="")
		{
			//-- add ci to call based on class
			$assignClass = gv('opencall_callclass');
			if($arrOpencallValues['status'] == CS_INCOMMING)$assignClass = "Incoming";
			cmdb_addci_to_call(gv('opencall_equipment'), $callref_num, $assignClass);					
		}
 
		//-- add any extended information here
		//-- loop through ext tables
		$swDATA = database_connect("swdata");
		foreach ($arrExtendedTables as $table_name => $arr_columns)
		{
 
			//-- nwj - check if ext record already exists
			$strExtendedInsert = "insert into "	. strtolower($table_name);
			$boolInsert = true;
			$rsCount = $swDATA->Query("select count(*) as reccount from ".$table_name." where callref = ".$callref_num,true);
			if(($rsCount)&&($rsCount->f('reccount')>"0"))
			{
				$boolInsert = false;
			}
			
			$strUpdateFields = "";
			$strSetFields = "";
			$strSetValues = "";
 
			//-- create insert cols
			foreach ($arr_columns as $column_name => $column_value)
			{
				if($strSetFields != "")$strSetFields .= ",";
				if($strSetValues != "")$strSetValues .= ",";
 
				$intType = swdti_getdatatype($table_name.".".$column_name);
				$strEncaps = ($intType==8||$intType==-1)?"'":"";
 
				$strSetFields .= $column_name;
				$strSetValues .= $strEncaps . PrepareForSql($column_value) . $strEncaps;
 
				if($strUpdateFields!="")$strUpdateFields.=",";
				$strUpdateFields .= $column_name . " = " . $strEncaps . PrepareForSql($column_value) . $strEncaps;
			}
 
			//-- apply insert
			if(($strSetValues!="")&&($strSetFields!=""))
			{
				if($boolInsert)
				{
					$strExtendedInsertOne = $strExtendedInsert . " (opencall," . $strSetFields . ") values (".$callref_num.",". $strSetValues .")";
					if($swDATA->Query($strExtendedInsertOne)==false)
					{
						//-- try callref
						$strExtendedInsertTwo = $strExtendedInsert . " (callref," . $strSetFields . ") values (".$callref_num.",". $strSetValues .")";			
						if ($swDATA->Query($strExtendedInsertTwo)==false)
						{
						}
					}
				}
				else
				{
					//-- update
					$strExtendedUpdate = "update "	. strtolower($table_name) . " set " . $strUpdateFields . " where callref = ". $callref_num;
					if($swDATA->Query($strExtendedUpdate)==false)
					{
					}
 
				}
			}
		}
	}
 
	unset($hdConn); //-- nullify
 
	//- get active incident coutn to show in menu count 
	$conCache  = database_connect("syscache","","");
	$GLOBALS['inccount'] = $conCache->GetRecordCount("opencall", "status < 15 and status != 6 and cust_id = '".PrepareForSql($_SESSION['userdb_keysearch'])."'");
 
?>
 
<div class="boxWrapper" style="margin:0px auto 10px auto; width:600px"><img src="img/structure/box_header_left.gif" width="6" height="11" alt="" border="0" /><div class="boxMiddle">
	<div class="boxContent">
		<div class="spacer">&nbsp;</div>
		<!-- box content -->
		<h2>Your request has been logged (<?=$new_callref;?>)</h2>
		<p>Thank you. Your request has been logged, with a reference of <b><?=$new_callref;?></b>. 
 
		
		<?
			//--
			//-- only show resp and fix time if call status is logged as when the status is incoming does not apply sla
			if (($intRespByEpoch>0))
			{
		?>
				The support team will aim to respond to you by <?=$respondbydate;?> and resolve your request by <?=$fixbydate;?>.</p>	
		<?
			}
		?>
 
 
		<p>To assist us in providing you with a quick response to any future enquires you may have regarding this matter, please keep a note of the above reference. If 
		you call our support hotline on <?=$_SESSION['config_helpdeskphone']?> to check the status of your request, you will be asked for this reference.</p>
 
		<!-- end of box content -->
		<div class="spacer">&nbsp;</div>
	</div>
</div>
<div class="boxFooter"><img src="img/structure/box_footer_left.gif" /></div>
</div>
 
 
<div class="boxWrapper" style="margin:0px auto 10px auto; width:600px"><img src="img/structure/box_header_left.gif" width="6" height="11" alt="" border="0" /><div class="boxMiddle">
	<div class="boxContent">
		<div class="spacer">&nbsp;</div>
		<!-- box content -->
		<h2>File Attachment</h2>
		<p>If you have any files, such as business documents, log files or screenshots, that will help the support team expedite your request you can attach them using the field below.</p>	
		<iframe style="width:550px;height:90px;" border="0" frameborder="0" src="php/xmlhttp/uploadfile.php?in_callref=<?=$callref_num?>" name="if_uploader"></iframe>
		<!-- end of box content -->
		<div class="spacer">&nbsp;</div>
	</div>
</div>
<div class="boxFooter"><img src="img/structure/box_footer_left.gif" /></div>
</div>
 
<script autoload>
	//-- show new log count in menu item My requests
	var mnuItem = document.getElementById('mi_custreqs');
	if(mnuItem!=null)
	{
		app.setElementText(mnuItem,"My Requests (<?=$GLOBALS['inccount'];?> Open)");
	}
</script>

Open in new window

0
NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

 
LVL 19

Expert Comment

by:NerdsOfTech
ID: 22766435
If you need all posted values as a huge chuck...

How about trying out the $_POST global and imploding it >:)
$insane = implode("," $_POST);

Open in new window

0
 
LVL 4

Author Comment

by:MikeSel
ID: 22767203
Ok, ill give it a go.....

Thanks
0
 
LVL 19

Accepted Solution

by:
NerdsOfTech earned 1000 total points
ID: 22772085
The above will cause you to end up with
$insane = value1, value2, value3, value4, etc.

You could also do this as well:
// If you need to reference individual inputs just do this:
$value = $_POST['name of the input here']

Open in new window

0

Featured Post

NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses how to create an extensible mechanism for linked drop downs.
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
Suggested Courses

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question