WordPress.org

Ready to get started?Download WordPress

Forums

Contact Form DB
[resolved] table shortcode (10 posts)

  1. Panos
    Member
    Posted 1 year ago #

    Is it possible to create a shortcode to display a table but the header text of each column will be a name that I will chose? Up until now I used "cfdb-table" shortcode but I couldn't manage to change the header text. I also tried cfdb-datatable which is better (different colors on each row) but I couldn't change it also.
    I would appreciate if you could help me.
    My site: http://paiones.gr and the table I want to be displayed correct is on http://paiones.gr/?page_id=31

    http://wordpress.org/extend/plugins/contact-form-7-to-database-extension/

  2. Michael Simpson
    Member
    Plugin Author

    Posted 1 year ago #

    This is not an elegant way, but you can do it using cfdb-html:

    - Put you own TABLE, THEAD, TR, TH tags in your post, followed by TBODY
    - followed by a cfdb-html short code that output TR, TD element for each row
    - After the short code, put in closign /TBODY /TABLE tags

    You choose the names you want in our TH tags

  3. Panos
    Member
    Posted 1 year ago #

    First of all thank you for the advise. I tried this but the Header Text is displayed in every row.
    Here is my code. (Short)

    <table border="1">
    <thead>
    <tr>
    <th>Name</th>
    <th>Surname</th>
    </tr>
    </thead>
    <tbody>
    <tr>
    <td>${text-708}</td>
    <td>${your-name}</td>
    </tr>
    
    </tbody>
    </table>

    Probably it is my mistake but I can not figure it out.

  4. Michael Simpson
    Member
    Plugin Author

    Posted 1 year ago #

    Put that stuff outside the shortcode

    <table border="1">
    <thead>
    <tr>
    <th>Name</th>
    <th>Surname</th>
    </tr>
    </thead>
    <tbody>
    [cfdb-html form="your-form"]
    <tr>
    <td>${text-708}</td>
    <td>${your-name}</td>
    </tr>
    [/cfdb-html]
    </tbody>
    </table>
  5. Panos
    Member
    Posted 1 year ago #

    Thank you for the solution. It worked great.

  6. Panos
    Member
    Posted 1 year ago #

    Would it be possible to calculate the summary of a specific collumn? I have for example a collumn that displays a choise from a dropdown menu. I know it is a text but the first character is arithmetic.

  7. Michael Simpson
    Member
    Plugin Author

    Posted 1 year ago #

    If you want to compute a sum, then you need to do this as a create your own short code instead of using cfdb-html. Here is some code to get you started. Change 'some-column' to match your column name.

    require_once(ABSPATH . 'wp-content/plugins/contact-form-7-to-database-extension/CFDBFormIterator.php');
    $exp = new CFDBFormIterator();
    $exp->export($atts['form'], $atts);
    echo '<table border="1">
    <thead>
    <tr>
    <th>Name</th>
    <th>Surname</th>
    </tr>
    </thead>
    <tbody>';
    
    $summary = 0;
    while ($row = $exp->nextRow()) {
        echo '<tr>';
        echo '<td>'. $row['text-708'] . '</td>';
        echo '<td>'. $row['your-name'] . '</td>';
        echo '</tr>';
        // first character of string is number
        $summary = $summary + substr($row['some-column'], 0, 1);
    }
    
    echo '</tbody></table>';
    echo "$summary";
  8. Panos
    Member
    Posted 1 year ago #

    Thanks a lot. It was very helpful. Finally I managed to have a sum of the columns.
    However I want to improve it by add the summary of the column in the last entry of the specific row.
    Is this possible?

  9. Panos
    Member
    Posted 1 year ago #

    Hello. Is it possible to create for example 3 different tables instead of one that are assigned each to a choice of a radio button? Lets say place of delivery.
    I tried to put it after while a constraint but didn't worked.
    Any ideas

  10. Michael Simpson
    Member
    Plugin Author

    Posted 1 year ago #

    I suppose so. The template code for "create your own short code" basically shows you how to get and loop through the data. You can write your own PHP code there to create different tables or anything you want based on the data you see. It's up to you to write the code.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags

No tags yet.