Insert selected value in array/drop down in database

Asked

Viewed 635 times

1

Next: Use the Rsform! and instead of using the functionality Mapping that it offers, I do the script of Update (if the logged-in user already has registration) and Insert (if not). This script is inserted in the part "Script called on form process". Here I do the tests and update or enter the data in the database. My problem is in the following: I have 1 drop down in the form whose items are assigned through an array, as code below:

*//<code>
$items = array('','1|Solteiro','2|Casado','3|Marital','4|Desquitado','5|Divorciado','6|Viúvo','7|Outros');
$db = JFactory::getDbo();
$idUsuarioLogado = JFactory::getUser()->id;
$db->setQuery("SELECT estado_civil FROM minha_tabela WHERE id_usuario = $idUsuarioLogado");
$result = $db->loadObject();

foreach ($items as $chave => $item) {
  if($result->estado_civil == $chave){
    $items[$chave] = $item."[c]";
  }else{
    $items[$chave] = $item;
  }
}
$items = implode("\n", $items);
return $items;
//</code>*

When the user is logged in and already has registration, he brings the data from the database and fills the drop down. When not, it fills in the list for the user to choose.

The problem is: how do I enter in the bank the value selected in the drop down?

'Cause if I just take it like this: $estado_civil = $_POST['form']['estadocivil']; It returns an array to me and inserts nothing into the database.

Someone has a light?

PS: When I use functionality Mapping and make a INSERT, it normally inserts the drop down data into the database. I do not use the Mapping because I need to test if I’m going to give a UPDATE or a INSERT at the bank. And I haven’t found out if it’s possible to do this test using this feature.

  • By chance this array has values like array([0] = > 1 [1] => single)?

  • Yes, the array looks like this.

1 answer

1


Everything indicates that Rsform! transforms the value of select into an array where the first element is the code of the option and the second is the option itself. In this case, just get the information you want on:

$_POST['form']['estadocivil'][1]

Assuming that "1" is the index corresponding to the value.

  • Thank you so much! Rsform! really does it.. Solved my problem!

  • @Welcome to Stackoverflow! If this answer solved your problem you can also mark as accepted.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.