• Resolved nathanvh

    (@nathanvh)


    Hello,

    First of all thank you for making this plugin. It helps me alot! Unfortunately I ran upon a problem with sending the mail. I made a wizard with questions and in the end the user can send a email to me for a appointment. During the wizard I created a jQuery function which dynamicly changes some hidden fields in the ‘end’ form. In the form are some basic questions like name and email.

    When I send the mail, every basic input is succesfully send. But the hidden input fields aren’t.

    Can somebody help me?

    The send-a-mail function (which works fine, but no hidden input values are send)

    function handle_aircokiezer_submission( $form, $fields, $args )
    {
        $to = '[email protected]';
        $subject = 'Thank you for your reaction';
    
        $headers = "From: [email protected]\r\n";
        $headers .= "MIME-Version: 1.0\r\n";
        $headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
    
        $message = '<html><body>';
        $message .= '<h1>This is a test!</h1>';
        $message .= '<table>';
        $message .= '<tr><th>Fieldname</th><th>Data</th></tr>';
        $message .= '<tr><td>Name</td><td>' . af_get_field( 'firstname' ) . ' ' . af_get_field( 'lastname' ) . '</td></tr>'; // This works fine
        $message .= '<tr><td>E-mail</td><td>' . af_get_field( 'E-mailadres' ) . '</td></tr>'; // This works fine
        $message .= '<tr><td>Innerparts</td><td>' . af_get_field( 'hiddenInnerparts' ) . '</td></tr>'; // This doesn't work
        $message .= '<tr><td>Room 1 size</td><td>' . af_get_field( 'hiddenRoom1Size' ) . '</td></tr>'; // This doesn't work
        $message .= '<tr><td>Room 1 heating</td><td>' . af_get_field( 'hiddenRoom1Heating' ) . '</td></tr>'; // This doesn't work
    
        mail($to, $subject, $message, $headers);
    }
    

    The create-hidden-inputs function:

    function hidden_field( $form, $args )
    {
    echo '<input type="hidden" name="hiddenInnerparts" value="1">';
    echo '<input type="hidden" name="hiddenRoom1Size" value="2">';
    echo '<input type="hidden" name="hiddenRoom1Heating" value="3">';
    }
    add_action( 'af/form/hidden_fields/key=form_5a997b9a7925a', 'hidden_field' );
    • This topic was modified 6 years, 11 months ago by nathanvh.
Viewing 1 replies (of 1 total)
  • Plugin Author fabianlindfors

    (@fabianlindfors)

    Hi! I’m glad you’re enjoying AF and seems like you’ve found an interesting use case, cool!

    Hidden fields can’t be retrieved using af_get_field. This is because af_get_field uses ACF field functions to format and process values. Since the hidden fields aren’t really ACF fields the function can’t be used. Instead I would simply use the regular $_POST variable to retrieve your values, something like:

    $message .= '<tr><td>Innerparts</td><td>' . $_POST['hiddenInnerparts'] . '</td></tr>'; // This should work
    $message .= '<tr><td>Room 1 size</td><td>' . $_POST['hiddenRoom1Size'] . '</td></tr>'; // This should work
    $message .= '<tr><td>Room 1 heating</td><td>' . $_POST['hiddenRoom1Heating'] . '</td></tr>'; // This should work
    

    Also worth noting is that there is no validation or sanitation for these fields as they are not ACF fields.

    Hope this was helpful!

Viewing 1 replies (of 1 total)
  • The topic ‘Send hidden fields with mail’ is closed to new replies.