Forums

Editable table

petermazzi 04 Jan, 2012
Hi there,

I need to create a page with a table that is visible and contains the results of an online form. Moreover, I need that it is possible also to edit/update the fields of the table .

Can Chronoform do this ? If not, any clue where I can look for ?

hope I wss clear enough...
GreyHead 04 Jan, 2012
Hi petermazzi,

I think you can do this with ChronoForms - I'm not sure how you expect the edit part to work though? You can add an edit button that would re-open the form??

Bob
petermazzi 05 Jan, 2012
Yes this would be a perfect solution... How to do it ?
GreyHead 05 Jan, 2012
Hi petermazzi,

I think I'd create a new form to edit the data using the DB Load Record action to retrieve the data and then in the list create a button with a link to the new form and include the record id in the link URL. Something like this:
<a href='index.php?option=com_chronoform&chronoform=edit_form&id={id}'>
  <input type='button' name='edit' value='Edit' />
</a>

Bob
petermazzi 05 Jan, 2012
Thank you very much, I will try to follow your advice...I will keep you posted on the outcome !!!
Peetzen 13 Jan, 2012
Maybe this helps. Thats my list_data.php with the extra for edit the entry. the url goes to the standart show_data.php. The show_data.php is modified to. so you have the option on the right side to edit the entry. In the second show_data.php (edit) option you have the same as the original show_data.php entrys but the option to change. If you submit the form it opends another form how updates your sql entries. You have to setup these forms for your own envoirement. because i dosnt setup my solution to a dynamic form.

I just wrote that in a few minutes, so i am not sure thats what you need.
---->list_data*php
<?php
/**
* CHRONOFORMS version 4.0
* Copyright (c) 2006 - 2011 Chrono_Man, ChronoEngine.com. All rights reserved.
* Author: Chrono_Man (ChronoEngine.com)
* @license		GNU/GPL
* Visit http://www.ChronoEngine.com for regular updates and information.
* Edited by David Peetzen www.dp-networld.de
**/
	$mainframe =& JFactory::getApplication();
	$primary = '';
	foreach($table_fields as $table_field => $field_data){
		if($field_data->Key == 'PRI'){
			$primary = $table_field;
		}
	}
?>
<h3>Listing data records for table: <?php echo $table_name; ?></h3>
<?php if(empty($primary)): ?>
<h3 style="color:red;">This table has no primary keys and its records can't be viewed!</h3>
<?php endif; ?>
<?php
	$extra_dataview_actions = array();
	if(isset($_POST['form_id'])){
		$row =& JTable::getInstance('chronoforms', 'Table');
		$row->load($_POST['form_id']);
		$params = new JParameter($row->params);
		$dataview_actions = $params->get('dataview_actions', '');
		
		if(!empty($dataview_actions)){
			$dataview_actions = explode(",", $dataview_actions);
			foreach($dataview_actions as $dataview_action){
				$action_pieces = explode(":", $dataview_action);
				$extra_dataview_actions[$action_pieces[0]] = $action_pieces[1];
			}
		}
	}
?>
<form action="index.php?option=com_chronoforms" method="post" name="adminForm" id="adminForm">
<table class="adminlist">
<thead>
	<th width="1%" class='title'>#</th>
	<?php if(!empty($primary)): ?>
	<th width="2%" class='title' style="text-align: left;">ID</th>	
	<th width="1%" class='title' style="text-align: left;"><input type="checkbox" name="toggle" value="" onclick="checkAll(<?php echo count($table_data); ?>);" /></th>
	<?php endif; ?>
	<th width="10%" align="left" class='title' style="text-align: left;">Record</th>
	<?php // Eingefügt von David Peetzen?>
	<th align='left' class='title' style="text-align: left;">Editieren</th>
	<?php foreach($extra_dataview_actions as $action_k => $action_title): ?>
		<th width="10%" align="left" class='title' style="text-align: left;"><?php echo $action_title; ?></th>
	<?php endforeach; ?>
	
</thead>
<?php if(!empty($table_data)): ?>
	<?php $i = 0; ?>
	<?php foreach($table_data as $row): ?>
		<tr>
			<td width="1%" class='title'><?php echo $i + 1;?></td>
			<?php if(!empty($primary)): ?>
			<td width="2%" class='title'><?php echo $row->$primary; ?></td>			
			<td width="1%" class='title'>
				<input type="checkbox" id="cb<?php echo $i;?>" name="cb[]" value="<?php echo $row->$primary; ?>" onclick="isChecked(this.checked);" />
			</td>
			<?php endif; ?>
			<td width="10%" align="left" class='title'><a href="#show_data" onclick="return listItemTask('cb<?php echo $i;?>','show_data')">Record #<?php echo $i + 1 + $pageNav->limitstart; ?></a></td>
			<?php //Eingefügt von David Peetzen ?>
			<td width="10%" align="left" class='title'><a href="#show_data_dp" onclick="return listItemTask('cb<?php echo $i;?>','show_data_dp')">Record #<?php echo $i + 1 + $pageNav->limitstart; ?></a></td>
			<?php foreach($extra_dataview_actions as $action_k => $action_title): ?>
				<td width="10%" align="left" class='title'><a href="#admin_form:<?php echo $action_k; ?>" onclick="return listItemTask('cb<?php echo $i;?>','admin_form:<?php echo $action_k; ?>')"><?php echo $action_title; ?> #<?php echo $i + 1 + $pageNav->limitstart; ?></a></td>
			<?php endforeach; ?>
		</tr>
	<?php $i++; ?>
	<?php endforeach; ?>
<?php endif; ?>
<tr><td colspan="<?php echo (5 + count($extra_dataview_actions)); ?>" style="white-space:nowrap;" height="20px"><?php echo $pageNav->getListFooter(); ?></td></tr>
</table>
<input type="hidden" name="table_name" value="<?php echo $table_name; ?>" />
<?php if(isset($_POST['form_id'])): ?>
<input type="hidden" name="form_id" value="<?php echo $_POST['form_id']; ?>" />
<?php endif; ?>
<input type="hidden" name="boxchecked" value="" />
<input type="hidden" name="task" value="list_data" />
<input type="hidden" name="option" value="com_chronoforms" />
</form>

show_data*php
<?php
/**
* CHRONOFORMS version 4.0
* Copyright (c) 2006 - 2011 Chrono_Man, ChronoEngine.com. All rights reserved.
* Author: Chrono_Man (ChronoEngine.com)
* @license		GNU/GPL
* Visit http://www.ChronoEngine.com for regular updates and information.
* Edited by David Peetzen www.dp-networld.de
**/
	$mainframe =& JFactory::getApplication();
	$primary = '';
	foreach($table_fields as $table_field => $field_data){
		if($field_data->Key == 'PRI'){
			$primary = $table_field;
		}
	}
//Just prepared for my next update to include the System in Joomla
if ($_POST['update11'] == 'updaten11'){
	$table_name = isset($_POST['table_name']) ? $_POST['table_name'] : $_GET['table_name'];
	$mainframe =& JFactory::getApplication();
		$database =& JFactory::getDBO();
		$database->setQuery("Update * FROM ".$table_name." WHERE ".$primary."='".$_POST['cb'][0]."'");
		$form = $database->loadObject();
}	

		
		
		
//echo $row_data->input_Name;		
		?>

<?php 

if ($_POST['task'] ==  'show_data_dp'){?>
<form action="http://xxxxxxxx/edit_form.php" method="post" name="adminForm" id="adminForm" accept-charset="UTF-8">
<table class="adminlist">
<thead>
	<th width="20%" class='title'>Field title</th>
	<th width="80%" class='title'>Field value</th>
</thead>
<?php if(!empty($row_data)): ?>
	<?php $i = 0; ?>
	<?php //foreach($table_fields as $table_field => $field_data): ?>
		<tr>
		<td width='20%' class='title'>Nachname </td>
		<td><input type='text' class='title' name='nachname' value='<?php echo $row_data->input_Name;?>' /></td>
		</tr>
		<tr>
		<td width='20%' class='title'>Vorname </td>	 
		<td><input type='text' class='title' name='vorname' value='<?php echo $row_data->input_Vorname;?>' /></td>
		</tr>
		<tr>
		<td width='20%' class='title'>E-Mail </td>
		<td><input type='text' class='title' name='email' value='<?php echo $row_data->input_email;?>' /></td>
		</tr>
		<tr>
		<td width='20%' class='title'>Telefon </td>
		<td><input type='text' class='title' name='telefon' value='<?php echo $row_data->input_Tel;?>' /></td>
		</tr>
		<tr>
		<td width='20%' class='title'>Anfrage </td>
		<td><textarea name='anfrage' cols='50' rows='10' ><?php echo $row_data->input_anfrage;?></textarea></td>
		</tr>
		<tr>
		<td width='20%' class='title'>Bemerkung </td>
		<td><textarea name='bemerkung' cols='50' rows='10' ><?php echo $row_data->bemerkung_admin;?></textarea></td>
		</tr>
		<tr>
			<td colspan="2">
	<?php //$i++; ?>
	<?php //endforeach; ?>
<?php endif; ?>

<input type="hidden" name="table_name" value="<?php echo $table_name; ?>" />
<?php if(isset($_POST['form_id'])): ?>
<input type="hidden" name="post_id" value="<?php echo $row_data->cf_id; ?>" />
<?php endif; ?>
<input type="hidden" name="boxchecked" value="" />
<input type="hidden" name="form_id" value="<?php echo $_POST['form_id']; ?>" />
<input type="hidden" name="option" value="com_chronoforms" />
<tr><td colspan="2"><input type="submit" name="submit" value="updaten" />  
</table>
</form>





<?php } else {?>
<form action="index.php?option=com_chronoforms" method="post" name="adminForm" id="adminForm">
<table class="adminlist">
<thead>
	<th width="20%" class='title'>Field title</th>
	<th width="80%" class='title'>Field value</th>
</thead>
<?php if(!empty($row_data)): ?>
	<?php $i = 0; ?>
	<?php foreach($table_fields as $table_field => $field_data): ?>
		<tr>
			<td width="20%" class='title'><?php echo $table_field; ?></td>
			<td width="80%" class='title'><?php echo htmlspecialchars($row_data->$table_field); ?></td>
		</tr>
	<?php $i++; ?>
	<?php endforeach; ?>
<?php endif; ?>
</table>
<input type="hidden" name="table_name" value="<?php echo $table_name; ?>" />
<?php if(isset($_POST['form_id'])): ?>
<input type="hidden" name="form_id" value="<?php echo $_POST['form_id']; ?>" />
<?php endif; ?>
<input type="hidden" name="boxchecked" value="" />
<input type="hidden" name="task" value="" />
<input type="hidden" name="option" value="com_chronoforms" />
</form>
<?php } ?>


edit_form*php

<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<?php
//Created by David Peetzen www.dp-networld.de
//echo $_POST['submit'];
//echo $_POST['post_id'];
$debug = '0';
if ($debug == '1') {
echo $_POST['submit'];
echo '<br>';
echo $_POST['form_id'];	
echo '<br>';
echo $_POST['post_id'];
echo '<br>';
echo $_POST['table_name'];
echo '<br>';
echo $_POST['nachname'];
echo '<br>';
echo $_POST['vorname'];
echo '<br>';
echo $_POST['email'];
echo '<br>';
echo $_POST['telefon'];
echo '<br>';
echo $_POST['anfrage'];
echo '<br>';
echo $_POST['bemerkung'];
}
//Variabeln setzen für Übergabe aus verständlichkeit nicht direkt übernommen
$post_id = $_POST['post_id'];
$form = $_POST['form_id'];
$nach = $_POST['nachname'];
$vorn = $_POST['vorname'];
$emai = $_POST['email'];
$tele = $_POST['telefon'];
$anfr = $_POST['anfrage'];
$beme = $_POST['bemerkung'];
$table_name = $_POST['table_name'];
echo $table_name;
$mysql_hostname = 'xxxxx';
$mysql_username = 'xxxxx';
$mysql_password = 'xxxxx';
$mysql_database = 'xxxxx';
//Datenbank verbindung
$con =mysql_connect($mysql_hostname, $mysql_username, $mysql_password) or die('Fehler bei der Verbindung');
mysql_select_db($mysql_database, $con) or die('Fehler beim aufbauen der Verbindung by mysql_select');
$mysql = "SELECT * FROM ".$table_name." WHERE cf_id=".$post_id." LIMIT 1";
$result=mysql_query($mysql);
$row1 = mysql_fetch_assoc($result);
//echo '<br>';
//	echo $row1["cf_id"];
//	echo $row1["input_Name"];
//	echo $row1['input_Vorname'];
//echo'<br><br><br><br><br><br><br><br>';
	
	
		$mysqlupd="UPDATE ".$table_name." SET input_Name='".$nach."', input_Vorname='".$vorn."', input_email='".$emai."', input_Tel='".$tele."', input_anfrage='".$anfr."', bemerkung_admin='".$beme."'  WHERE cf_id=".$post_id." " OR mysql_error();
		echo $mysqlupd;
		$result1=mysql_db_query($mysql_database, $mysqlupd);	
		if ($result1) {
			echo '<br>Anzahl geänderter Datensätze: '.mysql_affected_rows($con);
		}else {
			echo '<br>Datensatz nicht gespeichert';
		}
		mysql_close($con);
		echo '<a href="xxxxxxxxxxxxx/administrator/index.php?option=com_chronoforms">zurück</a>';
?>
petermazzi 16 Jan, 2012
Hi there,

I developed the table and it seems to work fine.

I need only one extra bit: that the table shows the cf_id numbers starting from the number 101 (therefore 100+cf_id). Which code should I use to enable this addition ?
<table style="width: 540px;" border="1" cellpadding="0" cellspacing="0">
<tbody>
        <tr>
            <td style="width: 30px;"><strong>EMN</strong></td>
            <td style="width: 30px;"><strong>Date</strong></td>
            <td style="width: 60px;"><strong>Location</strong></td>
            <td style="width: 50px;"><strong>Country</strong></td>
            <td style="width: 100px;"><strong>Organiser</strong></td>
            <td style="width: 60px;"><strong>Tel/Fax</strong></td>
            <td style="width: 40px;"><strong>Email</strong></td>
            <td style="width: 40px;"><strong>Website</strong></td>
            <td style="width: 40px;"><strong></strong></td>
        </tr>
<?php
foreach($form->data['opencalendar_rr'] as $detail):
?>
<tr>
<td valign="top"><?php echo $detail['cf_id']; ?></td>
<td valign="top"><?php echo $detail['date']; ?></td>
<td valign="top"><?php echo $detail['location']; ?></td>
<td valign="top"><?php echo $detail['country']; ?></td>
<td valign="top"><?php echo $detail['organiser']; ?></td>
<td valign="top"><?php echo $detail['telephone']; ?></td>
<td valign="top"><a href="mailto:<?php echo $detail['email']; ?>">Email</a></td>
<td valign="top"><a href="<?php echo $detail['website']; ?>">Website</a></td>
<td valign="top"><a href="index.php?option=com_chronoforms&chronoform=opencalendar_rr&token=<?php echo $detail['cf_uid']; ?>">Edit</a></td>
</tr>
<?php
endforeach;
?>
</table>
GreyHead 16 Jan, 2012
Hi petermazzi ,

Can you use WHERE `cf_id` > 100 in the DB Record Loader action?

Bob
petermazzi 16 Jan, 2012
Do you mean I have to do this ?

<td valign="top"><?php echo $detail[WHERE `cf_id` > 100]; ?></td>



It does not seem to work... Am I doing something wrong ?
GreyHead 16 Jan, 2012
Hi petermazzi ,

No. Are you using s DB Multi Record Loader action to get the data? That has a WHERE box where you can filter the records.

Bob
petermazzi 16 Jan, 2012
Hi Bonb...Yes, I am using the DB Multi Record Loader action. However, I do not need to filter records, but I need to do a simple sum to each record, adding 100 to the 'cf_id'. Therefore the first entry would be 1+100 = 101 the second entry 2+100=102 and so on...
I cannot find the right code to do this simple addition in the Custom Code action... Any idea ?
Thanks a lot for your extremely kind support.
Best regards,
Peter
GreyHead 17 Jan, 2012
Hi Petermazzi.

I'm sorry, I missed the point completely :-(
<td valign="top"><?php echo $detail['cf_id'] + 100; ?></td>


Bob
petermazzi 17 Jan, 2012
Ops, I thought it should have been more complex than this.

Thanks a lot !!!
This topic is locked and no more replies can be posted.