2017-10-02 3 views
1

ich ein Formular in Single- $ post_type.php haben, die Daten zu meiner Themen Funktionen Datei sendet. Die Form Beiträge in Ordnung, wenn der Benutzer angemeldet.Wordpress: Wie eine Post-Anforderung für nicht eingeloggte Benutzer zu handhaben, wenn das Formular für eingeloggte Benutzer arbeitet

Aber wenn der Benutzer nicht in der Form dann gerade angemeldet ist, schlägt fehl, und lädt die Homepage.

Kurz gesagt, ist die Form, ein Bewerbungsformular. Das Formular sendet alle Daten an die Funktion, die Funktion erstellt zwei E-Mails und sendet sie beide an die HR und den Kandidaten. Dann wird auf eine Dankeseite umgeleitet.

DIE FORM PROZESSOR IN functions.php

add_action('admin_post_nopriv_email_appliaction_form', 'processform'); 
add_action('admin_post_email_appliaction_form', 'processform'); 

function processform() { 
    //Handle the CV Upload 
    require_once(ABSPATH . 'wp-admin/includes/image.php'); 
    require_once(ABSPATH . 'wp-admin/includes/file.php'); 
    require_once(ABSPATH . 'wp-admin/includes/media.php');   

    $attachment_id = media_handle_upload('cv', $_POST['post_id']); 
    $attachments = get_attached_file($attachment_id); 

    //Get variables for emai content 
    $jobTitle = $_POST['jobTitle']; 
    $jobLocation = $_POST['jobLocation']; 
    $fullName = $_POST['fullName']; 
    $email = $_POST['email']; 
    $telephone = $_POST['tel']; 
    $quickmessage = strip_tags ($_POST['message']); 

    $to = $_POST['email']; 
    $admin_email = get_option('admin_email'); 

    //Build the message to the candidate 
    $messageCandidate = email_header(); 
    $messageCandidate .= candidate_application($jobTitle, $jobLocation); 
    $messageCandidate .= reason_jobapplication(); 
    $messageCandidate .= email_footer(); 

    //Build the message to the head office 
    $messageOffice = email_header(); 
    $messageOffice .= new_candidate_application($jobTitle, $jobLocation, $fullName, $email, $telephone, $quickmessage); 
    $messageOffice .= reason_new_jobapplication(); 
    $messageOffice .= email_footer(); 


    $headers[] = 'Content-Type: text/html; charset=UTF-8'; 
    $headers[] = 'From: Greenfield IT Recruitment <[email protected]>'; 

    $mailCandidate = wp_mail($to, 'Application successfull', $messageCandidate, $headers); 
    $mailoffice = wp_mail($admin_email, 'New Candidate Application', $messageOffice, $headers, array($attachments)); 

    if ($mailCandidate) { 
     wp_delete_attachment($attachment_id, true); 
     wp_redirect(get_site_url().'?p=227'); 
     exit; 
    } 



} 

HTML-Formular in Ein- $ POST_TYPE.PHP

<form id="jobApplication" name="jobApplication" action="<?php echo esc_url(admin_url('admin-post.php')); ?>" method="post" enctype="multipart/form-data" onsubmit="return validation(this)"> 
     <div class="col-sm-6"> 
      <input type="text" name="fullName" placeholder="Full Name: (required)" required> 
      <input type="email" name="email" placeholder="Email: (required)" required> 
      <input type="tel" name="tel" placeholder="Telephone: (required)" required> 
      <textarea name="message" placeholder="Quick message"></textarea> 
      <span>Please upload a copy of your cv in .doc or .docx format. We will accept a pdf.</span> 
      <span><input type="file" name="cv" accept="application/pdf" required></span> 
     </div> 
     <div class="col-sm-6"> 
      <p><strong>Protecting your data</strong><br>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p> 
      <input type="hidden" name="action" value="email_appliaction_form"> 
      <input type="hidden" name="jobTitle" value="<?php the_title(); ?>"> 
      <input type="hidden" name="jobLocation" value="<?php echo $meta['city'][0]; ?>"> 
      <input type="hidden" name="post_id" id="post_id" value="<?php the_id(); ?>" /> 
      <input type="submit" class="btn" name="submit"> 
     </div> 
    </form> 

glücklich den Rest des Codes in der funciton posten wenn nötig.

Dank

+1

Wir können nicht mit 2 Zeilen Code nichts tun .. Bitte würden Sie geben uns mehr Code – Tomm

+0

wird es hilfreich sein, wenn Ihr gehören „Wordpress“ in Titel und Beschreibung – parpar

+0

aktualisiert. Vielen Dank. –

Antwort

0

Der Grund, dies funktioniert nicht, weil es eine Funktion innerhalb des Themas war ich, dass eingeschränkter Zugriff auf nur wp-admin hatte hinzugefügt Admin. Dies erforderte, dass Sie eingeloggt waren, andernfalls würde es die Homepage umleiten. Ich habe noch einen Workaround zu finden.

add_action('init', 'blockusers_init'); 
function blockusers_init() { 
    if ( 
    is_admin() && ! current_user_can('administrator') && 
    ! (defined('DOING_AJAX') && DOING_AJAX) && 
    ! ($_SERVER['REQUEST_METHOD'] === 'POST')) 
    { 
    wp_redirect(home_url()); 
    exit; 
} 
} 
Verwandte Themen