• Resolved 0cg0

    (@0cg0)


    Good morning and happy new year Tobias.
    I would like to ask if it is possible to pass the row number to a variable.
    I have a table in which in the first column there is a link that refers to another page.
    In each cell there is a string like this:
    cell A2: <a href="https://test.com?xyz=2"> READ </a>
    cell A3: <a href="https://test.com?xyz=3"> READ </a>
    cell A4: <a href="https://test.com?xyz=4"> READ </a>

    Is it possible to replace the line number with a variable that automatically fetches the row number? A thing like that?
    cell A2: <a href="https://test.com?xyz=<?php echo $var; ?>"> READ </a>
    cell A3: <a href="https://test.com?xyz=<?php echo $var; ?>"> READ </a>
    cell A4: <a href="https://test.com?xyz=<?php echo $var; ?>"> READ </a>

    Thanks in advance for the reply?

    • This topic was modified 2 years, 3 months ago by 0cg0.
    • This topic was modified 2 years, 3 months ago by 0cg0.
Viewing 8 replies - 1 through 8 (of 8 total)
  • Hi There,

    It is possible but you have to add a custom script in the footer that detects the row number and append the into the link.
    I would like to try this but you have to share the your table page url so we can check the dom content of your table.

    Thanks And Regards
    Koustab

    Thread Starter 0cg0

    (@0cg0)

    Thanks Koustab.
    The site is under construction and I cannot make the pages publish!
    If you tell me what to look for, can I try to give you the value you need?
    Let me know.

    You have to change into the Plugin code. It is possible to add your table to some stagging websites. I need only the table front end dom elements to configure the js

    Plugin Author TobiasBg

    (@tobiasbg)

    Hi,

    thanks for your post, and sorry for the trouble.

    Yes, this is possible if you use the Formula feature in TablePress, see https://tablepress.org/tablepress-features-formulas/
    In your case, you would use the ROW variable, and the formula into text integration feature. Thus, please try this as the cell content of these cells:

    
    =<a href="https://test.com?xyz={ROW}"> READ </a>

    Using a JavaScript-based solution, as astra001 suggests, would also work, but is not really necessary, I think.

    Regards,
    Tobias

    Thread Starter 0cg0

    (@0cg0)

    Hi,

    thanks it works fine.

    I would like to ask you something else.
    In the formula I populate the link dynamically with $_GET and for safety I thought it better to sanitize it.
    My full formula is:

    =<a href="https://test.com/<?php echo htmlspecialchars($_GET['abc'], ENT_QUOTES); ?>?xyz={ROW}">READ</a>

    In your opinion is this sanitation sufficient?

    Does Tablepress perform a general sanitization on the strings present in the tables? And if so, can I delete my htmlspecialchars sanitization?

    Thanks for the reply.
    Regards

    Plugin Author TobiasBg

    (@tobiasbg)

    Hi,

    I’m not an expert here, but I would recommend to make the validation as strict as possible, and prevent everything that is not valid in your URL parameters. As for the sanitization, something like

    =<a href="<?php echo esc_url( 'https://test.com/' . $_GET['abc'] . '?xyz={ROW}', ENT_QUOTES); ?>">READ</a>
    

    is probably safer.

    TablePress does not perform any validation here, so you must add your own!

    Regards,
    Tobias

    Thread Starter 0cg0

    (@0cg0)

    Hi,

    thanks again, I replaced the string and it works perfectly.

    Thanks for the reply.
    Regards

    Plugin Author TobiasBg

    (@tobiasbg)

    Hi,

    no problem, you are very welcome! 🙂 Good to hear that this helped!

    Best wishes,
    Tobias
     
    P.S.: In case you haven’t, please rate TablePress here in the plugin directory. Thanks!

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Row number’ is closed to new replies.