?
		
	
			
			
					Hi all,
so far I've been using the submit article for a form that would allow to add articles only and the db save for a form that allows editing articles only
now I am trying to set up a form that allows both adding and editing articles where eg the published state can be set by the user.
as Max pointed out in this thread I should use the db save action for non default setups
http://www.chronoengine.com/forums/index.php?option=com_chronoforums&cont=posts&f=26&t=23094
this works with exception of setting fields created / created_by on new items or fields modified / modified_by for editing items respectively. upon submission these fields remain empty. thus my query to only list those articles for editing where created_by = $user->id does not return anything for not admins.
how should I get this done without using an edited submit_article action pls?
J!1.5.24; CF4 RC 2.1
				
				
				
			so far I've been using the submit article for a form that would allow to add articles only and the db save for a form that allows editing articles only
now I am trying to set up a form that allows both adding and editing articles where eg the published state can be set by the user.
as Max pointed out in this thread I should use the db save action for non default setups
http://www.chronoengine.com/forums/index.php?option=com_chronoforums&cont=posts&f=26&t=23094
this works with exception of setting fields created / created_by on new items or fields modified / modified_by for editing items respectively. upon submission these fields remain empty. thus my query to only list those articles for editing where created_by = $user->id does not return anything for not admins.
how should I get this done without using an edited submit_article action pls?
J!1.5.24; CF4 RC 2.1
					Hi gabrielah,
I think that you need to set values for those columns in the form data. You can do this in a Custom Code block something like this:
Note - I haven't checked the column names or the date format so debug this carefully!
Bob
				
				
				
			I think that you need to set values for those columns in the form data. You can do this in a Custom Code block something like this:
<?php
$user =& JFactory::getUser();
$form->data['modified_by'] = $user->id;
$form->data['modified_date'] = date('Y-m-d H:i:s');
?>Note - I haven't checked the column names or the date format so debug this carefully!
Bob
				
	
	
		
			?
		
	
			
			
					Hi Bob,
thanks for getting back to me!
I have added a custome code action before the db save in the onsubmit with the following content:
phpMyAdmin reveals that all data has been posted properly.
but I get the following error:
Notice: Undefined index: publish_up in ../administrator/components/com_chronoforms/form_actions/custom_code/custom_code.php(18) : eval()'d code on line 11
would you mind a hint pls ?
				
				
				
			thanks for getting back to me!
I have added a custome code action before the db save in the onsubmit with the following content:
<?php
$user =& JFactory::getUser();
if (JRequest::getInt('token') {
  $form->data['id'] = (int)$form->data['id'];
  $form->data['modified'] = date("Y-m-d H:i:s");
  $form->data['modified_by'] = $user->id; 
} else {
  $form->data['id'] = null;
  $form->data['created'] = date("Y-m-d H:i:s");
  $form->data['created_by'] = $user->id;
  if (!$form->data['publish_up']) $form->data['publish_up'] = $form->data['created'];
}
?>phpMyAdmin reveals that all data has been posted properly.
but I get the following error:
Notice: Undefined index: publish_up in ../administrator/components/com_chronoforms/form_actions/custom_code/custom_code.php(18) : eval()'d code on line 11
would you mind a hint pls ?
					Hi gabrielaH,
It's just a PHP warning that you are using an undeclared variable. You can usually hide these y setting Error Reporting to System Default or None in the Site Global Ssttings. To get rid of it, try replacing
Bob
				
				
				
			It's just a PHP warning that you are using an undeclared variable. You can usually hide these y setting Error Reporting to System Default or None in the Site Global Ssttings. To get rid of it, try replacing
if (!$form->data['publish_up']) $form->data['publish_up'] = $form->data['created'];withif ( !isset($form->data['publish_up']) || !$form->data['publish_up'] ) {
  $form->data['publish_up'] = $form->data['created'];
}Bob
This topic is locked and no more replies can be posted.
		
	
  