Stránka ze které byl odeslán formulář

Úvodní stránka Fórum podpory WordPressu Pluginy (funkčnost webu) Stránka ze které byl odeslán formulář

Zvolené téma obsahuje celkem 3 odpovědi. Do diskuze (3 účastníci) se naposledy zapojil uživatel  admin a poslední změna je stará 9 let, 9 měsíců.

Aktuálně jsou na stránce zobrazeny 4 příspěvky - 1. až 4. (z celkem 4)
  • Autor
    Příspěvky
  • #19664

    mil667
    Participant

    Mám v šabloně tento formulář:

          if(!isset($hasError)) {
             $user_email = get_post_meta($post->ID, '_email', true);
             $emailTo = get_the_author_meta('user_email').','.$user_email;
             $subject = __('Zpráva z webu od ','smooth').$name;
             $sendCopy = trim($_POST['sendCopy']);
             $body = "Name: $name \n\nEmail: $email \n\nComments: $comments";
             $headers = __('From: ','smooth').get_bloginfo('name').' <'.$emailTo.'>' . "\r\n" . __('Reply-To: ','smooth') . $email;
             
             wp_mail($emailTo, $subject, $body, $headers);
    
             if($sendCopy == true) {
                $subject = __('You emailed Your ','smooth').get_bloginfo('name');
                $headers = __('From:  ','smooth').get_the_author_meta('user_email');
                wp_mail($email, $subject, $body, $headers);
             }
    
             $emailSent = true;
    
          }
       }
    }

    Potřebuji do něj doplnit funkci, která by spolu s formulářem odeslala na mail informaci ze které stránky webu byl formulář odeslán.

    Jak se to dá udělat? Děkuji.

    #19669

    sjiamnocna
    Participant
    Web

    Nemohu si pomoci, ale váš kód mi žádný formulář nepřipomína. Jediné co vidím je $_POST['sendCopy']
    jinak adresu bych získal nějak takto:
    $url='http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
    popř. bych ji přidal k formuláři jako hidden input:
    <input type="hidden" name="acturl" value="<?php echo $url; ?>">
    a připojil ji k tělu zprávy

    $url=$_POST['acturl'];
    wp_mail($emailTo, $subject, $body.'<br/>Odesláno z URL '.$url, $headers);
    #19694

    mil667
    Participant

    Díky za reakci. Kompletní kód vypadá takto:

    <?php
    
    //If the form is submitted
    if(isset($_POST['submitted'])) {
    
       //Check to see if the honeypot captcha field was filled in
       if(isset($_POST['checking']) && (trim($_POST['checking']) !== '')) {
          $captchaError = true;
       } else {
       
          //Check to make sure that the name field is not empty
          if(trim($_POST['contactName']) === '') {
             $nameError = __('Zadejte Vaše jméno.','smooth');
             $hasError = true;
          } else {
             $name = trim($_POST['contactName']);
          }
          
          //Check to make sure sure that a valid email address is submitted
          if(trim($_POST['email']) === '')  {
             $emailError = __('Zadejte Váš e-mail.','smooth');
             $hasError = true;
          } else if (!eregi("^[A-Z0-9._%-]+@[A-Z0-9._%-]+\.[A-Z]{2,4}$", trim($_POST['email']))) {
             $emailError = __('Zadejte platný formát e-mailu.','smooth');
             $hasError = true;
          } else {
             $email = trim($_POST['email']);
          }
             
          //Check to make sure comments were entered   
          if(trim($_POST['comments']) === '') {
             $commentError = __('Zapoměli jste zadat Vaši zprávu.','smooth');
             $hasError = true;
          } else {
             if(function_exists('stripslashes')) {
                $comments = stripslashes(trim($_POST['comments']));
             } else {
                $comments = trim($_POST['comments']);
             }
          }
             
          //If there is no error, send the email
          if(!isset($hasError)) {
             $user_email = get_post_meta($post->ID, '_email', true);
             $emailTo = get_the_author_meta('user_email').','.$user_email;
             $subject = __('Zpráva z webu od ','smooth').$name;
             $sendCopy = trim($_POST['sendCopy']);
             $body = "Name: $name \n\nEmail: $email \n\nComments: $comments \n\nURL: $url";
             $headers = __('From: ','smooth').get_bloginfo('name').' <'.$emailTo.'>' . "\r\n" . __('Reply-To: ','smooth') . $email;
             
             wp_mail($emailTo, $subject, $body, $headers);
    
             if($sendCopy == true) {
                $subject = __('You emailed Your ','smooth').get_bloginfo('name');
                $headers = __('From:  ','smooth').get_the_author_meta('user_email');
                wp_mail($email, $subject, $body, $headers);
             }
    
             $emailSent = true;
    
          }
       }
    } ?>
    
    <?php if(isset($emailSent) && $emailSent == true) { ?>
    
       <div class="thanks">
          <strong><?php _e('Děkujeme, ','smooth');?><?php echo '<span class="font-width:bold!important">'.$name.'</span>';?></strong>
          <p><?php _e('Vaše zpráva byla úspěšně odeslána.<br/> Budeme Vás kontaktovat.','smooth');?></p>
       </div>
    
    <?php } else { ?>
    
             
          <?php global $post; if(isset($hasError) || isset($captchaError)) { ?>
             <p class="error"><?php _e('Vyplňte prosím všechna pole.','smooth');?><p>
          <?php } ?>
    
          <form action="<?php the_permalink(); ?>" class="agent-contact-form print" method="post">
    
                   <p><input type="text" name="contactName" id="name-bar" value="Jméno<?php if(isset($_POST['contactName'])) echo $_POST['contactName'];?>" class="requiredField input-bar " /></p>
                   <?php if(isset($nameError) == ''){ ?>
                      <span class="error"><?php $nameError;?></span>
                   <?php } ?>
                
                   <p><input type="text" name="email" id="email-bar" value="E-mail<?php if(isset($_POST['email']))  echo $_POST['email'];?>" class="requiredField email input-bar" /></p>
                   <?php if(isset($emailError) == ''){ ?>
                      <span class="error"><?php $emailError;?></span>
                   <?php } ?>
             
                   <p><textarea name="comments" id="commentsText" class="requiredField message-box"><?php if(isset($_POST['comments'])) { if(function_exists('stripslashes')) { echo stripslashes($_POST['comments']); } else { echo $_POST['comments']; } } ?><?php _e('Mám zájem o více informací k ','smooth');?><?php echo $post->post_title ?></textarea></p>
                   <?php if(isset($commentError) == ''){ ?>
                      <span class="error"><?php $commentError;?></span>
                   <?php } ?>
             
                <input type="submit" name="submitted"  class="send-btn"   value="Odeslat" /></p>
    
          </form>      
    <?php } ?>

    Zkoušel jsem ho upravit podle toho co jste mi napsal, ale url na email nepřijde. Kód jsem upravil takto:

    <?php
    
    //If the form is submitted
    if(isset($_POST['submitted'])) {
    
       //Check to see if the honeypot captcha field was filled in
       if(isset($_POST['checking']) && (trim($_POST['checking']) !== '')) {
          $captchaError = true;
       } else {
       
          //Check to make sure that the name field is not empty
          if(trim($_POST['contactName']) === '') {
             $nameError = __('Zadejte Vaše jméno.','smooth');
             $hasError = true;
          } else {
             $name = trim($_POST['contactName']);
          }
          
          //Check to make sure sure that a valid email address is submitted
          if(trim($_POST['email']) === '')  {
             $emailError = __('Zadejte Váš e-mail.','smooth');
             $hasError = true;
          } else if (!eregi("^[A-Z0-9._%-]+@[A-Z0-9._%-]+\.[A-Z]{2,4}$", trim($_POST['email']))) {
             $emailError = __('Zadejte platný formát e-mailu.','smooth');
             $hasError = true;
          } else {
             $email = trim($_POST['email']);
          }
             
          //Check to make sure comments were entered   
          if(trim($_POST['comments']) === '') {
             $commentError = __('Zapoměli jste zadat Vaši zprávu.','smooth');
             $hasError = true;
          } else {
             if(function_exists('stripslashes')) {
                $comments = stripslashes(trim($_POST['comments']));
             } else {
                $comments = trim($_POST['comments']);
             }
          }
             
          //If there is no error, send the email
          if(!isset($hasError)) {
             $user_email = get_post_meta($post->ID, '_email', true);
             $emailTo = get_the_author_meta('user_email').','.$user_email;
             $subject = __('Zpráva z webu od ','smooth').$name;
             $sendCopy = trim($_POST['sendCopy']);
             $body = "Name: $name \n\nEmail: $email \n\nComments: $comments \n\nURL: $url";
             $headers = __('From: ','smooth').get_bloginfo('name').' <'.$emailTo.'>' . "\r\n" . __('Reply-To: ','smooth') . $email;
             
             $url=$_POST['acturl'];
             wp_mail($emailTo, $subject, $body.'<br/>Odesláno z URL '.$url, $headers);
    
             if($sendCopy == true) {
                $subject = __('You emailed Your ','smooth').get_bloginfo('name');
                $headers = __('From:  ','smooth').get_the_author_meta('user_email');
                wp_mail($email, $subject, $body, $headers);
             }
    
             $emailSent = true;
    
          }
       }
    } ?>
    
    <?php if(isset($emailSent) && $emailSent == true) { ?>
    
       <div class="thanks">
          <strong><?php _e('Děkujeme, ','smooth');?><?php echo '<span class="font-width:bold!important">'.$name.'</span>';?></strong>
          <p><?php _e('Vaše zpráva byla úspěšně odeslána.<br/> Budeme Vás kontaktovat.','smooth');?></p>
       </div>
    
    <?php } else { ?>
    
             
          <?php global $post; if(isset($hasError) || isset($captchaError)) { ?>
             <p class="error"><?php _e('Vyplňte prosím všechna pole.','smooth');?><p>
          <?php } ?>
    
          <form action="<?php the_permalink(); ?>" class="agent-contact-form print" method="post">
                    <input type="hidden" name="acturl" value="<?php echo $url; ?>">
                   <p><input type="text" name="contactName" id="name-bar" value="Jméno<?php if(isset($_POST['contactName'])) echo $_POST['contactName'];?>" class="requiredField input-bar " /></p>
                   <?php if(isset($nameError) == ''){ ?>
                      <span class="error"><?php $nameError;?></span>
                   <?php } ?>
                
                   <p><input type="text" name="email" id="email-bar" value="E-mail<?php if(isset($_POST['email']))  echo $_POST['email'];?>" class="requiredField email input-bar" /></p>
                   <?php if(isset($emailError) == ''){ ?>
                      <span class="error"><?php $emailError;?></span>
                   <?php } ?>
             
                   <p><textarea name="comments" id="commentsText" class="requiredField message-box"><?php if(isset($_POST['comments'])) { if(function_exists('stripslashes')) { echo stripslashes($_POST['comments']); } else { echo $_POST['comments']; } } ?><?php _e('Mám zájem o více informací k ','smooth');?><?php echo $post->post_title ?></textarea></p>
                   <?php if(isset($commentError) == ''){ ?>
                      <span class="error"><?php $commentError;?></span>
                   <?php } ?>
             
                <input type="submit" name="submitted"  class="send-btn"   value="Odeslat" /></p>
    
          </form>      
    <?php } ?>

    Předem díky za pomoc.

    #19703

    admin
    Keymaster
    Web

    Proč nepoužijete nějaký standardní plugin pro tvorbu formulářů, např. Contact Form 7? Jakým způsobem ten kód vkládáte do konkrétní stránky?

Aktuálně jsou na stránce zobrazeny 4 příspěvky - 1. až 4. (z celkem 4)

Pokud chcete odpovědět na toto téma, musíte se nejdříve přihlásit.

WordPress – novinky, návody a zajímavosti