• Resolved nathanhkn

    (@nathanhkn)


    I have a form that asks for the name of the profile you want to view then will redirect you to a profile page. That profile page is full of shortcode that looks like this “[get_sheet_value location=”Kayla!B2″]” Instead of “Kayla” I want it to be whatever the user put for the profile name.

Viewing 5 replies - 1 through 5 (of 5 total)
  • Moderator bcworkz

    (@bcworkz)

    The best way IMO would be to alter the passed attribute through the “shortcode_atts_{$shortcode}” filter. I’m assuming the shortcode handler uses the related function, which most do that accept passed attributes. {$shortcode} in this case would be “get_sheet_value” Your filter callback would get the form value from $_REQUEST or similar and alter the appropriate element in the passed array. You’d likely want to use logic where the data is only altered if a value is available in $_REQUEST, otherwise the value from the shortcode is retained.
    https://developer.www.ads-software.com/reference/hooks/shortcode_atts_shortcode/

    Thread Starter nathanhkn

    (@nathanhkn)

    Thanks! I don’t really know how to do that, but I had another idea. Is there a way that when the form is submitted the name is saved to a variable that is accessible by other plugins and on different pages. So instead of passing the name through the shortcode, the plugin just gets the variable for the name.

    Moderator bcworkz

    (@bcworkz)

    Accessible on different pages means the variable’s value would need to be saved in a persistent manner. Variable values normally only persist for the current request. The data can be saved somewhere in the DB and accessed by other pages as needed. Where to save depends on the nature of the data. A few possibilities of many are post or user meta, options, or temporary transients.

    You will need form handling code that saves the form data somewhere. There are several ways to do so. One way is to include such code on the template that outputs the form. The form would be set to POST submissions. If the template sees a GET request, it outputs the form. If it sees a POST request, it saves the data from $_POST to the DB.

    Thread Starter nathanhkn

    (@nathanhkn)

    Okay thanks! Simple question, how would I delete a row in my database, from my plugin? I know it’s $wpdb->delete(); but I don’t what to put for array $where

    Moderator bcworkz

    (@bcworkz)

    Without $where, how would the function know which row to delete?

    If doing so programmatically were not a requirement, you can manually delete stray, undesired rows through the phpMyAdmin app. Emphasis on “stray”. If the deleted row is tied to other data in the DB, it could cause WP to malfunction. It’s always wise to make backups before doing anything with phpMyAdmin unless you’re absolutely sure you know what you’re doing is completely safe.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Passing inputted form data to shortcode’ is closed to new replies.