• Hello everyone ??

    I would like to create a plugin with a widget where people will complete a form.

    Form example:
    – Name
    – Age:
    – What do you like: movies, books, cars

    and when they press submit, it will show the results on the specific plugin page (so I have to create that page too…) but it will fulfill a sentence already made.
    For example on that plugin page, the basic sentence is:
    Hi, my name is [Name], I am [Age] y/o, and I like [].

    So when the user submit his form, the sentence will be completed with what he choose.
    But I don’t want the page to be permanently changed, I just want it to change dynamicly, like a search results.

    I don’t know really much about php and widgets, so that is why I am asking for help. I am not asking to do it for me, just give me advices or show me an example somewhere; I don’t know, because I am a bit lost for the moment ^^
    Thank you very much ??

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

    (@bcworkz)

    If your plugin has a custom page, you don’t really need a widget. You can if you like, but it makes for more coding work. The main purpose of a widget is so an admin can optionally place it in one of the areas designated for widgets by the theme, typically “sidebars”. A possibility is also introduced for the admin to specify certain settings for the widget when it is placed in the sidebar or where ever.

    I would suggest you first focus on your plugin page. You could always wigetize it later if you still think there is a need. You will essentially be creating a custom page template. Page templates normally go in the theme folder, which is sort of off limits for plugins. Templates can reside elsewhere though, such as in plugin folders. Doing so only means authors cannot select the template for creating their own pages.

    Your plugin can insert the page on activation with wp_insert_post() (even though you are inserting a page). Initially, insert the page using the default template. Once inserted, alter the template path in the postmeta table, keyed ‘_wp_page_template’. This is mainly so you have an URL with which to access the page. Unlike external pages, page templates have access to all WP resources.

    The page template can present different content depending on if the request is a GET or POST. If GET, present the form. If POST, present the sentence with the fields filled in.

    Thread Starter Doremdou

    (@doremdou)

    thank you for your help bcworkz ??
    I found something which seems to work^^

    have a good day! ^^

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Widget Form with results in a new page (plugin specific page)’ is closed to new replies.