Hello!
I am trying to use Chronoforms to display in Joomla powered site some dynamic forms created in PHP. Those forms are taking data from MySql database and displaying them, or create new records, or update existing ones. My code works fine on testing server, but when submitted to Chronoforms, it does not insert new records to database. The form is displayed OK, it also reads the data from database. However, the problem is that it does not update existing record when changed, nor write new record to database. As I said, outside Chronoforms and Joomla the code works fine.
Do you have any idea what is wrong, please? Thanks in advance.
Here is my code:
Edited: to add code tags. Greyhead<br><br>Post edited by: GreyHead, at: 2007/08/17 14:38
I am trying to use Chronoforms to display in Joomla powered site some dynamic forms created in PHP. Those forms are taking data from MySql database and displaying them, or create new records, or update existing ones. My code works fine on testing server, but when submitted to Chronoforms, it does not insert new records to database. The form is displayed OK, it also reads the data from database. However, the problem is that it does not update existing record when changed, nor write new record to database. As I said, outside Chronoforms and Joomla the code works fine.
Do you have any idea what is wrong, please? Thanks in advance.
Here is my code:
<?php require_once('Connections/MySql.php'); ?>
<?php
if (!function_exists("GetSQLValueString"«»)) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = ""«»)
{
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
$theValue = function_exists("mysql_real_escape_string"«») ? mysql_real_escape_string($theValue) : mysql_escape_string($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;
}
}
$currentPage = $_SERVER["PHP_SELF"];
$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}
if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form1"«»)) {
$updateSQL = sprintf("UPDATE `1st_zakaznici` SET meno_zakaznika=%s, ulica=%s, mesto=%s, psc=%s, ico=%s, dic=%s, kontaktna_osoba=%s, telefon=%s, mail=%s, webova_stranka=%s, poznamka=%s WHERE ID_zakaznika=%s",
GetSQLValueString($_POST['meno_zakaznika'], "text"«»),
GetSQLValueString($_POST['ulica'], "text"«»),
GetSQLValueString($_POST['mesto'], "text"«»),
GetSQLValueString($_POST['psc'], "text"«»),
GetSQLValueString($_POST['ico'], "text"«»),
GetSQLValueString($_POST['dic'], "text"«»),
GetSQLValueString($_POST['kontaktna_osoba'], "text"«»),
GetSQLValueString($_POST['telefon'], "text"«»),
GetSQLValueString($_POST['mail'], "text"«»),
GetSQLValueString($_POST['webova_stranka'], "text"«»),
GetSQLValueString($_POST['poznamka'], "text"«»),
GetSQLValueString($_POST['ID_zakaznika'], "int"«»));
mysql_select_db($database_MySql, $MySql);
$Result1 = mysql_query($updateSQL, $MySql) or die(mysql_error());
}
$maxRows_zakaznici = 1;
$pageNum_zakaznici = 0;
if (isset($_GET['pageNum_zakaznici'])) {
$pageNum_zakaznici = $_GET['pageNum_zakaznici'];
}
$startRow_zakaznici = $pageNum_zakaznici * $maxRows_zakaznici;
mysql_select_db($database_MySql, $MySql);
$query_zakaznici = "SELECT * FROM `1st_zakaznici`";
$query_limit_zakaznici = sprintf("%s LIMIT %d, %d", $query_zakaznici, $startRow_zakaznici, $maxRows_zakaznici);
$zakaznici = mysql_query($query_limit_zakaznici, $MySql) or die(mysql_error());
$row_zakaznici = mysql_fetch_assoc($zakaznici);
if (isset($_GET['totalRows_zakaznici'])) {
$totalRows_zakaznici = $_GET['totalRows_zakaznici'];
} else {
$all_zakaznici = mysql_query($query_zakaznici);
$totalRows_zakaznici = mysql_num_rows($all_zakaznici);
}
$totalPages_zakaznici = ceil($totalRows_zakaznici/$maxRows_zakaznici)-1;
$queryString_zakaznici = "";
if (!empty($_SERVER['QUERY_STRING'])) {
$params = explode("&", $_SERVER['QUERY_STRING']);
$newParams = array();
foreach ($params as $param) {
if (stristr($param, "pageNum_zakaznici"«») == false &&
stristr($param, "totalRows_zakaznici"«») == false) {
array_push($newParams, $param);
}
}
if (count($newParams) != 0) {
$queryString_zakaznici = "&" . htmlentities(implode("&", $newParams));
}
}
$queryString_zakaznici = sprintf("&totalRows_zakaznici=%d%s", $totalRows_zakaznici, $queryString_zakaznici);
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<form action="<?php echo $editFormAction; ?>" method="post" name="form1" id="form1">
<table align="center">
<tr valign="baseline">
<td nowrap="nowrap" align="right">Meno_zakaznika:</td>
<td><input type="text" name="meno_zakaznika" value="<?php echo htmlentities($row_zakaznici['meno_zakaznika'], ENT_COMPAT, 'utf-8'); ?>" size="32" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">Ulica:</td>
<td><input type="text" name="ulica" value="<?php echo htmlentities($row_zakaznici['ulica'], ENT_COMPAT, 'utf-8'); ?>" size="32" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">Mesto:</td>
<td><input type="text" name="mesto" value="<?php echo htmlentities($row_zakaznici['mesto'], ENT_COMPAT, 'utf-8'); ?>" size="32" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">Psc:</td>
<td><input type="text" name="psc" value="<?php echo htmlentities($row_zakaznici['psc'], ENT_COMPAT, 'utf-8'); ?>" size="32" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">Ico:</td>
<td><input type="text" name="ico" value="<?php echo htmlentities($row_zakaznici['ico'], ENT_COMPAT, 'utf-8'); ?>" size="32" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">Dic:</td>
<td><input type="text" name="dic" value="<?php echo htmlentities($row_zakaznici['dic'], ENT_COMPAT, 'utf-8'); ?>" size="32" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">Kontaktna_osoba:</td>
<td><input type="text" name="kontaktna_osoba" value="<?php echo htmlentities($row_zakaznici['kontaktna_osoba'], ENT_COMPAT, 'utf-8'); ?>" size="32" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">Telefon:</td>
<td><input type="text" name="telefon" value="<?php echo htmlentities($row_zakaznici['telefon'], ENT_COMPAT, 'utf-8'); ?>" size="32" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">Mail:</td>
<td><input type="text" name="mail" value="<?php echo htmlentities($row_zakaznici['mail'], ENT_COMPAT, 'utf-8'); ?>" size="32" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">Webova_stranka:</td>
<td><input type="text" name="webova_stranka" value="<?php echo htmlentities($row_zakaznici['webova_stranka'], ENT_COMPAT, 'utf-8'); ?>" size="32" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">Poznamka:</td>
<td><input type="text" name="poznamka" value="<?php echo htmlentities($row_zakaznici['poznamka'], ENT_COMPAT, 'utf-8'); ?>" size="32" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right"> </td>
<td><input type="submit" value="Update record" /></td>
</tr>
</table>
<p> </p>
<table border="0" align="center">
<tr>
<td><?php if ($pageNum_zakaznici > 0) { // Show if not first page ?>
<a href="<?php printf("%s?pageNum_zakaznici=%d%s", $currentPage, 0, $queryString_zakaznici); ?>">First</a>
<?php } // Show if not first page ?>
</td>
<td><?php if ($pageNum_zakaznici > 0) { // Show if not first page ?>
<a href="<?php printf("%s?pageNum_zakaznici=%d%s", $currentPage, max(0, $pageNum_zakaznici - 1), $queryString_zakaznici); ?>">Previous</a>
<?php } // Show if not first page ?>
</td>
<td><?php if ($pageNum_zakaznici < $totalPages_zakaznici) { // Show if not last page ?>
<a href="<?php printf("%s?pageNum_zakaznici=%d%s", $currentPage, min($totalPages_zakaznici, $pageNum_zakaznici + 1), $queryString_zakaznici); ?>">Next</a>
<?php } // Show if not last page ?>
</td>
<td><?php if ($pageNum_zakaznici < $totalPages_zakaznici) { // Show if not last page ?>
<a href="<?php printf("%s?pageNum_zakaznici=%d%s", $currentPage, $totalPages_zakaznici, $queryString_zakaznici); ?>">Last</a>
<?php } // Show if not last page ?>
</td>
</tr>
</table>
</p>
<p> </p>
<p>
<input type="hidden" name="ID_zakaznika" value="<?php echo $row_zakaznici['ID_zakaznika']; ?>" />
<input type="hidden" name="MM_update" value="form1" />
<input type="hidden" name="ID_zakaznika" value="<?php echo $row_zakaznici['ID_zakaznika']; ?>" />
</p>
</form>
<p> </p>
</body>
</html>
<?php
mysql_free_result($zakaznici);
?>
Edited: to add code tags. Greyhead<br><br>Post edited by: GreyHead, at: 2007/08/17 14:38
Hi sketman,
This may well be possible but it will take some work on your part. ChronoForms is a form manager for Joomla - it will take form html and help you create forms with that. But the form html it uses is just the part between the <form> and </form> tags. And the form itself is embedded into a Joomla page of some kind which has some other constraints to it - for example it already has <head> and <body> tags.
You might get this to work by putting the form html code 'only' in the Form HTML field, then working through your pre-processing PHP to put that in the appropriate places e.g. there are fields in ChronoForms where you can add the Form Action, Redirect URL and some pre-processing code.
That said, I'm not sure that ChronoForms is the most useful tool. Given the code that you have you may just be able to put it into a Joomla content page of some kind.
Bob
This may well be possible but it will take some work on your part. ChronoForms is a form manager for Joomla - it will take form html and help you create forms with that. But the form html it uses is just the part between the <form> and </form> tags. And the form itself is embedded into a Joomla page of some kind which has some other constraints to it - for example it already has <head> and <body> tags.
You might get this to work by putting the form html code 'only' in the Form HTML field, then working through your pre-processing PHP to put that in the appropriate places e.g. there are fields in ChronoForms where you can add the Form Action, Redirect URL and some pre-processing code.
That said, I'm not sure that ChronoForms is the most useful tool. Given the code that you have you may just be able to put it into a Joomla content page of some kind.
Bob
Hi Bob,
Thanks for quick answer.
I tryed to separate HTML code and PHP code, putting PHP code to "On Submit Code" field in Chronoforms. Unfortunatelly, it didnt work for me.
The funny think about all is, that it can read from database. Logically, when it cant write in it, also with regards to your explanation, it shouldnt be able to read from it neither. But it connect to database and can read from it...:silly:
Regarding your advice putting my code directly into Joomla content page, I couldnt find any appropriate way. For example, in Drupal there is a option to insert PHP code directly into content page - but I couldnt find that functionality in Joomla...
Anyway, Chronoforms is great component, excellent work!
Thanks again for your commitement and for good advices.
Thanks for quick answer.
I tryed to separate HTML code and PHP code, putting PHP code to "On Submit Code" field in Chronoforms. Unfortunatelly, it didnt work for me.
The funny think about all is, that it can read from database. Logically, when it cant write in it, also with regards to your explanation, it shouldnt be able to read from it neither. But it connect to database and can read from it...:silly:
Regarding your advice putting my code directly into Joomla content page, I couldnt find any appropriate way. For example, in Drupal there is a option to insert PHP code directly into content page - but I couldnt find that functionality in Joomla...
Anyway, Chronoforms is great component, excellent work!
Thanks again for your commitement and for good advices.
Hi sketman,
I was a bit surprised that your form worked at all - I only spent a few minutes looking at the code though.
In ChronoForms I think I'd probably put the database write code either into the OnSubmit - after email field; or you could just pate it into the AutoGenerated field in place of ChronoForms own code. The entry in this field is just 'evaluated' as a chunk of PHP.
As a Joomla page, I'm no Joomla expert, but I think that the Joomla 'wrapper' page is what you need - see here.
Bob
I was a bit surprised that your form worked at all - I only spent a few minutes looking at the code though.
In ChronoForms I think I'd probably put the database write code either into the OnSubmit - after email field; or you could just pate it into the AutoGenerated field in place of ChronoForms own code. The entry in this field is just 'evaluated' as a chunk of PHP.
As a Joomla page, I'm no Joomla expert, but I think that the Joomla 'wrapper' page is what you need - see here.
Bob
Hi All,
If it cant write, doesn't it give any errors ?
If it cant write, doesn't it give any errors ?
This topic is locked and no more replies can be posted.