Use SELECT result in the form

AndreaZ 21 Mar, 2010
I have a chronoforms form wich edits a chronoconnectivity record.
In the form code I select data from a database table (the email address of the user wich entered the record) and I put the information in the current session. Then, in the on submit before, I need to get the information from the session to send an email to the user.

The problem is that I retrieve correctly data from the database table (I can see data with echo command) but, when I submit the form, I don't have anymore the information available in the current session; I think the form is refreshed when submitted and data are not written in the session.

Can anyone help me to have available in the on submit data selected in the form code ?

The code in form code is:
<?php
$session =& JFactory::getSession();

print "<h1>Manutenzione richiesta</h1>";
print "<br>";

// Get user-information from Joomla
$user = &JFactory::getUser();
$utente = $user->username;

// Lancia la query e legge i dati dalla tabella
$db =& JFactory::getDBO();
$data = date("Y/m/d");
$query = "SELECT id, tipo, movimento FROM `#__users_tipomovimenti`
  WHERE tipo = 'C'";
$db->setQuery($query);
$result = $db->loadAssocList();

// Lancia la query e legge i dati dalla tabella
$selezione = JRequest::getString('cids', '', 'get');
$query = "SELECT id, user FROM `#__chronoforms_informazioni`
  WHERE id = ".$selezione;
$db->setQuery($query);
$nomes = $db->loadRow();
$utente_nome = $nomes[1];

$query = "SELECT id, email FROM `#__users`
  WHERE username = ".chr(34).$utente_nome.chr(34);
$db->setQuery($query);
$nomes = $db->loadRow();
$utente_email = $nomes[1];
$session->set('toemail', "$utente_email");
?>

<div class="form_item">
  <div class="form_element cf_dropdown">
    <label class="cf_label" style="width: 100px;">Richiesta</label>
    <select class="cf_inputbox validate-selection" id="select_6" size="1" title="Selezione obbligatoria"  name="id_richiesta">
    <option value="">Selezionare richiesta</option>
      <?php foreach($result as $val) {
echo "<option value='" . $val['id'] . "'>" . $val['movimento'] . "</option>";
                                     }
?>
    </select>
    <a class="tooltiplink" onclick="return false;"><img height="16" border="0" width="16" class="tooltipimg" alt="" src="components/com_chronocontact/css/images/tooltip.png"/></a>
<div class="tooltipdiv">Richiesta :: Selezionare la richiesta</div>
  </div>
  <div class="cfclear"> </div>
</div>

<div class="form_item">
  <div class="form_element cf_textbox">
    <label class="cf_label" style="width: 100px;">Denominazione</label>
    <input class="cf_inputbox required" maxlength="100" size="30" title="La denominazione è richiesta" id="text_1" name="denominazione" type="text" />
  
  </div>
  <div class="cfclear"> </div>
</div>

<div class="form_item">
  <div class="form_element cf_textbox">
    <label class="cf_label" style="width: 100px;">Località</label>
    <input class="cf_inputbox" maxlength="100" size="30" title="" id="text_2" name="localita" type="text" />
  <a class="tooltiplink" onclick="return false;"><img height="16" border="0" width="16" class="tooltipimg" alt="" src="components/com_chronocontact/css/images/tooltip.png"/></a>
				<div class="tooltipdiv">Località :: Si consiglia di inserire la località quando non è inserito il codice fiscale</div>
  </div>
  <div class="cfclear"> </div>
</div>

<div class="form_item">
  <div class="form_element cf_textbox">
    <label class="cf_label" style="width: 100px;">Codice fiscale</label>
    <input class="cf_inputbox validate-alphanum" maxlength="16" size="16" title="" id="text_3" name="codicefiscale" type="text" />
  <a class="tooltiplink" onclick="return false;"><img height="16" border="0" width="16" class="tooltipimg" alt="" src="components/com_chronocontact/css/images/tooltip.png"/></a>
				<div class="tooltipdiv">Codice fiscale :: Consigliato inserire il codice fiscale per facilitare la ricerca</div>
  </div>
  <div class="cfclear"> </div>
</div>

<div class="form_item">
  <div class="form_element cf_dropdown">
    <label class="cf_label" style="width: 100px;">Stato</label>
    <select class="cf_inputbox validate-selection" id="select_0" size="1" title="Stato obbligatorio"  name="stato">
    <option value="">Scegli stato</option>
      <option value="Evasa">Evasa</option>
<option value="Inoltrata">Inoltrata</option>
<option value="Sospesa">Sospesa</option>
<option value="Annullata">Annullata</option>

    </select>
    
  </div>
  <div class="cfclear"> </div>
</div>

<div class="form_item">
  <div class="form_element cf_button">
    <input value="Aggiorna" name="button_4" type="submit" />
  </div>
  <div class="cfclear"> </div>
</div>


In the on submit before email I have:
 Get user-information from Joomla
$user = &JFactory::getUser();
$utente = $user->username;

$session =& JFactory::getSession();
$value = $session->get('toemail');

JRequest::setVar('to_email', $value);
?>


Thanks to all of you for the attention.
GreyHead 21 Mar, 2010
Hi AndreaZ,

Looks like a lot of work.

If you want to send an email to the current user and have a Dynamic To with to_email in the box then put this code in the OnSubmit Before box
<?php
//Get user-information from Joomla
$user =& JFactory::getUser();
JRequest::setVar('to_email', $user->email);
?>
You don't need anything in the Form HTML.

Bob
AndreaZ 21 Mar, 2010
Hi Bob.

Thanks for the prompt reply.

It's not so easy. I don't need to send email to the current user, but to the user wich entered a certain request that I'm editing in my form. So I need to see the user id and than search in the users table the email address and send the email. My problem is with the select SQL command in the form when I submit the form.

Thanks again for your courtesy.
GreyHead 21 Mar, 2010
Hi AndreaZ,

In that case put the username into a hidden input in the Form HTML
<input type='hidden' name='username' value='<?php echo $utente_nome; ?>' />
and use that go get the email in the OnSubmit Before box
<?php
//Get user-information from Joomla
$username =  JRequest:;getString('username', '', 'post');
$user =& JFactory::getUser($username);
JRequest::setVar('to_email', $user->email);
?>

Bob
AndreaZ 22 Mar, 2010
Hi Bob,

thanks again.

I have modified my form as suggested but, when I submit the form, I have an error:

JUser::_load: User does not exist

probably the code in on submit before is not able to find the $username.

Here my code.
<?php
//$session =& JFactory::getSession();

print "<h1>Manutenzione richiesta</h1>";
print "<br>";

// Get user-information from Joomla
$user = &JFactory::getUser();
$utente = $user->username;

// Lancia la query e legge i dati dalla tabella
$db =& JFactory::getDBO();
$data = date("Y/m/d");
$query = "SELECT id, tipo, movimento FROM `#__users_tipomovimenti`
  WHERE tipo = 'C'";
$db->setQuery($query);
$result = $db->loadAssocList();

// Lancia la query e legge i dati dalla tabella
$selezione = JRequest::getString('cids', '', 'get');
$query = "SELECT id, user FROM `#__chronoforms_informazioni`
  WHERE id = ".$selezione;
$db->setQuery($query);
$nomes = $db->loadRow();
$utente_nome = $nomes[1];

//$query = "SELECT id, email FROM `#__users`
//WHERE username = ".chr(34).$utente_nome.chr(34);
//$db->setQuery($query);
//$nomes = $db->loadRow();
//$utente_email = $nomes[1];
//$session->set('toemail', "$utente_email");
echo $utente_nome;
?>

<input type='hidden' name='username' value='<?php echo $utente_nome; ?>' />

<div class="form_item">
  <div class="form_element cf_dropdown">
    <label class="cf_label" style="width: 100px;">Richiesta</label>
    <select class="cf_inputbox validate-selection" id="select_6" size="1" title="Selezione obbligatoria"  name="id_richiesta">
    <option value="">Selezionare richiesta</option>
      <?php foreach($result as $val) {
echo "<option value='" . $val['id'] . "'>" . $val['movimento'] . "</option>";
                                     }
?>
    </select>
    <a class="tooltiplink" onclick="return false;"><img height="16" border="0" width="16" class="tooltipimg" alt="" src="components/com_chronocontact/css/images/tooltip.png"/></a>
<div class="tooltipdiv">Richiesta :: Selezionare la richiesta</div>
  </div>
  <div class="cfclear"> </div>
</div>

<div class="form_item">
  <div class="form_element cf_textbox">
    <label class="cf_label" style="width: 100px;">Denominazione</label>
    <input class="cf_inputbox required" maxlength="100" size="30" title="La denominazione è richiesta" id="text_1" name="denominazione" type="text" />
  
  </div>
  <div class="cfclear"> </div>
</div>

<div class="form_item">
  <div class="form_element cf_textbox">
    <label class="cf_label" style="width: 100px;">Località</label>
    <input class="cf_inputbox" maxlength="100" size="30" title="" id="text_2" name="localita" type="text" />
  <a class="tooltiplink" onclick="return false;"><img height="16" border="0" width="16" class="tooltipimg" alt="" src="components/com_chronocontact/css/images/tooltip.png"/></a>
				<div class="tooltipdiv">Località :: Si consiglia di inserire la località quando non è inserito il codice fiscale</div>
  </div>
  <div class="cfclear"> </div>
</div>

<div class="form_item">
  <div class="form_element cf_textbox">
    <label class="cf_label" style="width: 100px;">Codice fiscale</label>
    <input class="cf_inputbox validate-alphanum" maxlength="16" size="16" title="" id="text_3" name="codicefiscale" type="text" />
  <a class="tooltiplink" onclick="return false;"><img height="16" border="0" width="16" class="tooltipimg" alt="" src="components/com_chronocontact/css/images/tooltip.png"/></a>
				<div class="tooltipdiv">Codice fiscale :: Consigliato inserire il codice fiscale per facilitare la ricerca</div>
  </div>
  <div class="cfclear"> </div>
</div>

<div class="form_item">
  <div class="form_element cf_dropdown">
    <label class="cf_label" style="width: 100px;">Stato</label>
    <select class="cf_inputbox validate-selection" id="select_0" size="1" title="Stato obbligatorio"  name="stato">
    <option value="">Scegli stato</option>
      <option value="Evasa">Evasa</option>
<option value="Inoltrata">Inoltrata</option>
<option value="Sospesa">Sospesa</option>
<option value="Annullata">Annullata</option>

    </select>
    
  </div>
  <div class="cfclear"> </div>
</div>

<div class="form_item">
  <div class="form_element cf_button">
    <input value="Aggiorna" name="button_4" type="submit" />
  </div>
  <div class="cfclear"> </div>
</div>


<?php
// Get user-information from Joomla
$username = JRequest::getString('username', '', 'post');
$cliente = &JFactory::getUser($username);
JRequest::setVar('to_email', $cliente->email);
?>
GreyHead 22 Mar, 2010
Hi AndreaZ,

Pleae will you check the Page Source to make sure that there is a valid username in the hidden input.

Bob
AndreaZ 22 Mar, 2010
Hi Bob.

I have checked and the username is correct.

In my case the username is T444 and, if I check in my form with the command echo $username; I see T444.

I have tried, in on submit before box, to put the code:

<?php
// Get user-information from Joomla
$username = JRequest::getString('username', '', 'post');
//$cliente = &JFactory::getUser($username);
$cliente = &JFactory::getUser("T444");
JRequest::setVar('to_email', $cliente->email);
?>


and it works.

I think the problem is that, when I submit the form, I loose the information in the $utentenome variable and so nothing is posted to the on submit before box.

Thanks for the attention.

Andrea
GreyHead 22 Mar, 2010
Hi Andrea,

Something is wrong here. If the value is in the form html that it should be available to the OnSubmit box. Do you have another input with name='username'??

Can you post a link to the form?

Bob
AndreaZ 22 Mar, 2010
Hi Bob.

Now I have changed the 'username' field in 'userclient' field, but I have the same problem.

To view the form:

http://www.azrete.it/index.php?option=com_chronoconnectivity&connectionname=Informazioni_Amministrazione

If you click under Email you can edit che row and open my form.

In the form you find my echo $utente_nome which is 'T444'. When you submit you see the error.

Here I post the updated code:

<?php
//$session =& JFactory::getSession();

print "<h1>Manutenzione richiesta</h1>";
print "<br>";

// Get user-information from Joomla
$user = &JFactory::getUser();
$utente = $user->username;

// Lancia la query e legge i dati dalla tabella
$db =& JFactory::getDBO();
$data = date("Y/m/d");
$query = "SELECT id, tipo, movimento FROM `#__users_tipomovimenti`
  WHERE tipo = 'C'";
$db->setQuery($query);
$result = $db->loadAssocList();

// Lancia la query e legge i dati dalla tabella
$selezione = JRequest::getString('cids', '', 'get');
$query = "SELECT id, user FROM `#__chronoforms_informazioni`
  WHERE id = ".$selezione;
$db->setQuery($query);
$nomes = $db->loadRow();
$utente_nome = $nomes[1];

//$query = "SELECT id, email FROM `#__users`
//WHERE username = ".chr(34).$utente_nome.chr(34);
//$db->setQuery($query);
//$nomes = $db->loadRow();
//$utente_email = $nomes[1];
//$session->set('toemail', "$utente_email");
echo $utente_nome;
?>

<input type='hidden' name='userclient' value='<?php echo $utente_nome; ?>' />

<div class="form_item">
  <div class="form_element cf_dropdown">
    <label class="cf_label" style="width: 100px;">Richiesta</label>
    <select class="cf_inputbox validate-selection" id="select_6" size="1" title="Selezione obbligatoria"  name="id_richiesta">
    <option value="">Selezionare richiesta</option>
      <?php foreach($result as $val) {
echo "<option value='" . $val['id'] . "'>" . $val['movimento'] . "</option>";
                                     }
?>
    </select>
    <a class="tooltiplink" onclick="return false;"><img height="16" border="0" width="16" class="tooltipimg" alt="" src="components/com_chronocontact/css/images/tooltip.png"/></a>
<div class="tooltipdiv">Richiesta :: Selezionare la richiesta</div>
  </div>
  <div class="cfclear"> </div>
</div>

<div class="form_item">
  <div class="form_element cf_textbox">
    <label class="cf_label" style="width: 100px;">Denominazione</label>
    <input class="cf_inputbox required" maxlength="100" size="30" title="La denominazione è richiesta" id="text_1" name="denominazione" type="text" />
  
  </div>
  <div class="cfclear"> </div>
</div>

<div class="form_item">
  <div class="form_element cf_textbox">
    <label class="cf_label" style="width: 100px;">Località</label>
    <input class="cf_inputbox" maxlength="100" size="30" title="" id="text_2" name="localita" type="text" />
  <a class="tooltiplink" onclick="return false;"><img height="16" border="0" width="16" class="tooltipimg" alt="" src="components/com_chronocontact/css/images/tooltip.png"/></a>
				<div class="tooltipdiv">Località :: Si consiglia di inserire la località quando non è inserito il codice fiscale</div>
  </div>
  <div class="cfclear"> </div>
</div>

<div class="form_item">
  <div class="form_element cf_textbox">
    <label class="cf_label" style="width: 100px;">Codice fiscale</label>
    <input class="cf_inputbox validate-alphanum" maxlength="16" size="16" title="" id="text_3" name="codicefiscale" type="text" />
  <a class="tooltiplink" onclick="return false;"><img height="16" border="0" width="16" class="tooltipimg" alt="" src="components/com_chronocontact/css/images/tooltip.png"/></a>
				<div class="tooltipdiv">Codice fiscale :: Consigliato inserire il codice fiscale per facilitare la ricerca</div>
  </div>
  <div class="cfclear"> </div>
</div>

<div class="form_item">
  <div class="form_element cf_dropdown">
    <label class="cf_label" style="width: 100px;">Stato</label>
    <select class="cf_inputbox validate-selection" id="select_0" size="1" title="Stato obbligatorio"  name="stato">
    <option value="">Scegli stato</option>
      <option value="Evasa">Evasa</option>
<option value="Inoltrata">Inoltrata</option>
<option value="Sospesa">Sospesa</option>
<option value="Annullata">Annullata</option>

    </select>
    
  </div>
  <div class="cfclear"> </div>
</div>

<div class="form_item">
  <div class="form_element cf_button">
    <input value="Aggiorna" name="button_4" type="submit" />
  </div>
  <div class="cfclear"> </div>
</div>


and on submit before box:

<?php
// Get user-information from Joomla
$userclient = JRequest::getString('userclient', '', 'post');
$client = &JFactory::getUser($userclient);
JRequest::setVar('to_email', $client->email);
?>


Thanks and regards.

Andrea
AndreaZ 22 Mar, 2010
Sorry Bob but the link posted in the previous post doesn't work because the site is not yet public.
GreyHead 22 Mar, 2010
Hi Andrea,

Thanks - I tried it and found it wasn't working :-(

Where does ChronoConnectivity fit into the work-flow here? I thought that your two code blocks were Form HTML and OnSubmit code for the same ChronoForm?

Bob
AndreaZ 22 Mar, 2010
Hi Bob.

You're right. Form code and on submit before box are in the same chronoform.

I use the form to edit a chronoconnectivity record, and work as follows:

-) user (username T444 in my example) inserts a request;
-) I read the request editing a chronoconnectivity record with my form and answer to the user T444
-) I send, when submit the form, an automatic email message to inform the user T444 I have updated his request; to do this I read the username (T444), I search for the corresponding email address, and send the email.

I don't understand why I'm not able to pass the username value from the form code box to the on submit before box. Could be something in the general tab ?

Thanks, Andrea
AndreaZ 23 Mar, 2010
Well Bob,

making some extra tests I have understood that:

If I test the chronoform from the link in backend it works correctly; the value of hidden field in form html code is passed to the on submit before box, and email is sent;

If I use the chronoform to edit a chronoconnectivity record it doesn't work, probably because when submitted, it automatically returns to chronoconnectivity without sending email.

Do you already knew this kind of problem and how to solve it?

What could be an alternative solution, without use chronoconnectivity to edit records and choose which of them to edit ?

Thanks and regards.

Andrea
GreyHead 23 Mar, 2010
Hi Andrea,

Sorry, I've been busy with some client work and ignoring this.

What I have done it not to use {edit_record} but to code in the direct link to the ChronoForm in the ChronoConnectivity body (adding the appropriate ids in the url). I don't know if this would work for you but it does seem to avoid some of the problems between the two apps.

Bob
AndreaZ 23 Mar, 2010
Hi Bob,

don't worry for the time.

I've tried to link directly the chronoform from chronoconnectivity body (without {edit}), but when I submit the form it returns automatically to chronoconnectivity, and it doesn't send emails.

Do you know if there is a way to avoid the automatic return to chronoconnectivity after submitting the form ?

If I remove the record edit form in chronoconnectivity it doesn't work for editing.

Regards.

Andrea
AndreaZ 24 Mar, 2010
Well Bob

I think we can close this post.

I understood why it didn't work.
When chronoform is part of chronoconnectivity, to edit the records, it returns automatically to chronoconnectivity when submitted the form, and doesn't pass values from form code box to the on submit before box, and so doesn't send emails. It's a bug, I think.

Now it works because I have linked directly my chronoform from chronoconnectivity, without using {edit_record}, and when submitted the form and email was sent, I don't redirect immediately to chronoconnectivity.

I'll insert this message in bug forum.

Thank you again for the interest and the capability and good luck for the future and for your job.


My best regards, Andrea
This topic is locked and no more replies can be posted.