• Hi there,

    is there a way to connect the input of an input field with a page / URL?

    Purpose: Visitors of the web page enter the abbreviation of a region (e.g. license plate codes like “b” for berlin, “m” for munich, “gl” for the region east of cologne). The list of these regional codes is approx. 800 elements long and will be filled manually. Each code also represents one of 800 WordPress pages with unique content (cannot be generated automatically). The url can be identical to the input data. So after writing “m” and klicking on the enter / submit button they get directly to the “Munich” WordPress page mydomain.com/m.

    Is there a plugin that enables the linking of input field data with pages / URLs?
    Or is there a html / php solution (I can code html, but I only have superficial knowledgte of php)?

    Thank you very much for your help!

    • This topic was modified 8 years, 10 months ago by jgastmann.

    The page I need help with: [log in to see the link]

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

    (@bcworkz)

    There’s not any plugin I’m aware of, but I’m not that knowledgeable of what’s available. You can probably utilize search as well as I can 🙂

    There’s a fairly simple PHP solution, but you may find the supporting code needed to implement the solution overwhelming. The core concept is creating your manual list as a PHP lookup array. Structured maybe like this:

    $lookup = array(
      'b' => 'berlin-page-slug',
      'm' => 'munich-page-slug',
      'gl'=> 'east-cologne-region',
      // etc....
    );

    The input is matched against the related array element and then the user is redirected to the appropriate page. If no match is found, redirect back to the input form with an error message.

    I realize your plan was to simply redirect to a page matching the input, so the Munich page slug is simply ‘m’. I would advise against this, you will see far better search rankings by spelling out the areas. The page slug being meaningful to humans makes for a better user experience all around. Since you would need to validate input anyway, which requires some sort of array of valid input, you may as well translate that into a more meaningful slug.

    The resulting page slug is added to your site’s URL to make a complete permalink, which is passed to wp_redirect(). This function must be called before any page output occurs. Where this code occurs depends on how your form submit works.

    If you have difficulty with the coding to support this lookup and redirect scheme, you could hire help from a resource like https://jobs.wordpress.net/ or https://jetpack.pro/ . If you provide the lookup array, the remainder of the coding isn’t too involved for an experienced coder.

    Thread Starter jgastmann

    (@jgastmann)

    Thank you very much! An array would be to hard to fill and to maintain. So a database solution will probably the fitting solution. Thanks, too, for the hint to engage someone at jobs.wordpress.net. I think I’ll do that.

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘connect input field data with URL/page’ is closed to new replies.