Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End PHP form-mailer + validation WordPress help

  • This topic is empty.
Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #33120
    mjkorbel
    Member

    Hello all. This is my first posting on this forum, but certainly not my first time at this site. This site has been so helpful and inspirational to me that I consider it one of my go-to sites for info, help, and advice. Generally I can find what I need without posting, but the past two days have been so stressful that I need some extra help.

    I know Basic PHP (VERY BASIC). I created a WordPress theme which has a newsletter signup form in the footer which consists of an E-mail text-field and a submit button. When the user enters the E-mail, the script goes to another page I created which will test the Email address against a regular expression. If it meets the requirements, a message is displayed on this new page which reads “Thank you.” If the E-mail address is an incorrect format, the form is displayed in the same place as the “Thank you” message is displayed in.

    Before I get into the code, I must note that this script works 100% fine on another site, but it’s setup is slightly different (which I think is where my problem is). On the other site, the form is also in the footer, HOWEVER it goes to a file which is not included in the WordPress theme for that site, but in the main directory instead. I have wordpress in a /wpress/ directory but the root is for non-wordpress files.

    I really need to include this script into the theme folder for this theme so I can use it ‘right outa the box’ when I install the theme onto a new blog. Here’s what I’ve got:

    In the header.php file I have included:

    
    $email_patt = "/[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+.[A-Za-z]{2,4}$/";
    unset($contactThanks);
    unset($error_email);
    if(isset($_POST) and $_POST == "yes")
    {
    if(!preg_match($email_patt,$_POST))
    {
    $error_email = "

    You must enter a valid E-mail address.";
    }
    if (!isset($error_email))

    {
    $email = $_POST["email"];
    $email_from = '[email protected]';
    $email_subject = "I want your newsletter!";
    $email_body = "This is the E-mail generated by the form which allows people to submit errors they find with .

    E-mail: $email;";
    $to = "[email protected]";
    $headers .= "MIME-Version: 1.0rn";
    $headers .= "Content-Type: text/html; charset=ISO-8859-1rn";
    mail($to,$email_subject,$email_body,$headers);
    $contactThanks = "Your E-mail has been successfully added. Thank you.";

    }}
    ?>


    In the footer.php file I have included:




    I have created a static page where I included the following:


    if (!isset($contactThanks))
    {
    echo "
    Your E-mail address is not valid. Please resubmit.


    E-mail addresses must be in this format: [email protected].


    Email:




    ";
    }

    ?>

    Pretty straight forward and easy script. What I want is so that the form action doesn’t have to be an absolute URL but a relative URL so I can use the script anywhere. ALSO it is to be noted that the script doesn’t really work correctly in my WordPress Theme but DOES WORK perfectly on my other two web sites.

    When I submit the form while on the main page of my WordPress theme it directs me towards the WP Login form. Not what I want. When I submit the form after being on a single post page the form redirects the user to the correct page, sends the E-mail if the criteria is met, but the messages displayed to the user are always the same. If the email was correct it sends, but the message still says it didn’t. I am confused and ideally I don’t even want the validation to happen in the header.php file but considering the code has to be in the header, the header.php file seems like my only option with WordPress.

    Any help would be amazing. I practically pulled an all-nighter and have been working on this for two days with MINIMAL successes. Please also note that included some spaces in my script so it would display on this forum. Without the spaces, this forum wouldn’t display my code.
    Thanks all- MICHAEL

    #72899
    mjkorbel
    Member

    For the record–those STRONG tags are a result of me setting my code to BOLD before I realized there was a code option two buttons over from BOLD option. And there are a few extra spaces there which I included because my code wasn’t displaying (again, because I didnt realize there was a code button to use with code. Whoops. Newbie.. ;)!!)

Viewing 2 posts - 1 through 2 (of 2 total)
  • The forum ‘Back End’ is closed to new topics and replies.