Buy Now
Sign in

Save date from dropdown to database

bertvdb , September 08 2014, 13:39
B
bertvdb 7
September 08 2014, 13:39 #335802
I have the following code

<h2>Aanwezigheidslijst</h2><br>
Ploeg: <input type="text" name="ploeg" value="JU13" disabled><br><br>
<?php
$options = array();
$training
  • = "<option value=''>--Training?--</option>";
    $db =& JFactory::getDBO();
    $query = "
    SELECT `idt`, `ploegid`, `training`
    FROM `#__training`
    WHERE `ploegid`=24
    ORDER BY `idt`;
    ";
    $db->setQuery($query);
    $data = $db->loadObjectList();
    foreach ( $data as $d ) {
    $training
  • = "<option value='{$d->idt}'>{$d->training}</option>";
    }
    ?>
    <select class="" id="training" size="1" name="training">
    <?php echo implode("\n", $training); ?>
    </select>
    <br>
    <?php
    $options = array();
    $naam
  • = "<option value=''>--Welke speler?--</option>";
    $db =& JFactory::getDBO();
    $query = "
    SELECT `spelerid`, `ploegid`, `ploegid2`,`voornaam`, `achternaam`
    FROM `#__spelers`
    WHERE `ploegid`=24 OR `ploegid2`=24
    ORDER BY `achternaam`;
    ";
    $db->setQuery($query);
    $data = $db->loadObjectList();
    foreach ( $data as $d ) {
    $naam
  • = "<option value='{$d->spelerid}'>{$d->voornaam}&nbsp;{$d->achternaam}</option>";
    }
    ?>
    <select class="" id="naam" size="1" name="naam">
    <?php echo implode("\n", $naam); ?>
    </select>
    <br>
    <?php
    $options = array();
    $options
  • = "<option value=''>--Aanwezig?--</option>";
    $db =& JFactory::getDBO();
    $query = "
    SELECT `id`, `opties`
    FROM `#__trainingsopties`
    ORDER BY `opties`;
    ";
    $db->setQuery($query);
    $data = $db->loadObjectList();
    foreach ( $data as $d ) {
    $options
  • = "<option value='{$d->id}'>{$d->opties}</option>";
    }
    ?>
    <select class="" id="opties" size="1" name="opties">
    <?php echo implode("\n", $options); ?>
    </select>

    <input type="hidden" name="sendto" id="sendto"
    value="<?php echo $databaseContact; ?>">
    <br>
    <div class="form-group gcore-form-row" id="form-row-2"><div class="gcore-input gcore-display-table" id="fin-fld1">
    </div>
    <div class="form-group gcore-form-row" id="form-row-22"><div class="gcore-input gcore-display-table" id="fin-button9"><input name="button9" id="button9" type="submit" value="Opslaan" class="form-control A" style="" data-load-state="" /></div></div>


    I need to save the following to the database

    Ploeg -> value needs to be JU13
    Training -> choose date from dropdown
    Welke speler -> choose player from dropdown
    Aanwezig -> choose option from dropdown

    A preview of this form is on -> http://bravoc.be/index.php?option=com_chronoforms5&chronoform=Aanwezigheid

    I made a table in the database with following name lx59p_chronoengine_chronoforms_datatable_Aanwezigheid
    and following fields
      id  uniq_id  user_id  created  modified  ploeg  training  naam  opties

    What do I need to do to make the save work?
    admin 29
    September 12 2014, 03:08 #336023
    Hi bert,

    If your select names matches the table fields names then it should work, assuming you have a "db save" connected to the table.

    Let us know if the problem persists!

    Regards,
    Max
    Max
    If your main question got answered then please mark the answer using the button!
    Did you try the new ChronoForms7 ? if yes then please send us your comments!!
    B
    bertvdb 7
    September 12 2014, 08:47 #336037
    Problim still exist.

    This is my code
    <h2>Aanwezigheidslijst</h2>
    <?php
    $options = array();
    $ploeg
  • = "<option value=''>--Ploeg?--</option>";
    $db =& JFactory::getDBO();
    $query = "
    SELECT `ploegid`, `ploegnaam`
    FROM `#__ploegen`
    WHERE `ploegid`=24
    ORDER BY `ploegnaam`;
    ";
    $db->setQuery($query);
    $data = $db->loadObjectList();
    foreach ( $data as $d ) {
    $ploeg
  • = "<option value='{$d->ploegid}'>{$d->ploegnaam}</option>";
    }
    ?><br>
    <select class="" id="ploeg" size="1" name="ploeg">
    <?php echo implode("\n", $ploeg); ?>
    </select>
    <br>
    <?php
    $options = array();
    $training
  • = "<option value=''>--Training?--</option>";
    $db =& JFactory::getDBO();
    $query = "
    SELECT `idt`, `ploegid`, `training`
    FROM `#__training`
    WHERE `ploegid`=24
    ORDER BY `idt`;
    ";
    $db->setQuery($query);
    $data = $db->loadObjectList();
    foreach ( $data as $d ) {
    $training
  • = "<option value='{$d->idt}'>{$d->training}</option>";
    }
    ?>
    <select class="" id="training" size="1" name="training">
    <?php echo implode("\n", $training); ?>
    </select>
    <br>
    <?php
    $options = array();
    $naam
  • = "<option value=''>--Welke speler?--</option>";
    $db =& JFactory::getDBO();
    $query = "
    SELECT `spelerid`, `ploegid`, `ploegid2`,`voornaam`, `achternaam`
    FROM `#__spelers`
    WHERE `ploegid`=24 OR `ploegid2`=24
    ORDER BY `achternaam`;
    ";
    $db->setQuery($query);
    $data = $db->loadObjectList();
    foreach ( $data as $d ) {
    $naam
  • = "<option value='{$d->spelerid}'>{$d->voornaam}&nbsp;{$d->achternaam}</option>";
    }
    ?>
    <select class="" id="naam" size="1" name="naam">
    <?php echo implode("\n", $naam); ?>
    </select>
    <br>
    <?php
    $options = array();
    $options
  • = "<option value=''>--Aanwezig?--</option>";
    $db =& JFactory::getDBO();
    $query = "
    SELECT `id`, `opties`
    FROM `#__trainingsopties`
    ORDER BY `opties`;
    ";
    $db->setQuery($query);
    $data = $db->loadObjectList();
    foreach ( $data as $d ) {
    $options
  • = "<option value='{$d->id}'>{$d->opties}</option>";
    }
    ?>
    <select class="" id="opties" size="1" name="opties">
    <?php echo implode("\n", $options); ?>
    </select>

    <input type="hidden" name="sendto" id="sendto"
    value="<?php echo $databaseContact; ?>">
    <br>
    <div class="form-group gcore-form-row" id="form-row-2"><div class="gcore-input gcore-display-table" id="fin-fld1">
    </div>
    <div class="form-group gcore-form-row" id="form-row-22"><div class="gcore-input gcore-display-table" id="fin-button9"><input name="button9" id="button9" type="submit" value="Opslaan" class="form-control A" style="" data-load-state="" /></div></div>



    This is my database table
    Field  Type  Collation  Attributes  Null  Default  Extra  Action
      id  int(11)      No  None  AUTO_INCREMENT   Browse distinct values   Change   Drop   Primary   Unique   Index  Fulltext
      uniq_id  varchar(50)  utf8_general_ci    No  None     Browse distinct values   Change   Drop   Primary   Unique   Index   Fulltext
      user_id  int(11)      No  None     Browse distinct values   Change   Drop   Primary   Unique   Index  Fulltext
      created  datetime      No  0000-00-00 00:00:00     Browse distinct values   Change   Drop   Primary   Unique   Index  Fulltext
      modified  datetime      Yes  NULL     Browse distinct values   Change   Drop   Primary   Unique   Index  Fulltext
      ploeg  varchar(255)  utf8_general_ci    No  None     Browse distinct values   Change   Drop   Primary   Unique   Index   Fulltext
      training  varchar(255)  utf8_general_ci    No  None     Browse distinct values   Change   Drop   Primary   Unique   Index   Fulltext
      naam  varchar(255)  utf8_general_ci    No  None     Browse distinct values   Change   Drop   Primary   Unique   Index   Fulltext
      opties  varchar(255)  utf8_general_ci    No  None     Browse distinct values   Change   Drop   Primary   Unique   Index   Fulltext


    If I fill the form on -> http://bravoc.be/index.php?option=com_chronoforms5&chronoform=Aanwezigheid in then it gives no error but if I check the table than there are no records in the table :-(
    GreyHead 64
    September 12 2014, 09:34 #336038
    Hi bertvdb,

    I don't' see anything wrong in your code.

    Please drag a Debugger action into the On Submit event, then submit the form and post the debug results here.

    Note: if you are using the Easy Wizard you can turn on Debug on the Others tab in CFv4 or the Setup tab in CFv5.

    Bob
    ChronoForms technical support
    If you'd like to buy me a coffee or two, thank you very much
    B
    bertvdb 7
    September 12 2014, 10:08 #336044
    Data Array
    Array
    (
    [option] => com_chronoforms5
    [chronoform] => Aanwezigheid
    [event] => submit
    [ploeg] => 24
    [training] => 1
    [naam] => 140
    [opties] => 1
    [sendto] =>
    [button9] => Opslaan
    [id] => 0
    )
    Array
    (
    )
    Errors
    Array
    (
    )
    Debug Info
    Array
    (
    [11] => Array
    (
    [DB Save] => Array
    (
    [Queries] => Array
    (
    )

    )

    )

    )
    GreyHead 64
    September 12 2014, 15:18 #336079
    Hi bertvdb,

    The problem may be that id=0 at the end of the data array. Do you know where that is coming from?

    My guess is that the DB Save is failing because of that. Otherwise it may just not be linked to the table.

    Bob
    ChronoForms technical support
    If you'd like to buy me a coffee or two, thank you very much
    B
    bertvdb 7
    September 12 2014, 16:23 #336086
    Don't know but when i change the DB save settings to
    Enabled -> Yes
    Table name -> lx59p_chronoengine_chronoforms_datatable_Aanwezigheid
    Save under Model iD -> Yes
    Multi save -> No
    Model ID -> Data then I get this code
    Data Array
    Array
    (
    [option] => com_chronoforms5
    [chronoform] => Aanwezigheid
    [event] => submit
    [ploeg] => 24
    [training] => 1
    [naam] => 140
    [opties] => 1
    [sendto] =>
    [button9] => Opslaan
    [Data] => 2
    )
    Array
    (
    )
    Errors
    Array
    (
    )
    Debug Info
    Array
    (
    [11] => Array
    (
    [DB Save] => Array
    (
    [Queries] => Array
    (
    [0] => INSERT INTO `lx59p_chronoengine_chronoforms_datatable_Aanwezigheid` (`user_id`, `created`) values ('0', '2014-09-12 16:20:57');
    )

    )

    )

    )

    And I get this in my table

    Volledige teksten  id  uniq_id  user_id  created   modified  ploeg  training  naam  opties
         2      0  2014-09-12 16:20:57  NULL  
    But no values in ploeg - training - naam and opties         
    admin 29
    September 12 2014, 21:07 #336094
     Answer
    Ok, as Bob suggested, its the id, please set "save under model id" to "no", and use this code in a "custom code" action ABOVE the "db save":

    <?php
    unset($form->data["id"]);
    Max
    If your main question got answered then please mark the answer using the button!
    Did you try the new ChronoForms7 ? if yes then please send us your comments!!
    B
    bertvdb 7
    September 13 2014, 09:50 #336106
    Tnx, that worked!