Contact form 7 set the value of the request field

I want to set the value of the request field

example.com/subscribe/?email=asfafs

but when I load a page that has a form, the form does not appear. I understand why he could not show. Because the form itself can also send a request for receipt. I also installed this plugin, which should allow me to set the field value, but it is not.

this is what i have:

<p>Uw naam (verplicht)<br /> [text* input-name] </p> <p>Uw email (verplicht)<br /> [dynamictext dynamicname "CF7_GET key='email'"] </p> <p>Onderwerp<br /> [text your-subject] </p> <p>Uw bericht<br /> [textarea your-message] </p> <p>[submit "Verzenden"]</p> 

On my page:

 <?php echo do_shortcode('[contact-form-7 id="1062" title="Contactformulier 1"]'); ?> 

I would not mind using a different plugin for this. If there is one that fits my needs, please tell me.

+7
source share
5 answers

I just installed the connected plugin and tested it. The plugin is not intended to transfer the GET variable for the field in the contact form 7. The plugin will do two things

  • It will capture the $ _GET variable and create a hidden field with it.
  • It will display the variable on the page (as text, not in a field)

The barcode that you have in your example is for use by this http://wordpress.org/plugins/contact-form-7-dynamic-text-extension/ . I downloaded and tested this plugin and it seems to work fine.

Here is the page on which I created this example. http://jtwebb.com/stackoverflow-question/?someemail=asdf if you want to see how it works with the dynamic text extension plugin.

UPDATE This is my contact code 7:

 <p>Your Name (required)<br /> [text* your-name] </p> <p>[showparam someemail] <-- this is the shortcode of show param, just text no field</p> <p>[getparam someemail] If you inspect this you'll see a hidden get field with the value of 'someemail' in it.</p> <p>Your Email (required)<br /> [dynamictext* dynamictext-380 "CF7_GET key='someemail'"]<br>This field was created with <a href="http://wordpress.org/plugins/contact-form-7-dynamic-text-extension/">http://wordpress.org/plugins/contact-form-7-dynamic-text-extension/</a></p> <p>Subject<br /> [text your-subject] </p> <p>Your Message<br /> [textarea your-message] </p> <p>[submit "Send"]</p> 
+7
source

[text* your-name default:get] field will get its default value from the GET variable with the same name ("your-name"). Try this by going to the URL form page using an additional query string:

http://example.com/contact/?your-name=John+Smith

But what if you have two or more default options in the same form tag? Let's look at this case with form tags:

[text* your-name default:get default:post_meta "Your Name"]

+9
source

I know that this question has already been answered, but for those who are looking for a solution that does not require a plugin, I decided to do the following.

First I created my form from the plugin through the Wordpress toolbar. I added a field in which I wanted to save the parameter from the URL, and assigned it an identifier.

[text page-name class:form-control id:source minlength:2 maxlength:80]

Next, I added a link that would pass such a parameter to the form

<a href='http://mycoolwebsite.com/contact?id=homepage'>Contact Us</a>

Then, using some Javascript and JQuery , I get the id parameter from the URL and set it as the value for my input on the form. (The getParameterByName(name,url) function was taken from this answer: How to get query string values ​​in JavaScript? )

 function getParameterByName(name, url) { if (!url) url = window.location.href; url = url.toLowerCase(); name = name.replace(/[\[\]]/g, "\\$&"); var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"), results = regex.exec(url); if (!results) return null; if (!results[2]) return ''; return decodeURIComponent(results[2].replace(/\+/g, " ")); } var param = getParameterByName('id'); jQuery('#source').hide(); jQuery('#source').prop('disabled', true); jQuery('#source').attr('value', param); jQuery('#source').val(param); 

I also hide and disable the input field so that it is not visible and cannot be changed (easily). I also hide the input box using CSS

#source{visibility:hidden}

Thus, I can link to the form from anywhere on my site and add the source of where the person came from and put it in the received letter.

I do not see any problems with this method, and this eliminates the need to use a plugin. I am sure that this is not ideal to depend on Javascript, but equally it is not ideal for use with many plugins on your site, as they can quickly become outdated and can often cause conflicts among themselves.

Hope this helps anyone looking for an alternative. I would like to know the opinions of people along the way, as I am open to suggestions on how to improve it.

+4
source

You can initially set a unique text in the form field, and then use the hook to replace it with the desired value. And then no plug-in is needed.

Example. According to the form code:

 <p>Phone<br /> [text phone "PHONE_VALUE"] </p> 

in functions.php:

 add_filter( 'wpcf7_form_elements', function( $form ) { $form = str_replace( 'PHONE_VALUE', $_GET['phone'], $form ); return $form; } ); 

in url:

 example.com/page?phone=111111 
0
source

according to this article

if you want to send the value to the selection list, this can easily be done by adding the default:get parameter to the field code:

 [select* the-recipient default:get "Employee One| employeeone@yourdomain.com " "Employee Two| employeetwo@yourdomain.com " "Employee Three| employeethree@yourdomain.com "] 

and then send the parameter in the GET request, for example:

 http://yourdomain.com/contact/?the-recipient=Employee%20Two 
0
source

Source: https://habr.com/ru/post/970392/


All Articles