Skip to content

Instantly share code, notes, and snippets.

@johnnypea
Last active August 29, 2015 14:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save johnnypea/8c5e13f5ddf7910e4c38 to your computer and use it in GitHub Desktop.
Save johnnypea/8c5e13f5ddf7910e4c38 to your computer and use it in GitHub Desktop.
Presmerovanie s parametrom v Contact Form 7
add_filter( 'wpcf7_load_js', '__return_false' );
class WPCF7_Submit_Redirect {
var $field; //nazov pola, napr. 'your-name'
var $url; //adresa, na ktoru sa presmeruje
var $form_id; //ID formularu
function __construct( $field, $url, $form_id = 0 ) {
$this->field = $field;
$this->url = $url;
$this->form_id = $form_id;
add_action( 'wpcf7_submit', array( $this, 'redirect' ), 10, 2 );
add_shortcode( 'contact-form-7-field', array( $this, 'shortcode' ) );
}
public function redirect( $contact_form, $result ) {
if( $this->form_id && $this->form_id != $contact_form->id() )
return;
if ( $result['status'] == 'mail_sent' && isset( $_POST[$this->field] ) ) {
wp_redirect( add_query_arg( $this->field, $_POST[$this->field], $this->url ) );
exit;
}
}
public function shortcode() {
if ( ! empty( $_GET[$this->field] ) )
return $_GET[$this->field];
}
}
new WPCF7_Submit_Redirect( 'nazov-pola', 'http://example.com/dakujem', 11378 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment