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() {

    return ob_get_clean();


    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.


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

    Moderator 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.


    Sorry, that link didn’t help.

    • This reply was modified 6 months, 2 weeks ago by  Rachna.
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘problem with displaying forms dynamically in shortcode’ is closed to new replies.