Support » Developing with WordPress » problem with displaying forms dynamically in shortcode

  • Hi

    I am creating a plugin that uses shortcode to load forms. It has two forms: 1)input form 2)output form
    To add shortcode to my plugin, I use following code:

    function myplugin_maker_makeshortcode() {

    ob_start();
    myplugin_maker_apply();
    html_form_code($result);
    return ob_get_clean();

    }
    add_shortcode(‘myplugin_maker_form’,’myplugin_maker_makeshortcode’);

    ——–
    Input form variables are sent to myplugin_maker_apply() function to check and generate proper output.The html_form_code() is the function that shows forms based on $result. If $result is empty, it shows input form else shows output form, But output values are set in myplugin_maker_apply function. So I try to call html_form_code() in the myplugin_maker_apply function, but as output I receive both input and output forms. How can I solve this problem to show just one of the forms based on $result value.

    Thanks

Viewing 3 replies - 1 through 3 (of 3 total)
  • Hi,
    I recommend asking at https://developer.wordpress.org/plugins so the plugin’s developers and support community can help you with this.
    Thanks.

    Moderator bcworkz

    (@bcworkz)

    $result is out of scope or not defined in your shortcode handler. There are at least a couple ways to determine if a form has been submitted in order to decide whether to display the results or the initial form. One way is to have your form use POST method. Then check the request type in $_SERVER[‘REQUEST_METHOD’]. If it’s “POST”, handle the form submit, else show the form (because the request was probably “GET”). Or you can just check for a required form field in $_GET or $_POST (depending on the method used by your form).

    @rachna90 – thank you for trying to help, however the link you posted does not have any support available like you imply. I imagine you simply had the wrong link in your clipboard. Happens all the time, no worries, just FYI. In any case, the OP has their own plugin, so there is no dedicated forum to send them to.

    Hello,

    Sorry, that link didn’t help.

    • This reply was modified 2 months, 1 week ago by  Rachna.
Viewing 3 replies - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.