...

View Full Version : Form submision retrieving input values



musher
04-20-2005, 05:33 PM
not sure if this is Java or PHP problem..... and I'm hoping most of you Java guru's know abit about PHP and can help.

There's a function I'm using that does Rich Text Editing (alows you to edit a field on a form in a word type environment).

Rich Text Editor (http://www.kevinroth.com/rte/demo.htm)

After you click on the submit button on the form the page does a

alert("Value sumited = " + document.RTEDemo.rte1.value);
I'm guessing this is a Java thing and that the data entered is in document.RTEDemo.RTE1.value?????
How the heck do I get that data into a MySQl field?
Right now I have a hidden input set up "tbody" that is being stored into MySQl field "body" I've tried setting up different values for the hidden input "tbody" (ie: document.RTEDemo.RTE1.value, $content) but no luck so far.

Thanks for any help on this.




<?php require_once('../../Connections/ConnRidley.php'); ?>
<?php
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue;

switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form1")) {
/* $stuff = "this is the body area";*/
$updateSQL = sprintf("UPDATE pressrelease SET title=%s, body=%s WHERE ID=%s",
GetSQLValueString($HTTP_POST_VARS['title'], "text"),
/* GetSQLValueString($HTTP_POST_VARS['$content'], "text"),*/
GetSQLValueString($HTTP_POST_VARS['tbody'], "text"),
GetSQLValueString($_POST['ID'], "text"));

mysql_select_db($database_ConnRidley, $ConnRidley);
$Result1 = mysql_query($updateSQL, $ConnRidley) or die(mysql_error());

$updateGoTo = "press_sel.php";
if (isset($_SERVER['QUERY_STRING'])) {
$updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?";
$updateGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $updateGoTo));
}

$colname_rsPressrelease = "1";
if (isset($_GET['recordID'])) {
$colname_rsPressrelease = (get_magic_quotes_gpc()) ? $_GET['recordID'] : addslashes($_GET['recordID']);
}
mysql_select_db($database_ConnRidley, $ConnRidley);
$query_rsPressrelease = sprintf("SELECT * FROM pressrelease WHERE ID = '%s'", $colname_rsPressrelease);
$rsPressrelease = mysql_query($query_rsPressrelease, $ConnRidley) or die(mysql_error());
$row_rsPressrelease = mysql_fetch_assoc($rsPressrelease);
$totalRows_rsPressrelease = mysql_num_rows($rsPressrelease);
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
<script language="JavaScript" type="text/javascript" src="html2xhtml.js"></script>
<!-- To decrease bandwidth, use richtext_compressed.js instead of richtext.js //-->
<script language="JavaScript" type="text/javascript" src="richtext.js"></script>
</head>

<body>

<!-- START new Demo Code -->
<form name="RTEDemo" action="<?php echo $editFormAction; ?>" method="post" onSubmit="return submitForm();">
<div>ID: <?php echo $row_rsPressrelease['ID']; ?></div>
<div>Title: <input type="text" name="title" value="<?php echo $row_rsPressrelease['title']; ?>" size="100"></div>
<br>
<script language="JavaScript" type="text/javascript">
<!--
function submitForm() {
//make sure hidden and iframe values are in sync before submitting form
//to sync only 1 rte, use updateRTE(rte)
//to sync all rtes, use updateRTEs
updateRTE('rte1');
alert("Value sumited = " + document.RTEDemo.rte1.value);
//updateRTEs();

//change the following line to true to submit form
return true;
}

//Usage: initRTE(imagesPath, includesPath, cssFile, genXHTML)
initRTE("images/", "", "", true);
//-->
</script>
<noscript><p><b>Javascript must be enabled to use this form.</b></p></noscript>

<script language="JavaScript" type="text/javascript">
<!--
<?php
//format content for preloading
if (!(isset($_POST["rte1"]))) {
$content = $row_rsPressrelease['body'];
$content = rteSafe($content);
} else {
//retrieve posted value
$content = rteSafe($_POST["rte1"]);
}
?>//Usage: writeRichText(fieldname, html, width, height, buttons, readOnly)
writeRichText('rte1', '<?=$content;?>', 520, 200, true, false);
//-->
</script>

<p>Click submit to post the form and reload with your rte content.</p>
<p><input type="submit" name="submit" value="Submit"></p>
<input type="hidden" name="MM_update" value="form1">
<input type="hidden" name="ID" value="<?php echo $row_rsPressrelease['ID']; ?>">
<input type="hidden" name="tbody" value="<?php echo $content; ?>">
</form>

<?php
function rteSafe($strText) {
//returns safe code for preloading in the RTE
$tmpString = $strText;

//convert all types of single quotes
$tmpString = str_replace(chr(145), chr(39), $tmpString);
$tmpString = str_replace(chr(146), chr(39), $tmpString);
$tmpString = str_replace("'", "'", $tmpString);

//convert all types of double quotes
$tmpString = str_replace(chr(147), chr(34), $tmpString);
$tmpString = str_replace(chr(148), chr(34), $tmpString);
// $tmpString = str_replace("\"", "\"", $tmpString);

//replace carriage returns & line feeds
$tmpString = str_replace(chr(10), " ", $tmpString);
$tmpString = str_replace(chr(13), " ", $tmpString);
return $tmpString;
}
?>
<!-- END new Demo Code -->
</body>
</html>
<?php
mysql_free_result($rsPressrelease);
?>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum