Ich versuche, den Ländernamen aus dem Drop-down-Menü des Landes zu erhalten, in dem ich das Pipe-Symbol verwendet habe. so in meiner Form
[text* FullName id:fullname]
[select* country id:country include_blank "United States | [email protected]" "Canada | [email protected]" "Mexico | [email protected]" "United Kingdom | [email protected]"]
Ich habe different-2 E-Mail mit Ländernamen verwendet, weil ich E-Mails an Firmenmitarbeiter gemäß Ländernamen senden muss. In der E-Mail-Vorlage habe ich verwendet [country]
E-Mail zu bekommen und [_raw_country]
um den Ländernamen zu erhalten, der gut funktioniert. Ich versuche, den Ländernamen in der Datei function.php zu erhalten, um ihn auf diese Weise in der Datenbank zu speichern.
function contactform7_before_send_mail( $form_to_DB ) {
//set your db details
$mydb = new wpdb('user','password','databasename','localhost');
$form_to_DB = WPCF7_Submission::get_instance();
if ( $form_to_DB )
$formData = $form_to_DB->get_posted_data();
$fullname = $formData['FullName'];
$country = $formData['country'];
$mydb->insert( 'mytable', array( 'fullname' =>$fullname,'country' =>$country), array( '%s' ) );
}
Aber es gibt nichts. wenn ich versuche, so zu werden
$country = $formData['country'][0];
Es gibt mir nur eine E-Mail-ID wie [email protected], die ich versucht habe $country = $formData['country'][1];
Es bringt mir nichts. Ich habe es auch versucht $country = $formData['_raw_country'];
Aber kein Glück.
Dies ist das Referenzdokument
https://contactform7.com/selectable-recipient-with-pipes/
Ich habe diese Antwort in Ihrer anderen Frage gepostet. Das sollte funktionieren.
add_action( 'wpcf7_before_send_mail', 'cf7_pipes_so_67686211');
function cf7_pipes_so_67686211( $contact_form ) {
global $wpdb;
$mydb = new wpdb('user','password','database','localhost');
// Get Form Tags
$tags = $contact_form->scan_form_tags();
$pipe_array = array();
// Find the Values of the Pipes
foreach ($tags as $tag){
if ($tag->name === 'primarybusiness'){
$pipe_array = $tag->pipes->to_array();
}
}
// Get the form data
$form_to_DB = WPCF7_Submission::get_instance();
if ( $form_to_DB ) {
$formData = $form_to_DB->get_posted_data();
$fullname = $formData['FullName'];
foreach ($pipe_array as $value) {
// Compare and find the pipe value
if ( $posted_data['primarybusiness'][0] === $value[1] ){
$primarybusiness = $value[0];
}
}
$mydb->insert( 'mytable', array( 'fullname'=>$fullname,'primarybusiness'=>$primarybusiness), array( '%s' ) );
}
}
du brauchst sowas:
<?php
// Get the submitted data
$submission = WPCF7_Submission::get_instance();
if ( ! $submission
or ! $posted_data = $submission->get_posted_data() ) {
return;
}
// Get the contact form additional data
$contact_form = $submission->get_contact_form();
// get the tag used in the form
$mail_tags=$contact_form->scan_form_tags();
// search into tags for country
$key = array_search('country', array_column($mail_tags, 'name'));
// get the country pipes values
$pipes = new WPCF7_Pipes( $mail_tags[$key]->raw_values );
// get an array with the pipes
$pipes_array = $pipes->to_array();
// get the choosen value
$pipes_val = array_search( $posted_data['country'][0], array_column($pipes_array, 1));
// finally!
error_log(print_r($posted_data['country'],true));
error_log(print_r("in",true));
error_log(print_r($pipes_array[$pipes_val][0],true));
Sie können versuchen, dies zu verwenden stackoverflow.com/questions/60361457/… um Ihre Formulardaten an das Fehlerprotokoll zu senden und zu sehen, was die Ergebnisse sind.
– Howard E
26. Mai 2021 um 9:37 Uhr
[“FullName”]=> Zeichenkette(6) “Deepak” [“country”]=> Array(1) { [0]=> Zeichenkette(21) “[email protected]” }
– Deepak3301086
26. Mai 2021 um 10:34 Uhr
Ich habe folgt, was Sie vorschlagen ob_start (); var_dump($formData); error_log(ob_get_clean()); und die Ausgabe wurde im obigen Kommentar angezeigt.
– Deepak3301086
26. Mai 2021 um 10:35 Uhr
Ist diese Frage (in gewisser Weise) ein Duplikat Ihrer anderen Frage?
– Howard E
27. Mai 2021 um 9:48 Uhr