Support » Plugin: Contact Form 7 » php calculated with formula no show for user

  • Hello, I have the following fields in my contact form.
    [number height_window min: 10 max: 180 “95”]
    [number width_window min: 10 max: 380 “150”]

    Now I want the user not to be able to see my calculation in the HTML code, so it falls
    [calculated (width_window * height_window / 3.14159265)]
    out.

    Can I also implement the whole thing in php in functions.php?
    If yes how?

    $ formula_result = (width_window * height_window / 3.14159265);
    $ formula_important = (width_window + (88.5+ (height_window / 3.14159265)));
    (only example formula)

    And how do I get the result back into the email dispatch?

    • This topic was modified 5 months, 3 weeks ago by .

    The page I need help with: [log in to see the link]

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter Markus Böhm

    (@markusboehm)

    Can it work like that? or what else do I have to pay attention to?

    functions.php:

    add_filter('wpcf7_before_send_mail', 'myFunction');
    function myFunction($form)
    {
        // get post id from where the form was submitted
        $post_id = $_POST['_wpcf7_container_post'];
    
        // get the email from post field (modify it to actual field value)
        $height_window = get_field('height_window', $post_id)
        $width_window = get_field('width_window', $post_id)
        $stock = get_field('stock', $post_id)
    
    	$formula_result = ($width_window * $height_window / 3.14159265);
    	$formula_important = ($width_window + (88.5+ ($height_window / 3.14159265)));
    	$full_stock = ($formula_important+(4*$stock));
    
        // update the form properties
        $form->set_properties(array('formula_result' => $formula_result));
        $form->set_properties(array('formula_important' => $formula_important));
        $form->set_properties(array('full_stock' => $full_stock));
    }

    email:

    [full_stock]
    [formula_important]
    [formula_result]
    Thread Starter Markus Böhm

    (@markusboehm)

    Egal wie ich es mache bekomme ich es nicht hin.

    Kontaktformular:

    <label>Dein Bauchumfang [number umfang_bauchnabel min:10 max:500 "85"]</label>
    <label>Für wenn:[select* auswahl_erwachsener_kind "Erwachsener" "Kind"]</label>
    <label>[select* auswahl_groesse "Anfaenger" "Profi" "Experte" "Meister"]</label>

    habe folgendes in der Themen functions.php

    function myFunction()
    {
      	 $submission = WPCF7_Submission::get_instance();
     	 if ( $submission ) {
     	   $formData = $submission->get_posted_data();     
     	 }
    
        $umfang_bauchnabel = $formData['umfang_bauchnabel'];
        $auswahl_erwachsener_kind = $formData['auswahl_erwachsener_kind'];
        $auswahl_groesse = $formData['auswahl_groesse'];
    
    $profi_kind=$auswahl_groesse*5;
    
    	    $formData->set_properties(array('profi_kind' => $profi_kind));
    	    echo do_shortcode( '[contact-form-7 profi_kind "' . $profi_kind . '"]' );
    	    $formData->set_properties(array('durchmesser_reifen' => $profi_kind));
    	    echo do_shortcode( '[contact-form-7 durchmesser_reifen "' . $profi_kind . '"]' );
    }

    bekomme aber im Nachrichtenteil trotzdem keine shortcodes zum abrufen.
    wie z.B. [durchmesser_reifen] oder [profi_kind]

    was mache ich falsch?

    • This reply was modified 5 months, 3 weeks ago by .
Viewing 2 replies - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.