Roberto Parker
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'];
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>
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']?
ASKER
Yes
Good. Glad to hear that.
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
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>
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')
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Open in new window