WordPress.org

Ready to get started?Download WordPress

Forums

Ninja Forms
[resolved] Use name as 'from' name in email address (12 posts)

  1. press_ppm
    Member
    Posted 1 year ago #

    Hi,

    In the same way that you can click "Use this as the 'From' email address for Administrative recepients of this form? " on a textbox.

    Is there anyway to change it so it can "Use this as the "From" name for Administrative recepients of this form?"

    So it pulls the email from one textbox and the name from another?

    At the moment the email comes through with the submitted email address fine but the name is WordPress and is slightly annoying and hard to organise my bookings.

    http://wordpress.org/extend/plugins/ninja-forms/

  2. Kevin Stover
    The WP Ninjas
    Plugin Author

    Posted 1 year ago #

    Hey,

    We're probably going to be adding this in as an option in the near future, but you can follow the tutorial here: http://wpninjas.com/change-the-from-email-address-dynamically-with-ninja-forms/ if you would like to add this before we officially release it. Just make sure that you uncheck the "Use this as the 'From' email address" in the field settings.

  3. press_ppm
    Member
    Posted 1 year ago #

    Hi,

    Thanks for your reply.

    I can't get it to work. Here's what I have done:

    1. Added the folder 'booking-name' to the folder 'wp-content/plugins' and the file 'booking-name.php' within the 'booking-name' folder.

    2. Put this into the .php file:

    <?php
    /*
    Plugin Name: My Custom Functions
    */
    add_action( 'ninja_forms_email_admin', 'ninja_forms_change_from_address' );
    function ninja_forms_change_from_address(){
       global $ninja_forms_processing;
       if( 1 == $ninja_forms_processing->get_form_ID( 1 ) ) {
        $user_email = $ninja_forms_processing->get_field_value( 5 );
        $user_name = $ninja_forms_processing->get_field_value( 4 );
        $user_email = $user_name." <".$user_email.">";
        $ninja_forms_processing->update_form_setting( 'email_from', $user_email );
       }
    }

    I put the number 5 in because that's the field id of the email address and 4 is the field id of the name. Put a 1 in the brackets as that's my form id.

    3. Saved it all and it doesn't work. Now nothing comes through to my email. I unchecked the option in the form aswell.

  4. James Laws
    The WP Ninjas
    Plugin Author

    Posted 1 year ago #

    The first problem I see with this is this line...

    if( 1 == $ninja_forms_processing->get_form_ID( 1 ) ) {

    Inside the get_form_ID() function you should be trying to set the form ID. It's getting the current form's ID for you. Providing that your form ID is 1 it should look like this...

    if( 1 == $ninja_forms_processing->get_form_ID() ) {

    This checks to see if the current form being processed is in fact ID 1. If not it does nothing, if so it will process the code you have inside the if statement.

  5. press_ppm
    Member
    Posted 1 year ago #

    Yeh sorry i forgot to remove that. I put it in there just to try it as it wasn't working. However the problem was that I hadn't gone to the plugins and activated it.

    Works perfectly now.

    Thank you!

  6. James Laws
    The WP Ninjas
    Plugin Author

    Posted 1 year ago #

    Awesome, and yes, a crucial step.

    Glad you got it all working.

  7. press_ppm
    Member
    Posted 1 year ago #

    I have another form on a different page.

    Do I copy duplicate the code and switch the form id and field id?

  8. Kevin Stover
    The WP Ninjas
    Plugin Author

    Posted 1 year ago #

    Yes. You would copy it and change the appropriate values.

  9. press_ppm
    Member
    Posted 1 year ago #

    I take it not like this as this stops the whole site working:

    <?php
    /*
    Plugin Name: My Custom Functions
    */
    
    add_action( 'ninja_forms_email_admin', 'ninja_forms_change_from_address' );
    function ninja_forms_change_from_address(){
       global $ninja_forms_processing;
       if( 1 == $ninja_forms_processing->get_form_ID( ) ) {
        $user_email = $ninja_forms_processing->get_field_value( 5 );
        $user_name = $ninja_forms_processing->get_field_value( 4 );
        $user_email = $user_name." <".$user_email.">";
        $ninja_forms_processing->update_form_setting( 'email_from', $user_email );
       }
    }
    
    add_action( 'ninja_forms_email_admin', 'ninja_forms_change_from_address' );
    function ninja_forms_change_from_address(){
       global $ninja_forms_processing;
       if( 2 == $ninja_forms_processing->get_form_ID( ) ) {
        $user_email = $ninja_forms_processing->get_field_value( 23 );
        $user_name = $ninja_forms_processing->get_field_value( 26 );
        $user_email = $user_name." <".$user_email.">";
        $ninja_forms_processing->update_form_setting( 'email_from', $user_email );
       }
    }
  10. Kevin Stover
    The WP Ninjas
    Plugin Author

    Posted 1 year ago #

    You just need to change the name of the function. It has to be unique. Just make sure that you change the name in the second part of the add_action as well.

  11. press_ppm
    Member
    Posted 1 year ago #

    Hmm strange, this doesn't work.
    It still comes through as the standard admin:

    <?php
    /*
    Plugin Name: My Custom Functions
    */
    
    add_action( 'ninja_forms_email_admin', 'ninja_forms_change_from_address' );
    function ninja_forms_change_from_address(){
       global $ninja_forms_processing;
       if( 1 == $ninja_forms_processing->get_form_ID( ) ) {
        $user_email = $ninja_forms_processing->get_field_value( 5 );
        $user_name = $ninja_forms_processing->get_field_value( 4 );
        $user_email = $user_name." <".$user_email.">";
        $ninja_forms_processing->update_form_setting( 'email_from', $user_email );
       }
    }
    
    add_action( 'ninja_forms_name_admin', 'ninja_forms_change_from_name' );
    function ninja_forms_change_from_name(){
       global $ninja_forms_processing;
       if( 2 == $ninja_forms_processing->get_form_ID( ) ) {
        $user_email = $ninja_forms_processing->get_field_value( 25 );
        $user_name = $ninja_forms_processing->get_field_value( 26 );
        $user_email = $user_name." <".$user_email.">";
        $ninja_forms_processing->update_form_setting( 'email_from', $user_email );
       }
    }
  12. Kevin Stover
    The WP Ninjas
    Plugin Author

    Posted 1 year ago #

    The name change is going to be a feature that we add into the plugin in our weekly update. It'll be live sometime on Monday. Then you won't need the code at all. We've had several requests for this, so we're just going to add it into the core of the plugin.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags

No tags yet.