• Resolved mrprainx

    (@mrprainx)


    Hello everyone. I’m looking for help with an issue related to a newsletter subscription form.

    In the footer of [ redundant link removed ] there is a form in which the user should enter just his/her email addres.

    SCREENSHOT HERE

    The code of this form is:

    <form action="newsletter" method="post">
    <input style="width: 100%; margin-bottom: 5px;" name="email" id="email" type="text" value="" placeholder="il tuo indirizzo email" required />
    <input style="width: 50%;" type="submit" value="iscrivimi" />
    </form>

    When he/she submits the email by clicking on “iscrivimi” the form redirects to another page, called “newsletter” where there is another form with more fields to be filled.

    SCREENSHOT HERE

    I would like to have the email the user has filled already precompiled.

    I’ve tried to achieve this by using:

    <input type="text" name="email" id="email" value="<?php echo $_POST['email']; ?>" style="padding: 10px 2%; width: 90%; min-width: auto;">

    But what I get is:

    SCREENSHOT HERE

    What am I missing?

    Thank you in advance

    The page I need help with: [log in to see the link]

Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator Steven Stern (sterndata)

    (@sterndata)

    Volunteer Forum Moderator

    You can’t just drop PHP in-line in the content editor. You may want to make that second form a shortcode so you’re dealing with it in a programming context. By the way, that form is vulnerable to XSS and other problems. You need to make sure you sanitize the contents of $POST before echoing them onto your pages.

    Thread Starter mrprainx

    (@mrprainx)

    Thank you Steve.

    I will use <?php echo htmlspecialchars($_POST['email']); ?> to avoid XSS. Thank you for pointing this out.

    And I will give a try in using shortcode.

    Thank you again.

    • This reply was modified 6 years, 8 months ago by mrprainx.
    Thread Starter mrprainx

    (@mrprainx)

    For users who are looking for the same solution.

    I’ve managed to have this working by:

    1. Create a shortcode as suggested by Steve as follows:
      // Add Shortcode
      function newsletter_form() {
      
      	return htmlspecialchars($_POST['email']);
      }
      
      add_shortcode( 'newsletter-form', 'newsletter_form' );
    2. Add a filter in the functions.php file to use shortcodes inside <input> HTML tag, namely in the VALUE attribute as follows:
      // shortcodes in html
      
      add_filter( 'wp_kses_allowed_html', function ( $allowedposttags, $context ) {
          if ( $context == 'post' ) {
              $allowedposttags['input']['value'] = 1;
          }
          return $allowedposttags;
      }, 10, 2 );

      I found this solution here

    3. Edit the email field of the form as follows:
      <input type="text" name="email" id="email" value="[newsletter-form]" style="padding: 10px 2%; width: 90%; min-width: auto; color:#000000;">

    Hope this helps.

    • This reply was modified 6 years, 8 months ago by mrprainx.
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Pass an email address from one form to another’ is closed to new replies.