WordPress.org

Ready to get started?Download WordPress

Forums

Newsletter Sign-Up
Custom form template (3 posts)

  1. arnodmental
    Member
    Posted 1 year ago #

    I'm using zurb foundation and would like to use the recommended zurb markup for forms with the newsletter sign up form.
    I like the template override mechanism and modified your plugin in this way.
    Here is a proposal :

    --- NewsletterSignUp.php
    +++ (clipboard)
    @@ -486,28 +485,20 @@
    
     		 if(!isset($_POST['nsu_submit']) || count($errors) > 0) { //form has not been submitted yet
    -       $alternateFile = get_stylesheet_directory().'/newsletter-sign-up/submit_form.php';
    -       if(file_exists($alternateFile)) {
    -         ob_start();
    -         include($alternateFile);
    -         $output = ob_get_contents();
    -         ob_clean();
    -       } else {
    -   			$output .= "<form class=\"nsu-form\" id=\"nsu-form-$formno\" action=\"$form_action\" method=\"post\">";
    -   			if(isset($opts['mailinglist']['subscribe_with_name']) && $opts['mailinglist']['subscribe_with_name'] == 1) {
    -   				$output .= "<p><label for=\"nsu-name-$formno\">$name_label</label><input class=\"nsu-field\" id=\"nsu-name-$formno\" type=\"text\" name=\"$name_id\" value=\"$name_value\" onfocus=\"if(this.value == '$name_value') this.value=''\" />";
    -                                   if(isset($errors['name-field'])) $output .= '<span class="nsu-error error notice">'.$errors['name-field'].'</span>';
    -                                   $output .= "</p>";
    -   			}
    -
    -   			$output .= "<p><label for=\"nsu-email-$formno\">$email_label</label><input class=\"nsu-field\" id=\"nsu-email-$formno\" type=\"text\" name=\"$email_id\" value=\"$email_value\" onfocus=\"if(this.value == '$email_value') this.value=''\" />";
    -                           if(isset($errors['email-field'])) $output .= '<span class="nsu-error error notice">'.$errors['email-field'].'</span>';
    -                           $output .= "</p>";
    -   			$output .= $additional_fields;
    -   			$output .= "<p><input type=\"submit\" id=\"nsu-submit-$formno\" class=\"nsu-submit\" name=\"nsu_submit\" value=\"$submit_button\" /></p>";
    -   			$output .= "</form>";
    -       }
    
    +			$output .= "<form class=\"nsu-form\" id=\"nsu-form-$formno\" action=\"$form_action\" method=\"post\">";
    +			if(isset($opts['mailinglist']['subscribe_with_name']) && $opts['mailinglist']['subscribe_with_name'] == 1) {
    +				$output .= "<p><label for=\"nsu-name-$formno\">$name_label</label><input class=\"nsu-field\" id=\"nsu-name-$formno\" type=\"text\" name=\"$name_id\" value=\"$name_value\" onfocus=\"if(this.value == '$name_value') this.value=''\" />";
    +                                if(isset($errors['name-field'])) $output .= '<span class="nsu-error error notice">'.$errors['name-field'].'</span>';
    +                                $output .= "</p>";
    +			}
    +
    +			$output .= "<p><label for=\"nsu-email-$formno\">$email_label</label><input class=\"nsu-field\" id=\"nsu-email-$formno\" type=\"text\" name=\"$email_id\" value=\"$email_value\" onfocus=\"if(this.value == '$email_value') this.value=''\" />";
    +                        if(isset($errors['email-field'])) $output .= '<span class="nsu-error error notice">'.$errors['email-field'].'</span>';
    +                        $output .= "</p>";
    +			$output .= $additional_fields;
    +			$output .= "<p><input type=\"submit\" id=\"nsu-submit-$formno\" class=\"nsu-submit\" name=\"nsu_submit\" value=\"$submit_button\" /></p>";
    +			$output .= "</form>";
    
     		} else { // form has been submitted

    (changed file is frontend/newsletterSignUp.php)

    Now I can create a newsletter-sign-up/submit_form.php in my theme if I want to override the form.

    I'm not so familiar with wordpress so I don't know if there is a more "wp way" to acheive this,

    http://wordpress.org/extend/plugins/newsletter-sign-up/

  2. Danny van Kooten
    Member
    Plugin Author

    Posted 1 year ago #

    Hi,

    Sounds like a valid functionality which might be worth implementing into NSU. Your approach works fine but I'll give it a thought myself too.

    Thanks!

  3. arnodmental
    Member
    Posted 1 year ago #

    Nice ! Let me know if you find a more elegant way, I'm curious about it !

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic