Link to home
Start Free TrialLog in
Avatar of Roberto Parker
Roberto ParkerFlag 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

Avatar of David H.H.Lee
David H.H.Lee
Flag of Malaysia image

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





Avatar of 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>


do you get the value for $url = $formData['_url']? 
Yes
Good. Glad to hear that.
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

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

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
Avatar of Scott Fell
Scott Fell
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial