Support » Plugin: HTML Forms » To email dynamic

  • Resolved marbaque

    (@marbaque)


    I am adding the contact form directly on a single post template file. Like this:

    <?= do_shortcode('[hf_form slug="my-form"]'); ?>

    This is working fine, but I want to send the email to an address saved in a custom field into the post, besides de admin email. Is this even possible?

    • This topic was modified 5 months, 1 week ago by  marbaque.
    • This topic was modified 5 months, 1 week ago by  marbaque.
    • This topic was modified 5 months, 1 week ago by  marbaque.
Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Contributor Lap

    (@lapzor)

    Hi,

    That would be possible if you create your own custom “form action” instead of using the default email action.

    You can make a copy of email.php in the actions folder and rename it.

    1. Copy class from email.php
    2. Change name, choose unique $type and $label
    3. Create instance of that class and call hook method.

    $action = new HTML_Forms\Actions\Webhook();
    $action->hook();

    Hope that helps. If you have any questions, please let us know!

    marbaque

    (@marbaque)

    Thank you for replying @lapzor

    Could you point on some extra direction here?

    Can I add this new class into my theme?

    Plugin Contributor Lap

    (@lapzor)

    When you copy the Email.php file in the Actions folder in the Boxzilla plugin folder, you make a new file there, let’s say named MyOwnEmailAction.php
    That is the file where you replace the class name / type / label.
    And then of course write your own PHP code to email it to the field value.

    Note that this is not something you can just copy / paste and figure out if you are not actually an experienced PHP programmer.

    Hope that helps. If you have any questions, please let us know!

    marbaque

    (@marbaque)

    Thank you @lapzor. That goes a little out of my php knowledge. However, I managed to achieve what I intended using one of the code snippets I found in github:

    add_filter( 'hf_form_markup', function( $markup ) {
    	$email = get_field('email');
    	if ($email) {
    		$markup .= '<input type="hidden" name="HIDDEN_EMAIL" value="' . $email . '" />';
    		return $markup;
    	}
    	
    });

    This way I can get the value from the custom fields and pass it as a hidden input in the form. It is working without errors so far.

    • This reply was modified 5 months ago by  marbaque. Reason: Added explanation
    • This reply was modified 5 months ago by  marbaque.
Viewing 4 replies - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.