Redirect after saving data from CF

porgigi 02 Jul, 2010
Hello. Thank you for everything you do!

"CC" call a "CF" to modify, cancel or change the linked records.
After CF was submit, there is a redirect to "CC" that called it.
My question is: can return to a different page of "CC" after saving data?
Actually I have to keep a common value at "CC" and "CF", which is lost back to "CC"!

thanks
GreyHead 02 Jul, 2010
Hi porgigi,

I'm not sure I understand completely. I think you'd need to set up a custom ReDirect URL in the ChronoForm.


Bob
porgigi 02 Jul, 2010
thanks Bob.
the redirecturl is not static! With this code (Form HTML section) I risolved partially

<?php
$url = "index.php?option=com_chronoconnectivity&connectionname=artnove_conn&cidistruttorias=".$id_istruttoria;
$q = " UPDATE liq_chrono_contact SET redirecturl = '".$url."' WHERE id=69";
mysql_query($q);
if (mysql_error()) { echo mysql_error();}
?>


1) «69» is id of my form;
2) $id_istruttoria is not the primary key
3) $id_istruttoria is a filter value of table under "CC"

Problem: when two users are simultaneously connected with different filter values, it creates a conflict of return.
GreyHead 02 Jul, 2010
Hi porgigi,

Never, never, never do this:
$q = " UPDATE liq_chrono_contact SET redirecturl = '".$url."' WHERE id=69";


Search here are you'll find the code to set the redirect url from form OnSubmit box.

Bob
porgigi 05 Jul, 2010
Thanks, Bob.
I try to give more details, otherwise I pass for a fool.
table of CC is:

IDART9 (primary key),ID_ISTRUTTORIA,ID_VOLONTARIO,ID_DATORE and other fields.

«artnove_conn CC»
section WHERE SQL is
<?php
$selezione = JRequest::getVar('cidistruttorias', 0);
echo " WHERE ID_ISTRUTTORIA = ".$selezione;  
?>

section HEAD is
<?php
$selezione = JRequest::getVar('cidistruttorias',0);
$db =& JFactory::getDBO();
//****************************************************
// idistruttoria is primary key of '#__is_istruttorie'
//****************************************************
$query = " SELECT IDISTRUTTORIA, ISTRUTTORE,DENOMINAZIONE,EVENTO FROM #__is_istruttorie
          where  IDISTRUTTORIA =  ".$selezione." ;";
$db->setQuery( $query );
$result =& $db->loadObject();
$istruttore = $result->ISTRUTTORE;
$denominazione= $result->DENOMINAZIONE;
$evento= $result->EVENTO;
?>
<input name="associazione" value ="<?php echo $denominazione;?>" disabled />
<input name="evento" value ="<?php echo $evento;?>" disabled />

<table>
     <thead>
       <tr>
         <th>VOLONTARIO</th>
         <th>DATORE</th>
         <th>IBAN</th>
         <th>STATO</th>
         <th>IMPORTO LIQUIDABILE</th>
       </tr>
   </thead>
</table>
<table>

section BODY is
<?php
$db =& JFactory::getDBO();
$query = " SELECT DENOM_DAT, LEGALE_RAPPRESENTANTE_DAT, INDIRIZZO_DAT, PROVINCIA_DAT, COMUNE_DAT, CAP_DAT, IBAN_DAT, PARTITA_IVA_DAT, COGNOME_VOL, NOME_VOL, CODFIS_VOL, DENOMINAZIONE_ASS, ID_ISTRUTTORIA
FROM #__view_art9  where  IDART9 =  ".$MyRow->IDART9." ;";

$db->setQuery( $query );
$result =& $db->loadObject();
$denom_dat = $result->DENOM_DAT;
$denominazione_ass= $result->DENOMINAZIONE_ASS;
$iban_dat= $result->IBAN_DAT;
$cognome_vol= $result->COGNOME_VOL;
$nome_vol= $result->NOME_VOL;
?>
<tbody>
    <tr>
       <td><?php echo $cognome_vol. " ".$nome_vol; ?></td>
       <td><?php echo $denom_dat; ?></td>
       <td><?php echo $iban_dat?></td>
       <td>{STATO}</td>
       <td>{IMPORTO_LIQUIDABILE}</td>
       <td>{delete_record}</td>
       <td>
<a href="index.php?option=com_chronocontact&chronoformname=istrutt_art9_form_AGG&cids=<?php echo $MyRow->IDART9; ?>&cidistruttorias=<?php echo $MyRow->ID_ISTRUTTORIA;?>"><img src="images/edit_f2.png" border="0" title="Mofica Art.9" style="width: 20px;" />
</a>
</td>

    </tr>
</tbody>


FOOTER
</table>


code of CF (istrutt_art9_form_AGG):
section HTML

<?php
$selezione = JRequest::getVar('cidistruttorias',0);
$db =& JFactory::getDBO();
$query = " SELECT IDISTRUTTORIA, ISTRUTTORE, DENOMINAZIONE, EVENTO,DATA_INIZIO,
          DATA_FINE, ID_ASSOCIAZIONE FROM #__is_istruttorie
          where  IDISTRUTTORIA =  ".$selezione." ;";
$db->setQuery( $query );
$result =& $db->loadObject();
$istruttore = $result->ISTRUTTORE;
$denominazione= $result->DENOMINAZIONE;
$evento= $result->EVENTO;
$data_inizio= $result->DATA_INIZIO;
$data_fine= $result->DATA_FINE;
$id_associazione = $result->ID_ASSOCIAZIONE;
?>

<div>
 <label><?php echo $istruttore;?></label>
 <label><?php echo $denominazione;?></label>
 <label><?php echo $evento;?></label>
</div>



<?php
$selezione = JRequest::getVar('cids',0);
$db1 =& JFactory::getDBO();
$qry = " SELECT DENOM_DAT, COGNOME_VOL, NOME_VOL, DENOMINAZIONE_ASS, ART9_FLG, ISTRUTTORE,
IDART9, ID_ISTRUTTORIA, ID_DATORE_ART9, ID_DETERMINA_ART9, IBAN_ART9, ID_VOLONTARIO_ART9  
FROM LIQ_VIEW_ART9 WHERE IDART9 = ".$selezione.";";  
$db1->setQuery($qry);
$selezionati = $db1->loadAssocList();

if ($selezionati)
{
   $denom_dat = $selezionati[0]['DENOM_DAT'];  
   $cognome_vol = $selezionati[0]['COGNOME_VOL'];  
   $nome_vol = $selezionati[0]['NOME_VOL'];  
   $denominazione_ass = $selezionati[0]['DENOMINAZIONE_ASS'];  
   $id_istruttoria = $selezionati[0]['ID_ISTRUTTORIA'];
   $id_datore =  $selezionati[0]['ID_DATORE_ART9'];
   $id_volontario = $selezionati[0]['ID_VOLONTARIO_ART9'];
}
else
{  
   $denom_dat = "";  
   $cognome_vol = "";  
   $nome_vol = "";  
   $denominazione_ass = "";  
   $id_istruttoria = 0;
   $id_datore = 0;
   $id_volontario = 0;
}

// this is MY PROBLEM, BOB! 
// I need to update url redirct (to back artnove_conn CC!) because
// I lose $ id_istruttoria

$url = "index.php?option=com_chronoconnectivity&connectionname=artnove_conn&cidistruttorias=".$id_istruttoria;
$q = " UPDATE liq_chrono_contact SET redirecturl = '".$url."' WHERE id=69";
mysql_query($q);
if (mysql_error()) { echo mysql_error();}
$db =& JFactory::getDBO();
$query = " SELECT IDVOLONTARIO, COGNOME, NOME, CODFIS
FROM liq_is_volontario WHERE ID_DATORE =".$id_datore." ORDER BY COGNOME";
$db->setQuery($query);
$nomes = $db->loadAssocList();
$volontario_options = "";
foreach ( $nomes as $v )
{
if ( $id_volontario == $v['IDVOLONTARIO'] ) {
$selected = "selected='selected'";
} else {
$selected = '';
}
$volontario_options .= "<option value='".$v['IDVOLONTARIO']."' $selected >".$v['COGNOME']." ".$v['NOME']."</option>";
}

$db =& JFactory::getDBO();
$query = " SELECT IDDATORE, DENOM_DAT FROM liq_is_datore
WHERE IDDATORE IN ( SELECT DISTINCT (ID_DATORE) FROM liq_is_volontario WHERE ID_ASSOCIAZIONE =".$id_associazione.")";

$db->setQuery($query);
$nomes = $db->loadAssocList();
$datore_options = "";
foreach ( $nomes as $v ) {
if ( $id_datore == $v['IDDATORE'] )
     {
      $selected = "selected='selected'";
     }
     else
     {
       $selected = '';
     }  
$datore_options .= "<option value='".$v['IDDATORE']."' $selected >".$v['DENOM_DAT']."</option>";
}
?>
     
<div class="form_item">  
  <div class="form_element cf_dropdown">    
     <label class="cf_label" style="width: 150px;">Datore di lavoro</label>    
     <select class="cf_inputbox validate-selection" id="select_datore"  name="ID_DATORE" onChange="select_iban_volontario(this.form);">        
     <?php echo $datore_options; ?>    
     </select>  
  </div>  
  <div class="cfclear"> </div>
</div>
<input type="text" maxlength="27" size="35" id="ibandat" name="IBAN_DAT" readonly/>  
<div class="form_item">
 <div class="form_element cf_dropdown">
   <label class="cf_label" style="width: 150px;">Volontario</label>
   <select class="cf_inputbox validate-selection" id="select_volontario" size="1" title=""  name="ID_VOLONTARIO">
      <?php echo $volontario_options; ?>
   </select>
 </div>
 <div class="cfclear"> </div>
</div>
<input class="cf_inputbox" maxlength="2" size="4" title="" id="N_GIORNI" name="N_GIORNI" type="text" />  
<input type="hidden" name="ID_ISTRUTTORIA" value="<?php echo $id_istruttoria;?>"/>
<input type="hidden" name="IDART9" value="{IDART9}"/>
<input class="cf_inputbox" maxlength="11" size="12" title="" id="liquidabile" name="IMPORTO_LIQUIDABILE" type="text" onChange="aggiornacampi(this.form);"/>  
<input id="liquidato" name="IMPORTO_LIQUIDATO" type="hidden"/>
<div class="form_item">
<div class="form_element cf_dropdown">
<label class="cf_label" style="width: 150px;">Stato</label>
<select class="cf_inputbox" id="STATO" size="1" title="" name="STATO">
   <option value="">scegli una opzione</option>
   <option value="DA ISTRUIRE">DA ISTRUIRE</option>
   <option value="DA INTEGRARE">DA INTEGRARE</option>
   <option value="IN CORSO">IN CORSO</option>
   <option value="LIQUIDABILE">LIQUIDABILE</option>      
   <option value="NON LIQUIDABILE">NON LIQUIDABILE</option>    
</select>  
</div>  
<div class="cfclear"> </div>
</div>

<!--  Conferma/reset-->
<div class="form_item">  
<div class="form_element cf_button">    
   <input value="Conferma" name="button_5" type="submit"/>    
   <input type="reset" name="reset" value="Reset"/>    
   <input type="button" value="Indietro" onClick="javascript: history.go(-1)">  
</div>  
<div class="cfclear"> </div>
</div>


section SCRIPTCODE is not important for my problem (update combo related)
function select_iban_volontario(form)
{  
....
....
}
GreyHead 05 Jul, 2010
Hi porgigi,

Where do you want to redirect to?

Bob
porgigi 06 Jul, 2010
Azz! I fear not being precise.
From CC art9_conn, this link (section body)
<a href="index.php?option=com_chronocontact&chronoformname=istrutt_art9_form_AGG&cids=<?php echo $MyRow->IDART9; ?>&cidistruttorias=<?php echo $MyRow->ID_ISTRUTTORIA;?>">Mofica Art.9 />

calls form template CF (istrutt_art9_form_AGG) for update record.
After submit (and saving data) I want to redirect to
index.php?option=com_chronoconnectivity&connectionname=artnove_conn&cidistruttorias=".$id_istruttoria

I have to preserv $id_istuttoria after submit and saving!
thanks Bob
GreyHead 07 Jul, 2010
Hi porgigi,

Try this in the Form HTML
<?php
if ( !$mainframe->isSite() ) { return; }
$cidistruttorias =& JRequest::getInt('cidistruttorias', 0, 'get');
$url = 'index.php?option=com_chronoconnectivity&connectionname=artnove_conn';
if ( $cidistruttorias ) {
  $url .= '&cidistruttorias='.$cidistruttorias;
}
$MyForm->formmrow->redirecturl = $url;
?>


Bob
porgigi 12 Jul, 2010
hi Bob, Thanks.
I have been out for a few days.
I try your code, but it does not work 😟.
After Submit (data is saved), return to url:
index.php?option=com_chronocontact&task=send&chronoformname=istrutt_art9_form_AGG
and not to url:
index.php?option=com_chronoconnectivity&connectionname=artnove_conn&cidistruttorias=1  

in the previous example $cidistruttorias=1.
GreyHead 12 Jul, 2010
Hi porgigi,

My mistake I think, try the code in the OnSubmit After Email box instead.

Bob
porgigi 12 Jul, 2010
Hi Bob,
with the code in On Submit code - after sending email, I still remain to url:
index.php?option=com_chronocontact&task=send&chronoformname=istrutt_art9_form_AGG
porgigi 13 Jul, 2010
Hi Bob.
I must add that on the «istrutt_art9_form_AGG» form has been activated the plugin profile page.
It may happen that this plugin may conflict with your code?
<?php
if ( !$mainframe->isSite() ) { return; }
$cidistruttorias =& JRequest::getInt('cidistruttorias', 0, 'get');
$url = 'index.php?option=com_chronoconnectivity&connectionname=artnove_conn';
if ( $cidistruttorias ) {
  $url .= '&cidistruttorias='.$cidistruttorias;
}
$MyForm->formmrow->redirecturl = $url;
?>

thanks
GreyHead 13 Jul, 2010
Hi porgigi,

Possibly, please test it to see.

Bob
porgigi 13 Jul, 2010
hi BOB.
nothing! I try without profile page and it don't worked. I very :?
I think that I leave the internal form code update to redirecturl field in table liq_chrono_contact.
thanks all!
porgigi 20 Jul, 2010
Hi, Bob.
I finally solved this way:
in FORM HTML of CF's «istrutt_art9_form_AGG»
<?php
if ($id_istruttoria == "")
{ 	$id_istruttoria = JRequest::getVar('cidistruttorias',0);  };

$url = "index.php?option=com_chronoconnectivity&connectionname=artnove_conn&cidistruttorias=".$id_istruttoria;
?>

<input name="myredirectlink" value="<?php echo $url;?>" type="hidden" />


and I hack (😶 ) chronoform.php at line 495 in:
if ( !empty($MyForm->formrow->redirecturl)) 
{
   if   ( !$debug ) 
        {
        $mainframe->redirect($MyForm->formrow->redirecturl);
        } 
   else {
	$MyForm->addDebugMsg("<div class='debug' >Redirect link set, click to test:<br /><a href='".$MyForm->formrow->redirecturl."'>".$MyForm->formrow->redirecturl."</a></div>");
        }
} 
// porgigi
else	
{ 
    if ( !empty($posted['myredirectlink'])) { $mainframe->redirect($posted['myredirectlink']);}
} // porgigi 


Thanks Bob.
This topic is locked and no more replies can be posted.