• Resolved Nikodemsky

    (@nikodemsky)


    So i was wondering how i can achieve something like in here:
    goodmove.co.uk
    – you can type any text in “post code” field and click “go”, after that page goes to form, where “post code” is already filled with text typed on front page.

    I was thinking about using that with contact form 7, since it’s giving different ID’s for each field, but i don’t even know how to start.

    Would appreciate any help in that matter.

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

    (@bcworkz)

    To do that with CF7, you may need to insert the post code or whatever with jQuery or javascript because CF7 produces forms via shortcode. Even so, there may be a way with only PHP because CF7 does offer numerous hooks to alter it’s default operation. Using CF7 hooks would require digging into the internal workings of CF7. I’m not sure where to even start digging with CF7.

    Forgetting CF7 for a moment, passing post codes or other user data between pages is relatively simple. The landing page has a simple one field form. That form’s action attribute points to the next page. That next page’s PHP gets the user input sent by the first form with $_POST['postcode'] and uses it to set the value of the first field of a more comprehensive form.

    That same value can instead be passed to a javascript script where it is used to populate the form field after the page loads. The user value may instead be able to be placed directly into the field through a CF7 hook of some sort, but I wouldn’t know what that hook might be.

    Thread Starter Nikodemsky

    (@nikodemsky)

    I have found this in CF7 documentation:
    https://contactform7.com/getting-default-values-from-the-context/
    – but i have no idea how to modify it, so the button/input or anything will pass text typed in field.

    Moderator bcworkz

    (@bcworkz)

    Oh! Good find!
    First of all, the landing page’s form action attribute points to the page with the CF7 form. The method attribute can be either get or post as long as it matches the default: value for the corresponding CF7 field. The name attribute of the landing page’s input field must also match the name of the CF7 field. Something like this on the landing page:

    <form action="<?php site_url('/next-pages-slug/');?>" method="post" >
    <input name="postcode" type="text" placeholder="Enter your postcode here" value="">
    <input type="submit" value="Go!">
    </form>

    Then on the /next-pages-slug/ page you have the CF7 shortcode which loads a form that includes this tag:
    [text* postcode default:post]

    Thread Starter Nikodemsky

    (@nikodemsky)

    Works like a charm! Thank you very much.

    But since php execution is not allowed in page/posts content and it would require another plugin(or function) to run it i’ve changed:
    <form action="<?php site_url('/next-pages-slug/');?>" method="post" >
    to simply
    <form action="next-pages-slug/" method="post" >
    and it works too.

    Thanks again!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Get/Print text in form from input field’ is closed to new replies.