Forums

build form with data from db

federcla 05 Jul, 2013
hi,
can i build a form with data from the db?

I should make a page similar to an email list, with a checkbox as the first field of the list. for to change only the rows that are checked

I do not know the number of rows that returns the db

I have to build the form I in the Custom Code?

tks
GreyHead 07 Jul, 2013
Hi federcla,

I think that you could do that but it would need to use mostly Custom Code.

Bob

PS Possibly it could be done in ChronoConnectivity?
federcla 08 Jul, 2013
I do not know ChronoConnectivity

ok, I do it in code, it seems to me the best solution

thanks
federcla 09 Jul, 2013
how can I call a form from code?

I have this code in the action but what can I use to call another page?


<form method="post" action=" page or form??? ">
 <input type="checkbox" name="myCheck[a]" value="Valore A" /> Valore A
 <br />
 <input type="checkbox" name="myCheck[b]" value="Valore B" /> Valore B
 <br />
 <input type="checkbox" name="myCheck[c]" value="Valore C" /> Valore C
 <br />
 <input type="submit" value="invia form" />
</form>


i should perhaps use the global variable $ data [] to insert the form values​​?

tks
GreyHead 09 Jul, 2013
Hi federcla,

I'm sorry, I don't understand what you are trying to do here. Is this in a ChronoForm? If so then you probably don't need the <form> tags????

Bob
federcla 09 Jul, 2013
sorry,

I'm building a form with data that I get from a db

the form has the following fields:
checkbox
text box
dropdown

I created a form with ChronoForms and inserted into a Custom Code Action, the code for to create the fields

Now I have to put a button to send the information to the database selected in the form, but since I'm using choronoforms I have a lot 'of doubts.

I have to create a forms? how do I send the user's selection?

I hope I have explained better what I'm trying to do

tks
federcla 09 Jul, 2013
ok, adding a submit button I can handle sending data, I was stuck on a stupid problem.

but now I do not know how to send data for processing,

I create a table with the data that I fetch from the db, the first field of the table is a checkbox, the last one is a select option


foreach ($caricoDatiTemp as $caricoDT) 
  { 
    echo '<tr><td><input type=checkbox name=prova value='.$caricoDT['1'].' /></td>';
    echo '<td>'.$caricoDT['1'].'</td>';
    echo '<td>'.$caricoDT['2'].'</td>';
    echo '<td><select name="mydropdown">
          <option value="0"> </option>
          <option value="1">Costi Manutenzioni</option>
          <option value="2">Servizi Utenze</option>
          <option value="3">Beni Terzi</option>
          <option value="4">Costi Personale</option>
          <option value="5">Oneri Diversi</option>
          <option value="6">Ammortamenti</option>
          <option value="7">Gestione Finanziaria</option>
          </select></td>';
  } 


I would like to only process the data in rows that have the flag in the checkbox, but I can not make it work.

can you help me?

tks
GreyHead 09 Jul, 2013
Hi federcla,

This code won't work because every checkbox (and every select) has the same name so only the last one will be submitted. You will need to give them different names.

I'm still not clear what you are trying to do here?

Bob
federcla 10 Jul, 2013
hi,
I'll try to explain better what I'm doing🙂

I created a form and in the Actions->On Load I posted a Custom Code with PHP code that reads data from a db table and prints the image checkbox.png

now I have to make sure that the data selected with checkboxes, are inserted into another table.

I modified the code but still can not get it to work


foreach ($caricoDatiTemp as $caricoDT) 
  {   
    echo '<tr><td><input type="checkbox" name="prova[]" value="'.$caricoDT['1'].'" /></td>';
    echo '<td>'.$caricoDT['1'].'</td>';
    echo '<td>'.$caricoDT['2'].'</td>';
  }  


in a custom code in the Actions->On Submit I would like to take the data to be able to do the insert in db

but I'm definitely something wrong😟

thanks for the help
GreyHead 11 Jul, 2013
Hi federcla,

What does the Debugger output look like?

What code are you using to save the results? The DB Save action won't save multiple rows.

Bob
federcla 11 Jul, 2013
hello bob,
I was getting worried that you were not online🙂

the problem is that I do not know how to get the data to another custom code, I was thinking - hoping that they could save themselves automatically in the global variable $data di choronoforms, so as to recover

at the moment I do not mind the inclusion in the database, if I can pass an array with all the necessary information, I will use a foreach and an insert to the db
GreyHead 11 Jul, 2013
Hi federcla,

Anything that is submitted from a ChronoForm is added to the $form->data array. You can use that to pass data between actions in the same event.

Bob
federcla 12 Jul, 2013
hi Bob,

i know that i can $form->data[] but don't work in my code

i have insert this code inside of a custom code in Actions->On Load


<?php
  
  echo '<div style="overflow:auto;"><table width=100%><thead bgcolor=c9daff height=30><th>Seleziona</th><th align="left">Codice</th><th align="left">Descrizione</th><th align="left">Mastrino</th><thead>';
  
  $db =& JFactory::getDBO();
 
  $query_1 = "SELECT * FROM sks_app_cons_temp";
  $db->setQuery($query_1);
  $caricoDatiTemp = $db->loadRowList();
  
  
  foreach ($caricoDatiTemp as $caricoDT) 
  { 
    echo '<tr><td height=22 align=center><input type="checkbox" name="prova[]" value="'.$caricoDT['1'].'" /></td>';
    echo '<td>'.$caricoDT['1'].'</td>';
    echo '<td>'.$caricoDT['2'].'</td></tr>';
  }  

 echo '</table></div><br>';
 
?>


and this code in a custom code in Actions->On Submit


<?php

  $prova = $form->data['prova'];
  
  foreach ($prova as $prov) 
  {
    foreach ($prov as $value) 
    {
      echo $value;	
    }   	
  }
?>


but the screen does not print anything

thanks for the help
GreyHead 12 Jul, 2013
Hi federcla,

It should work if there are values in $form->data['prova']

Use a Debugger action to see what is there.

Bob
federcla 12 Jul, 2013
i have inserted the debugger action in on submit, this is the result

Data Array:

Array
(
    [option] => com_chronoforms
    [chronoform] => Consuntivo_Inserimento_Codice
    [event] => submit
    [Itemid] => 169
    [view] => form
    [input_submit_1] => Submit
    [9ba14c908d977ac7fa26081fa605b6f2] => 1
)


Validation Errors:

Array
(
)
GreyHead 12 Jul, 2013
Hi federcla,

As you see there is nothing on 'prova' . . . now you have to work out why that is. Is the input inside the ChronoForms form tags when you view the page source?

Bob
federcla 12 Jul, 2013
sorry but I did not understand
GreyHead 12 Jul, 2013
Hi federcla,

There is no $form->data['prova'] . . . why not??

Bob
federcla 12 Jul, 2013
I don't know🙂

may be because the form that generates the list I call it from php code?

i have a form where I read a csv file, if the id_code is in a table i modify a value if isn't in the table i insert id_code in another table and i made the redirect a new form "Inserimento_Codice" with this code


header("location: ?option=com_chronoforms&chronoform=Inserimento_Codice"); 
die();


in the form "Inserimento_Codice" there is the code that made the page checkbox.png
GreyHead 12 Jul, 2013
Hi federcla,

Sorry, I'm lost. I have no idea what that is supposed to do :-(

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