Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9134081
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T08:35:54+00:00 2026-06-17T08:35:54+00:00

I have worked on this for a while and gave up because I couldn’t

  • 0

I have worked on this for a while and gave up because I couldn’t figure it out, but now I’m back to it. I have an email newsletter signup form on my website, and I have a checkbox for people to check if they are interested in music classes with me. The way I want the form to work is that if they are not interested in classes, I will get no value, but if they are interested in classes I get “Interested in classes – $city”. Right now I am getting “Interested in classes – $city” in both cases.

The form is kind of complicated because I’m using javascript as well as the regular html code (hiding divs, etc), so I think I’m getting confused there.

The form:

<form action="../index_success.php" method="post" id="sendEmail" class="email">
            <h3 class="register2">Newsletter Signup:</h3>
            <ul class="forms email">
                <li class="name">
                    <label for="yourName">Name: </label>
                    <input type="text" name="yourName" class="info" id="yourName" value="<?php echo $_POST['yourName']; ?>" /><br />
                </li>
                <li class="city"><label for="yourCity">City: </label>
                    <input type="text" name="yourCity" class="info" id="yourCity" value="<?php echo $_POST['yourCity']; ?>" /><br />
                </li>
                <li class="classes"><label for="classInterest">Interested in classes?: </label>
                    <input type="checkbox" name="classInterest" class="info" id="classInterest" value="Yes" /><br />
                </li>
                <li class="email">
                    <label for="emailFrom">Email: </label>
                    <input type="text" name="emailFrom" class="info" id="emailFrom" value="<?php echo $_POST['emailFrom']; ?>" />
                     <?php if(isset($emailFromError)) echo '<span class="error">'.$emailFromError.'</span>';

                     ?>
                </li>
                <li class="buttons email">
                     <button type="submit" id="submit">Send</button>
                     <input type="hidden" name="submitted" id="submitted" value="true" />
                </li>
            </ul>
        </form>

The javascript-my apologies if this code is not relevant to the question-I’m still pretty new so I have found that it is best to include too much rather than not enough! (I’m using jQuery):

    <script type="text/javascript">
$(document).ready(function(){

 $('#emailFrom')
  .focus(function(){
   if ($('#overlay').length) { return; } // don't keep adding overlays if one exists
   $('#sendEmail')

    .find('.name, .city, .classes').slideDown(300, function(){ $(this).show(); });
   $('.outeremailcontainer').css({ position: 'relative', bottom: 0, left: 0, zIndex : 1001 });
   $('<div id="overlay"></div>').appendTo('body');
  });

 $('#overlay').live('click', function(){
   $('#sendEmail')
    .css({ backgroundColor : 'transparent' })
    .find('.name, .city, .classes').slideUp(300);
   $('.outeremailcontainer').css({ position : 'static' });
   $('#overlay').remove();
  });

});
</script>

Here is the javascript for checking the errors on the form and emailing setting the value for the class interest classInterestVal:

$(document).ready(function(){
  $("#submit").click(function(){
    $(".error").hide();
    var hasError = false;
    var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;


    var emailFromVal = $("#emailFrom").val();

    if(emailFromVal == '') {
      $("#emailFrom").after('<span class="error"><br />You forgot to enter the email address to send from.</span>');
      hasError = true;

    } else if(!emailReg.test(emailFromVal)) {
      $("#emailFrom").after('<span class="error"<br />>Enter a valid email address to send from.</span>');
      hasError = true;
    }

    var yourNameVal = $("#yourName").val();
    if(yourNameVal == '') {
        $("#yourName").after('<span class="error"><br />You forgot to enter your name.</span>');
        hasError = true;
    }

    var yourCityVal = $("#yourCity").val();
    if(yourCityVal == '') {
        $("#yourCity").after('<span class="error"><br />You forgot to enter your city.</span>');
        hasError = true;
    }
    var classInterestVal = $("#classInterest").val();


    if(hasError == false) {
      $(this).hide();
      $("#sendEmail li.buttons").append('<img src="/wp-content/themes/default/images/template/loading.gif" alt="Loading" id="loading" />');
      $.post("/includes/sendemail.php",
//emailTo: emailToVal, 
           { emailFrom: emailFromVal, yourName: yourNameVal, yourCity: yourCityVal, classInterest: classInterestVal },
             function(data){
            $("#sendEmail").slideUp("normal", function() {
              $("#sendEmail").before('<h3 class="register2">Thank you!  You\'re on the email list!</h3><p class="emailbox">Click <a href="http://rattletree.com/Songs/Live_EP/Chikende.mp3">HERE</a> for your free song.</p>');
            });
             }
         );
    }
    return false;
  });
});

And lastly here is the sendEmail.php (this is where I put the conditional for $classInterest):

    <?php 
$mailTo = 'email@address.com'; // This is the hardcoded Recipient Address 
$mailSubject = 'Newsletter'; // This is the hardcoded Subject
$mailFrom = $_POST['emailFrom']; 
$yourName = $_POST['yourName']; 
$yourCity = $_POST['yourCity'];


if (isset($_POST['classInterest']) && $_POST['classInterest'] == 'Yes'){
                            $classInterest ="Class Interest - " . $yourCity;
                        }
                        else {
                            $classInterest = '';
                        }
$mailHeader = "From: {$mailFrom}"; 
$mailBody = "Name = {$yourName} City = {$yourCity} Class interest = {$classInterest}";

mail( $mailTo , $mailSubject , $mailBody , $mailHeader );
?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T08:35:55+00:00Added an answer on June 17, 2026 at 8:35 am

    Getting .val() from classInterest will always return the value whether it is checked or not. What you need to do is $(“#classInterest”).is(“:checked”) this will return a boolean telling you if the checkbox is checked or not.

    A good way to debug problems like this in the future would be to view the network tab in a browser like Chrome that has dev tools (F12). This will allow you to view the information that you are passing so that you can see where the error is occurring.

    If you want the value then do:

    var classInterest = $("#classInterest");
    var classInterestVal = classInterest.is(":checked") ? classInterest.val() : "";
    

    I’m caching the classInterest selector here for efficiency.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hi, I have worked with WCF for a while now but there is somthing
ReportLab/xhtml2pdf have worked perfectly until now when it crashes at this style bit in
I have worked with Django for a while but I am new to xml-rpc.
I found this question while trying to figure out how to make a TextBlock
I have worked with NSUserDefault but this keychain concept is totally new for me.
I have worked on this problem for my entire day and can't solve it.
I have come across Evernote's bookmarklet and was wondering how this worked. You can
I have an AS3 project making use of compile time constants. This has worked
I have run this program before and it worked fine. Then I added the
I have this weird problem with setting up cookies with PHP. Everything worked fine

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.