PHP - Editar un formulario de contacto para que se pueda seleccionar el destinatario

 
Vista:

Editar un formulario de contacto para que se pueda seleccionar el destinatario

Publicado por Daniel (1 intervención) el 16/03/2015 17:03:15
Hola, Estoy intentando editar una plantilla de wordpress con un formulario de contacto para agregarla la opción de seleccionar el destinatario, ej: “Enviar a Sucursal Barcelona”, “Enviar a Sucursal Milan”

Entonces según a opción seleccionada se envía al e-mail correspondiente de esta sucursal.

Los archivos que procesan esto son "tour.php" en la siguiente sección de código:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<form id="pp_booking_form" method="post" action="/wp-admin/admin-ajax.php">
    <input type="hidden" id="action" name="action" value="pp_booking_mailer"/>
    <input type="hidden" id="tour_title" name="tour_title" value="<?php echo get_the_title(); ?>"/>
    <input type="hidden" id="tour_url" name="tour_url" value="<?php echo get_permalink($current_page_id); ?>"/>
 
    <div class="one_half">
        <label for="first_name"><?php echo _e( 'First Name', THEMEDOMAIN ); ?></label>
        <input id="first_name" name="first_name" type="text" class="required_field"/>
    </div>
 
    <div class="one_half last">
        <label for="last_name"><?php echo _e( 'Last Name', THEMEDOMAIN ); ?></label>
        <input id="last_name" name="last_name" type="text" class="required_field"/>
    </div>
 
    <br class="clear"/><br/>
 
    <div class="one_half">
        <label for="email"><?php echo _e( 'Email', THEMEDOMAIN ); ?></label>
        <input id="email" name="email" type="text" class="required_field"/>
    </div>
 
    <div class="one_half last">
        <label for="phone"><?php echo _e( 'Phone', THEMEDOMAIN ); ?></label>
        <input id="phone" name="phone" type="text"/>
    </div>
 
    <br class="clear"/><br/>
 
    <div class="one">
        <label for="message"><?php echo _e( 'Additional Message', THEMEDOMAIN ); ?></label>
        <textarea id="message" name="message" rows="7" cols="10"></textarea>
    </div>
 
    <br class="clear"/>
 
    <div class="one">
        <p>
            <input id="booking_submit_btn" type="submit" value="<?php echo _e( 'Book By Email', THEMEDOMAIN ); ?>"/>
        </p>
    </div>
</form>


Y "functions.php" en la siguiente parte del código:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/** 
*    Setup booking form mailing function 
**/
add_action('wp_ajax_pp_booking_mailer', 'pp_booking_mailer');
add_action('wp_ajax_nopriv_pp_booking_mailer', 'pp_booking_mailer');
 
function pp_booking_mailer() {
    check_ajax_referer( 'tgajax-post-contact-nonce', 'tg_security' );
 
    //Get your email address 
    $contact_email = get_option('pp_booking_email');
    $pp_contact_thankyou = '<br/>'.__( 'Thank you for booking! We will get back to you as soon as possible', THEMEDOMAIN );
    $pp_contact_thankyou.= '<br/><br/><a href="javascript:;" id="booking_close_form" class="button">'.__( 'Close', THEMEDOMAIN ).'</a>';
 
    //Error message when message can't send 
    define('ERROR_MESSAGE', 'Oops! something went wrong, please try to book later.');
 
    if (isset($_POST['first_name'])) {
 
        /* 
        | 
        | Begin sending mail 
        | 
        */
 
        $first_name = $_POST['first_name'];
        $last_name = $_POST['last_name'];
        $email = $_POST['email'];
        $phone = $_POST['phone'];
        $form_message = $_POST['message'];
 
        $tour_title = $_POST['tour_title'];
        $tour_url = $_POST['tour_url'];
 
        $from_name = $first_name.' '.$last_name;
 
        //Get contact subject 
        if(!isset($_POST['subject']))
        {
            $contact_subject = __( 'Booking form', THEMEDOMAIN );
        }
        else
        {
            $contact_subject = $_POST['subject'];
        }
 
        $headers = "";
           $headers.= 'From: '.$from_name.' <'.$email.'>'.PHP_EOL;
           $headers.= 'Reply-To: '.$from_name.' <'.$email.'>'.PHP_EOL;
           $headers.= 'Return-Path: '.$from_name.' <'.$email.'>'.PHP_EOL;
 
        $message = __( 'Booking for', THEMEDOMAIN ).' '.$tour_title.' ('.$tour_url.')'.PHP_EOL;
 
        $message.= 'Name: '.$from_name.PHP_EOL;
        $message.= 'Email: '.$email.PHP_EOL.PHP_EOL;
        $message.= 'Phone: '.$phone.PHP_EOL.PHP_EOL;
        $message.= 'Message: '.PHP_EOL.$form_message.PHP_EOL.PHP_EOL;
 
 
        if(!empty($first_name) && !empty($last_name) && !empty($email))
        {
            wp_mail($contact_email, $contact_subject, $message, $headers);
            echo '<p>'.$pp_contact_thankyou.'</p>';
 
            die;
        }
        else
        {
            echo '<p>'.ERROR_MESSAGE.'</p>';
 
            die;
        }
 
    }
    else
    {
        echo '<p>'.ERROR_MESSAGE.'</p>';
    }
    die();
}


Esas son las secciones que generan y procesan el formulario de contacto, pero ¿como hago para agregarle la función de "seleccionar destinatario"?

Desde ya muchas gracias.

Thanks in advanced.
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder