tags:

views:

118

answers:

1

I've got about 6 subdomains that have a "contact us" link and I'm sending all these links to a single form that uses "Contact Form 7". I add ?from=site-name to each of the links so that I can set a $referredFrom variable in the contact form.

The only two things I'm missing are (1) the ability to insert this referredFrom variable into the email that I get whenever someone submits the form and (2) The ability to redirect the user back to the site they came from (stored in $referredFrom)

Any ideas?

Here's a bit of code from includes/classes.php that I thought might be part of the email insert but its not doing much...

function mail() {
    global $referrer;
    $refferedfrom = $referrer; //HERE IS MY CUSTOM CODE
    $fes = $this->form_scan_shortcode();

    foreach ( $fes as $fe ) {
        $name = $fe['name'];
        $pipes = $fe['pipes'];

        if ( empty( $name ) )
            continue;

        $value = $_POST[$name];

        if ( WPCF7_USE_PIPE && is_a( $pipes, 'WPCF7_Pipes' ) && ! $pipes->zero() ) {
            if ( is_array( $value) ) {
                $new_value = array();
                foreach ( $value as $v ) {
                    $new_value[] = $pipes->do_pipe( $v );
                }
                $value = $new_value;
            } else {
                $value = $pipes->do_pipe( $value );
            }
        }

        $this->posted_data[$name] = $value;
        $this->posted_data[$refferedfrom] = $referrer; //HERE IS MY CUSTOM CODE
    }

I'm also thinking that I could insert the referredFrom code somewhere in this function as well...

function compose_and_send_mail( $mail_template ) {
    $regex = '/\[\s*([a-zA-Z][0-9a-zA-Z:._-]*)\s*\]/';
    $callback = array( &$this, 'mail_callback' );

    $mail_subject = preg_replace_callback( $regex, $callback, $mail_template['subject'] );
    $mail_sender = preg_replace_callback( $regex, $callback, $mail_template['sender'] );
    $mail_body = preg_replace_callback( $regex, $callback, $mail_template['body'] );
    $mail_recipient = preg_replace_callback( $regex, $callback, $mail_template['recipient'] );

    $mail_headers = "From: $mail_sender\n";

    if ( $mail_template['use_html'] )
        $mail_headers .= "Content-Type: text/html\n";

    $mail_additional_headers = preg_replace_callback( $regex, $callback,
        $mail_template['additional_headers'] );
    $mail_headers .= trim( $mail_additional_headers ) . "\n";

    if ( $this->uploaded_files ) {
        $for_this_mail = array();
        foreach ( $this->uploaded_files as $name => $path ) {
            if ( false === strpos( $mail_template['attachments'], "[${name}]" ) )
                continue;
            $for_this_mail[] = $path;
        }

        return @wp_mail( $mail_recipient, $mail_subject, $mail_body, $mail_headers,
            $for_this_mail );
    } else {
        return @wp_mail( $mail_recipient, $mail_subject, $mail_body, $mail_headers );
    }
}
A: 

First of all, in order to get the from variable you'll have to insert

$referrer = $_GET['from'];

somewhere in the top script, at least before the last line you inserted.

Additionally, in the second script you have to add the value to $mail_body somehow, but since I don't know how that value is made up I can't help much with that. Is the code for this form available online somewhere?

Arda Xi
http://wordpress.org/extend/plugins/contact-form-7/
Scott B