Buy Now
Sign in

Read the content from the database & limit record creation to 1 per User and Form

marcq , November 22 2014, 08:39
M
marcq 45
November 22 2014, 08:39 #339387
Hi,

First of all, you have a great component. I was able to create in less than an hour a form that saves its data in a database.

I just have two issues I was unable to solve myself (I’m not, really not a professional developer) : Read the content from the database & limit record creation to 1 per User and Form. If you could give me some advice in order to help me move forward, it would be great !

I have created two forms

1.  one to insert content,
2.  the other to read content.

In fact I wanted to create all in one : insert and read content in the same form, but I was unable to do it (if you have here a lead would be great!).

The forms contain only multiple checkboxes fields.

First form is working well, saving the content correctly in the database, populating all needed fields incl. the logged in user id (see DATABASESTRUCTURE.JPG).

The second one didn’t work well and doesn’t display the content resp. repopulate the checkboxes accordingly (I have only one record created).

Please find the form parameters in the CHRONOFORMS SETUP.PDF file and hereafter the debugging informations, thanks in advance, cheers, Marc :

Debugging

Data Array

Array
(
[BrandingUpdate
  • =>
    [id] => 32
    [uniq_id] =>
    [user_id] => 437
    [created] => 2014-11-21 19:15:52
    [modified] =>
    [type_brand] => 1,2
    [ecomarketing_functions] => 1,2
    )

    Array
    (
    )

    Errors

    Array
    (
    )

    Debug Info

    Array
    (
    [7] => Array
    (
    [DB Read] => Array
    (
    [Queries] => Array
    (
    [0] => SELECT `Data`.`id` AS `Data.id`, `Data`.`uniq_id` AS `Data.uniq_id`, `Data`.`user_id` AS `Data.user_id`, `Data`.`created` AS `Data.created`, `Data`.`modified` AS `Data.modified`, `Data`.`type_brand` AS `Data.type_brand`, `Data`.`ecomarketing_functions` AS `Data.ecomarketing_functions` FROM `mcl_chronoengine_chronoforms_datatable_branding` AS `Data` WHERE `Data`.`user_id` = '437'
    )

    )

    )

    )

    Form Code
    <input name="id" id="id" value="" type="hidden" class="form-control A" /><div class="form-group gcore-form-row" id="form-row-20"><label for="type_brand" class="control-label gcore-label-top gcore-label-checkbox">A quel type de marque appartient votre marque ?</label>
    <div class="gcore-input-wide gcore-display-table" id="fin-type_brand"><div class="gcore-single-column" id="fclmn19"><div class="gcore-checkbox-item" id="fitem2"><input name="type_brand
  • " id="type_brand1" class="validate[&#039;group:8&#039;
  • A" title="A quel type de marque appartient votre marque ?" style="" data-load-state="" data-tooltip="" type="checkbox" value="1" />
    <label class="control-label gcore-label-checkbox" for="type_brand1">Marque-caution (ou marque-entreprise ou marque-corporate)</label></div>
    <div class="gcore-checkbox-item" id="fitem4"><input name="type_brand
  • " id="type_brand3" class="validate[&#039;group:8&#039;
  • A" title="A quel type de marque appartient votre marque ?" style="" data-load-state="" data-tooltip="" type="checkbox" value="2" />
    <label class="control-label gcore-label-checkbox" for="type_brand3">Marque-ombrelle</label></div>
    <div class="gcore-checkbox-item" id="fitem6"><input name="type_brand
  • " id="type_brand5" class="validate[&#039;group:8&#039;
  • A" title="A quel type de marque appartient votre marque ?" style="" data-load-state="" data-tooltip="" type="checkbox" value="3" />
    <label class="control-label gcore-label-checkbox" for="type_brand5">Marque-topic (ou marque-produit)</label></div>
    <div class="gcore-checkbox-item" id="fitem8"><input name="type_brand
  • " id="type_brand7" class="validate[&#039;group:8&#039;
  • A" title="A quel type de marque appartient votre marque ?" style="" data-load-state="" data-tooltip="" type="checkbox" value="4" />
    <label class="control-label gcore-label-checkbox" for="type_brand7">Marque-enseigne</label></div>
    <div class="gcore-checkbox-item" id="fitem10"><input name="type_brand
  • " id="type_brand9" class="validate[&#039;group:8&#039;
  • A" title="A quel type de marque appartient votre marque ?" style="" data-load-state="" data-tooltip="" type="checkbox" value="5" />
    <label class="control-label gcore-label-checkbox" for="type_brand9">Marque de distributeur (MDD) ou marque propre</label></div>
    <div class="gcore-checkbox-item" id="fitem12"><input name="type_brand
  • " id="type_brand11" class="validate[&#039;group:8&#039;
  • A" title="A quel type de marque appartient votre marque ?" style="" data-load-state="" data-tooltip="" type="checkbox" value="6" />
    <label class="control-label gcore-label-checkbox" for="type_brand11">Marque de service</label></div>
    <div class="gcore-checkbox-item" id="fitem14"><input name="type_brand
  • " id="type_brand13" class="validate[&#039;group:8&#039;
  • A" title="A quel type de marque appartient votre marque ?" style="" data-load-state="" data-tooltip="" type="checkbox" value="7" />
    <label class="control-label gcore-label-checkbox" for="type_brand13">Griffe</label></div>
    <div class="gcore-checkbox-item" id="fitem16"><input name="type_brand
  • " id="type_brand15" class="validate[&#039;group:8&#039;
  • A" title="A quel type de marque appartient votre marque ?" style="" data-load-state="" data-tooltip="" type="checkbox" value="8" />
    <label class="control-label gcore-label-checkbox" for="type_brand15">Marque de luxe</label></div>
    <div class="gcore-checkbox-item" id="fitem18"><input name="type_brand
  • " id="type_brand17" class="validate[&#039;group:8&#039;
  • A" title="A quel type de marque appartient votre marque ?" style="" data-load-state="" data-tooltip="" type="checkbox" value="9" />
    <label class="control-label gcore-label-checkbox" for="type_brand17">Marque industrielle (B to B)</label></div></div></div></div><div class="form-group gcore-form-row" id="form-row-28"><label for="ecomarketing_functions" class="control-label gcore-label-top gcore-label-checkbox">Quelles sont les fonctions économique et marketing de ma marque ?</label>
    <div class="gcore-input-wide gcore-display-table" id="fin-ecomarketing_functions"><div class="gcore-single-column" id="fclmn27"><div class="gcore-checkbox-item" id="fitem22"><input name="ecomarketing_functions
  • " id="ecomarketing_functions21" class="A" title="Quelles sont les fonctions économique et marketing de ma marque ?" style="" data-load-state="" data-tooltip="" type="checkbox" value="1" />
    <label class="control-label gcore-label-checkbox" for="ecomarketing_functions21">Fonction transactionnelle</label></div>
    <div class="gcore-checkbox-item" id="fitem24"><input name="ecomarketing_functions
  • " id="ecomarketing_functions23" class="A" title="Quelles sont les fonctions économique et marketing de ma marque ?" style="" data-load-state="" data-tooltip="" type="checkbox" value="2" />
    <label class="control-label gcore-label-checkbox" for="ecomarketing_functions23">Fonction relationnelle et identitaire</label></div>
    <div class="gcore-checkbox-item" id="fitem26"><input name="ecomarketing_functions
  • " id="ecomarketing_functions25" class="A" title="Quelles sont les fonctions économique et marketing de ma marque ?" style="" data-load-state="" data-tooltip="" type="checkbox" value="3" />
    <label class="control-label gcore-label-checkbox" for="ecomarketing_functions25">Fonction aspirationnelle</label></div></div></div></div><div class="form-group gcore-form-row" id="form-row-29"><div class="gcore-input gcore-display-table" id="fin-button10"><input name="button10" id="button10" type="submit" value="Enregistrer" class="form-control A" style="" data-load-state="" /></div></div>
    Attachments
    DATABASESTRUCTURE.jpg
    DATABASESTRUCTURE.jpg
    (174.95 KiB)
    617 Downloads/Views
    CHRONOFORMS SETUP.pdf
    (207 KiB)
    443 Downloads/Views
    M
    marcq 45
    November 24 2014, 09:57 #339449
    Hi,
    No leads in order to help me to move forward ? :?
    BNDragon 498
    November 24 2014, 10:24 #339453
    Hi marcq,

    You want to read the last insert data from a user? Is that? If yes, I easily help you
    If not, please, explain me better, my english is not very good, so some times I can't understand well.

    BN
    Sorry for my english, any problem understanding me, let me know, I will try to explain myself better!
    BNDragon 498
    November 24 2014, 10:25 #339454
    P.s. The user is logged r8?

    BN
    Sorry for my english, any problem understanding me, let me know, I will try to explain myself better!
    M
    marcq 45
    November 24 2014, 11:10 #339459
    Hi BNDragon,

    Thanks for your PM, I'm working on a localserver, so I can't grant you access.

    You can find all about the form its parameters in the CHRONOFORMS SETUP.pdf which is allready attached to my original post.

    Thanks in advance for your wise support !

    Cheers,

    Marc
    BNDragon 498
    November 24 2014, 11:34 #339461
    Hi Marc,

    I didn't saw the pdf, I'll take a look soon

    BN
    Sorry for my english, any problem understanding me, let me know, I will try to explain myself better!
    BNDragon 498
    November 24 2014, 11:45 #339463
    Hi Marc,

    I never used a db reader action, but I can help you with a custom code to an Custom action.

    But in a fast search in the faqs, I think that your code is not right, try some like this:


    <?php
    $user = JFactory::getUser();
    return array("user_id" => $user->get("id"), "id" => $form->data("id"));
    ?>


    BN
    Sorry for my english, any problem understanding me, let me know, I will try to explain myself better!
    M
    marcq 45
    November 24 2014, 12:03 #339464
    Thanks BN,

    I put the code in the conditions field of DB Read, now when I load the BrandingUpdate form he is empty (checkboxgroups aren't shown anymore).
    BNDragon 498
    November 24 2014, 12:12 #339465
    Hi Marc,

    Hum, looking your confifigurations again, I think the problem is your hidden field. I believe that is your
    $form->data("id")
    right? So if the form is not load, there are no form to get the id.

    Try set your id in the query:
    <?php
    $user = JFactory::getUser();
    return array("user_id" => $user->get("id"), "id" => hiddenIdvalue);
    ?>


    BN
    Sorry for my english, any problem understanding me, let me know, I will try to explain myself better!
    M
    marcq 45
    November 24 2014, 12:15 #339466
    Dear BN,

    Could it be an implode/explode issue ? When the data are saved in the Branding form the checkbox arrays are imploded (handle array basic action in setip) in order to enable the saving of multiple values. Do I need also to put an handle array basic action in my BandingUpdate form in order to explod the array ?
    M
    marcq 45
    November 24 2014, 12:18 #339467
    Hi BN,

    Thanks ! I have put the code you have kindly sent to me in the conditions field of the DB read action. I still have no data displayed, sorry...
    BNDragon 498
    November 24 2014, 12:19 #339468
    Hi Marc,

    I think so, but the data is already loading?

    BN
    Sorry for my english, any problem understanding me, let me know, I will try to explain myself better!
    M
    marcq 45
    November 24 2014, 12:26 #339469
    Hi BN,

    No data is loading ? My form is embedded in an article, the page only show the few lines I have wroten just above the form itself.
    BNDragon 498
    November 24 2014, 13:06 #339470
    Hi Marc,

    Lets try a custom code,
    Put a Custom action (as first action on submit) and then a HTML.
    In the custom set this code:
        
    <?php 

        $user = JFactory::getUser();
        $formId = yourHiddenId;

        
      $con=mysqli_connect("localhost","root","","YOUR_DB_NAME");
      // Check connection
      if (mysqli_connect_errno())
      {
        echo "Error: " . mysqli_connect_error();
      }

      $FormData = mysqli_query($con,"SELECT * FROM #_mcl_chronoengine_chronoforms_datatable_branding WHERE user_id='".$user->get("id")."' AND id='".$formId."'");
      
      $line = mysqli_fetch_array($FormData);
      
      $type=$line['type_brand'];
      $pieces = explode(",", $type);
      $form->data["type_brand"] = $pieces;
      ?>
      

      
      Change yourHiddenId for your hidden id.
      Change YOUR_DB_NAME with you db name
      If mcl is your tables prefix user only "mcl_chronoengine_chronoforms_datatable_branding", in other case try as it is, or with youPrefixTable_mcl_chronoengine_chronoforms_datatable_branding
      
      I realy don't know if this code will work, please test and say me the result  $form->data["type_brand"] = $pieces;

      
    BN
    Sorry for my english, any problem understanding me, let me know, I will try to explain myself better!
    M
    marcq 45
    November 24 2014, 13:27 #339472
    Hi BN,

    Thanks a lot for your effort, it is vey kind from you ;-)

    I just create in my BrandingUpdate form Formid 4 a custom field where I put the (siehe below) following code according your instructions. Unfortunately it doesn't work :? Display is empty. Shouldn't we add the second checkboxgroup "ecomarketing_functions" in this piece of code ?


    <?php

    $user = JFactory::getUser();
    $formId = 4;


    $con=mysqli_connect("localhost","root","","marketingchecklists");
    // Check connection
    if (mysqli_connect_errno())
    {
    echo "Error: " . mysqli_connect_error();
    }

    $FormData = mysqli_query($con,"SELECT * FROM mcl_chronoengine_chronoforms_datatable_branding WHERE user_id='".$user->get("id")."' AND id='".$formId."'");

    $line = mysqli_fetch_array($FormData);

    $type=$line['type_brand'];
    $pieces = explode(",", $type);
    $form->data["type_brand"] = $pieces;
    ?>
    M
    marcq 45
    November 24 2014, 13:35 #339473
    BN,

    In 15 minutes I will grant you access to a website that a friend is developing. I'm on my way to replicate the forms and database, so I think it will be easier for you. I will send you per PM all the details username password ok ?
    BNDragon 498
    November 24 2014, 15:13 #339481
    Hi Marc,

    See the result in your site, to know is that what you need, and yes, you should add the second group, that is a test code, it is almost copy past to the ecomarketing_functions

     $type=$line['ecomarketing_functions'];
    $pieces = explode(",", $type);
    $form->data["ecomarketing_functions"] = $pieces;


    BN
    Sorry for my english, any problem understanding me, let me know, I will try to explain myself better!
    M
    marcq 45
    November 24 2014, 15:38 #339486
    Thanks BN, great job, it is nearly what I wanted. I just have the following code which appears after having created my new recod (I have emptied my database before) : user_id=".$user->get("id").
    BNDragon 498
    November 24 2014, 16:26 #339496
    Hi Marc,

    That was some tests I had done to fix the points you ask me by PM.

    If it is what you need, please post the relevant parts of our PM to help other users

    BN
    Sorry for my english, any problem understanding me, let me know, I will try to explain myself better!
    M
    marcq 45
    November 24 2014, 18:03 #339502
    Dear BN,

    Thank you very much fo your great support. It works exactely as I wanted to. Great job. I will create and post tomorrow morning a short tutorial which explain what you have done to solve those issues. Thanks again DN, cheers, Marc