• Hi I’m new in the WordPress world.

    I’d like to have a link in some of my posts/pages which opens a window with a form to receive some info like updates about specific content, some links, complaints about what is written in the post/page, suggestions how to improve the post/page and so on.

    I would like to collect, among the basic info such as email, message, name, the title of the post/page which is linked to the form.
    I also like the idea to present a different text for each form.

    Do I have to create a single page for each form using form plugin such as Ninja Form or is there any other way to make a single page working for each post?

    Is there any way to create a unique place to read the content of the form submitted by the users?

    Thank you very much

Viewing 2 replies - 1 through 2 (of 2 total)
  • Hmmm…you could potentially do something like this….

    1. Create a standard form page and use a custom page template for it. In this case, we’ll call it “contact_form.php”.

    2. If you’re using something like Contact Form 7 to create your forms, it will give you a shortcode to use wherever you want that particular form to display. I’m assuming Ninja Form does something similar. Regardless, create whatever forms you want and take note of the short codes.

    3. On your individual posts where you’ll link to the contact form page, create a button that says “Contact Form” or something like that. In the HTML, make the button an actual form submission using either GET or POST as the method. Since this isn’t a super-secure thing, you should be fine with GET. Either would be fine, though. The form could include a hidden field to send the post title of the post the user is currently looking at. When the user clicks the “Contact Form” button, they’ll go to the “contact_form.php” page, but the form will send along the name of the post they’ve come from.

    4. Now go back to your “contact_form.php” template code and add some php to the start of the page. Have it retrieve the page title of the previous page from the GET/POST variable. Then in the body of the template, run a conditional statement to display a certain form depending on what the previous page was.

    That may sound complicated but I wanted to explain it rather than do all the coding for you. This should give you a good starting point, though. You don’t even have to use the post title as the deciding variable if you don’t want to. Perhaps you’ll have a form for a certain category of posts….then you can just include the category as the hidden field in the GET/POST form submission.

    There are certainly other ways to do it but that should get you started.

    Depending upon your familiarity with PHP, the programmatic method presented above would certainly work. I was going to recommend using a custom page template to either modify the form on the fly or select a particular form. You can do either with Ninja Forms quite easily if you don’t mind doing some custom coding.

    I would slightly modify the method so that in your custom_template file instead of creating a submit button, you create a link to the form with a querystring attached to it that would represent the Post ID of the particular post or page. Something like: “https://www.mysite.com/form-page/?referrer=3” where the 3 is the ID of the post your link is on. You can do this quite easily using get_permalink( POST ID). And the Post ID can be appended to the url that is returned using add_query_arg(). Then, in Ninja Forms, you can select a form or show/hide/modify the form output based upon that Post ID.

    In your template file, as was mentioned above, you can look at the Post ID you get and decide which form should be displayed. If you are using Ninja Forms, you can use the template function ninja_forms_display_form( FORM_ID ); to pull in the form you want depending upon what the previous page was. This will save you the hassle of having to use shortcodes and modifying the form ID attribute in the shortcode.

    Of course, if you aren’t very comfortable using PHP, that can all sound like a rather daunting task. If you need this to be up quickly, I might recommend implementing the non-programmatic way and then modifying it once there isn’t a time constraint.

    If you need more direction than that, just let me know and I’ll see if I can help.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Form for different posts’ is closed to new replies.