I have a Form with a Custom element and a Submit button. It was working fine but now when I press the submit button it doesn't Save but starts to download a file called index.gz. I don't know what is going on here. Any ideas?
Hi peterswa62,
No idea, that's a new one to me.
What's in the Custom Code action?
Bob
No idea, that's a new one to me.
What's in the Custom Code action?
Bob
This is on a Custom Element:-
This is Custom Code On Submit:-
Apart from that there is a Submit button on the Chronoform nothing else.
<?php
$user =& JFactory::getUser();
$userGroups = $user->getAuthorisedGroups();
$session =& JFactory::getSession();
if ( in_array( '2', $userGroups ) ) {
$session->set('userid',$user->id);
$session->set('group','registered');
//echo "Registered User!";
}
elseif ( in_array( '8', $userGroups ) ) {
if (JRequest::getVar('token') != ''){
$param = JRequest::getVar('token');
$session->set('userid',$param);
$session->set('group','superuser');
}
//echo "Super User!";
}
elseif ( in_array( '7', $userGroups ) ) {
if (JRequest::getVar('token') != ''){
$param = JRequest::getVar('token');
$session->set('userid',$param);
$session->set('group','administrator');
}
}
else{
$mainframe->redirect('index.php','Access denied');
}
$session =& JFactory::getSession();
$userid = $session->get('userid');
$db =& JFactory::getDBO();
$query = "SELECT id,userid,employer_name_address,dates_of_employment, position, reason_for_leaving FROM tvs5y_custom_app1_employment_history WHERE USERID = {$userid}";
$db->setQuery($query);
$rows = $db->loadObjectList();
//$row['index'] // e.g. $row['2']
// set the total count
$x = count($rows);
$count = 20;
//$rowcount = 0;
$employer = "";
$dates ="";
$position = "";
$reason = "";
$id = "0";
for ( $i = 1, $rc = 0; $i <= $count; $i++, $rc++ )
{
// add classes which will let us identify the inputs to hide
if ( $i == 1 ) {
$class = 'show_me';
if( $rc == 0 && $x > 0 ){
$employer = $rows[$rc]->employer_name_address;
$dates = $rows[$rc]->dates_of_employment;
$position = $rows[$rc]->position;
$reason = $rows[$rc]->reason_for_leaving;
$id = $rows[$rc]->id;
}
}
elseif( $rc < $x ) {
$employer = $rows[$rc]->employer_name_address;
$dates = $rows[$rc]->dates_of_employment;
$position = $rows[$rc]->position;
$reason = $rows[$rc]->reason_for_leaving;
$id = $rows[$rc]->id;
$class = 'show_me';
} else {
$employer = '';
$dates = '';
$position = '';
$reason = '';
$id = '0';
$class = 'hide_me';
}
// add the 'Add one' buttons (but not to the last set)
if ( $i < $count ) {
$j = $i+1;
$button = "<input type='button' name='addone_{$j}' id='addone_{$j}' value='Add one' class='add_one' />";
} else {
$button = "";
}
// add the inputs with a little ChronoForms styling
echo "<input type='hidden' value='0' name='recipient[{$i}][id]' id='recipient_{$i}_id'/>
<div id='recipient_{$i}' class='{$class}' >
<div class='multicell'>
<label style='width:100%;'>Name and Address of Employer</label>
<textarea rows='6' name='recipient[{$i}][employer_name_address]' id='recipient_{$i}_name' class='textarea1'>{$employer}</textarea>
</div>
<div class='multicell2'>
<label style='width:100%;'>Dates of Employment</label>
<textarea name='recipient[{$i}][dates_of_employment]' rows='6' id='recipient_{$i}_dates' class='textarea2'>{$dates} </textarea>
</div>
<div class='multicell'>
<label style='width:100%;'>Position and summary of duties</label>
<textarea name='recipient[{$i}][position]' rows='6' id='recipient_{$i}_position' class='textarea1'>{$position} </textarea>
</div>
<div class='multicell2'>
<label style='width:100%;'>Reason for leaving</label>
<textarea name='recipient[{$i}][reason_for_leaving]' rows='6' id='recipient_{$i}_reason' class='textarea2'>{$reason}
</textarea>
</div>
<div class='multicell3'>
</br></br>
{$button}
</div>
<input type='hidden' value='0' name='recipient[{$i}][userid]' id='recipient_{$i}_userid'/>
<input type='hidden' value={$id} name='recipient[{$i}][id]' id='recipient_{$i}_id'/>
<div id ='test'>
</div>
";
}
?>
This is Custom Code On Submit:-
<?php
$Saved = false;
foreach($form->data['recipient'] as $record){
if ($record[id] == '0') {
if(
(strlen($record[employer_name_address]) == 0) &&
(strlen($record[reason_for_leaving]) == 0)
)
{
echo "Empty ";
} else {
$record[id] = NULL;
$session =& JFactory::getSession();
$record[userid] = $session->get('userid');
$Saved = SaveRecord($record);
}
} else {
if(
(strlen($record[employer_name_address]) == 0) &&
(strlen($record[reason_for_leaving]) == 0)
)
{
echo "Empty ";
} else {
$session =& JFactory::getSession();
$record[userid] = $session->get('userid');
$Saved = SaveRecord($record);
}
}
}
if($Saved){
JFactory::getApplication()->enqueueMessage('Saved');
}
else{
JError::raiseError( 100, 'An error occurred' );
}
/*************functions************/
function SaveRecord($record)
{
$db = JFactory::getDBO();
$table1 = 'tvs5y_custom_app1_employment_history';
$row = (object)$record;
if($db->insertObject($table1 , $row )){
return true;
}
else{
return false;
}
}
?>
Apart from that there is a Submit button on the Chronoform nothing else.
This topic is locked and no more replies can be posted.