WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] I need to add a new field to my custom form (6 posts)

  1. RenzoGamboa
    Member
    Posted 2 years ago #

    Hi. pluggable.php has the function function wp_mail( $to, $subject, $message, $headers = '', $attachments = array() ) . My contact form gets all this fields ex. `wp_mail($et_email_to, sprintf( '[%s] ' . esc_html($_POST['et_contact_subject']), $et_site_name ),
    esc_html($_POST['et_contact_message'],
    'From: "'. esc_html($_POST['et_contact_name']) .'" <' . esc_html($_POST['et_contact_email']) . ' >');
    ` I want to add a new field so that i can collect the phone number as well. Any ideas? not willing to use plugins.

  2. not willing to use plugins.

    Why?

    Because your options are:

    1) Use a plugin
    2) Write the code in functions.php (which is exactly the same as using a plugin)
    2b) Write your own plugin
    3) Editing core (NEVER EVER DO THAT)

    So ... Why not a plugin?

  3. Helen Hou-Sandi
    WordPress Dev
    Posted 2 years ago #

    I don't understand what you're looking to do here - why are you looking at the pluggable wp_mail() function? If you're collecting a phone number, you need a form that a user enters it in, and then you need to put the phone number into the text of the $message that you send. wp_mail(), which is essentially just a wrapper for PHP mail(), doesn't have a phone number argument.

  4. RenzoGamboa
    Member
    Posted 2 years ago #

    @Ipstenu dont want to use a plugin because all i want is just a single field (phone number), besides i dont want to create another page and change the design.
    @helen i was just reading about you yesterday as i was doing a research about multiple check boxes.
    1. apparently adding a new argument to the function wp_mail() is unnecessary, correct?
    2. if so, how can i put the phone number into the text of the $message?

    thank you guys!..

  5. Helen Hou-Sandi
    WordPress Dev
    Posted 2 years ago #

    I don't know where you are implementing this form, but this sounds like a basic PHP contact form. You build an HTML form, process the data in PHP, build a $message (which is just a string), and mail it. If you don't know how to do that and do it securely, you really should reconsider using a plugin.

  6. RenzoGamboa
    Member
    Posted 2 years ago #

    Thank you Helen i figured it out. yeah, you guys were right, adding another argument was crazy. So contact_number is the field that has the phone number.
    <!-------->
    wp_mail($email_to, sprintf( '[%s] ' . esc_html($_POST['contact_subject']), $et_site_name ), esc_html($_POST['contact_message']).esc_html($_POST['contact_number']), 'From: "'. esc_html($_POST['contact_name']) .'" <' . esc_html($_POST['contact_email']) . ' >');
    <!------------>
    the field for my form looks like this:

    <!------------->
    <p class="clearfix">
    <input type="text" name="contact_number" value="<?php if ( isset($_POST['contact_number']) ) echo esc_attr($_POST['contact_number']); else esc_attr_e('Phone Number','MyTheme'); ?>" id="contact_number" class="input" /></p>

    <!------------->
    Thank you. Please look at it and let me know if you think i need to add something else.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags