Solved

Combine two HTML field values to inport into a table

Posted on 2008-10-21
6
696 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
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
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
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 250 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

These days socially coordinated efforts have turned into a critical requirement for enterprises.
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
In this tutorial viewers will learn how to embed Flash content in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <object> tag to embed Flash content.: To specify that the object is Flash content, d…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

760 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now