Avatar of Roberto Parker
Roberto Parker
Flag for Mexico asked on

Pass data contact form 7. [_url] not passed

I have a contact 7 form I need to pass variables to my plugin. All variables are passed ok except $url = $formData['_url'];.The form sends the email and shows the [_url] variable. This is the code that should pass the [_url] variable. Any ideas?
fnction contactform7_before_send_mail( $contact_form ) {
  $C_data->skip_mail = true;
  global $wpdb;
  $title = $contact_form->title();

  $submission = wpcf7_Submission::get_instance();
  if ( $submission ) {
    $formData = $submission->get_posted_data();
  }


  $name = $formData['your-name'];
   $email = $formData['your-email'];
   $phone = $formData['your-phone'];
   $mensaje = $formData['your-message'];
  $url = $formData['_url'];

Open in new window

PHPWordPress

Avatar of undefined
Last Comment
Scott Fell

8/22/2022 - Mon
David H.H.Lee

Do you have a declared url hidden field in your form?

eg:
[hidden _url]


<script>
jQuery(document).ready(function(){
var url= window.location.href;  
jQuery('input.wpcf7-form-control.wpcf7-hidden').attr("value",url) ;    
 });    
</script>

Open in new window





Roberto Parker

ASKER
Like this:
In the form:
[hidden _url]
<label> Nombre  (requerido)
    [text* your-name] </label>

<label> Email  (requerido)
    [email* your-email] </label>

And in the body;
url: [_url]

And in the plugin:

<script> jQuery(document).ready(function(){ var url= window.location.href;   jQuery('input.wpcf7-form-control.wpcf7-hidden').attr("value",url) ;      });     </script>


David H.H.Lee

do you get the value for $url = $formData['_url']? 
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
Roberto Parker

ASKER
Yes
David H.H.Lee

Good. Glad to hear that.
Roberto Parker

ASKER
Hi sorry my bad. Not reading the variable

I want to know where the script goes. If I add it to the plugin I get an error

⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
David H.H.Lee

You can add the script directly inside the form's template editor section. Put try..catch block and share the error details for further inspection.

<script> 
jQuery(document).ready(function()
{ 
try{
  var url= window.location.href;  
  alert('url='+url); 
  jQuery('input.wpcf7-form-control.wpcf7-hidden').attr("value",url) ;  
  }catch(e){
   alert(e);
  }  
});     
</script>

Open in new window

Scott Fell

The issue with using javascript to get that data is it can easily be manipulated.

I have a small article on this

https://www.experts-exchange.com/articles/31767/Wordpress-ContactForm7-Save-Submitted-Data-To-Your-Own-Database.html

$url = $submission->get_meta('url')


ASKER CERTIFIED SOLUTION
Scott Fell

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.