Results 1 to 2 of 2

Thread: Getting radio buttons and check boxes to print to email

  1. #1
    Join Date
    Oct 2010
    Location
    Lakewood, New York
    Posts
    7
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Getting radio buttons and check boxes to print to email

    Hello,
    I am trying to get my form to send a simple male female, yes no answer to my email form with radio buttons. Everything else in the form works. I have been playing with this for hours and can't seem to resolve it.

    I also need to have a list of check boxes that more than one can be selected like:
    What kind of music do you like?

    Rock
    Pop
    ETC

    I do not have any code in for check boxes


    Here is my code.
    Any help would be greatly appreciated.

    Thank you
    DeZiner


    Code
    ----------------------------------------
    Above the head

    PHP Code:
    <?php 
    $your_email 
    ='gwhite@dezinezone2002.com';// <<=== update to your email address

    session_start();
    $errors '';
    $name '';
    $visitor_email '';
    $user_message '';

    if(isset(
    $_POST['submit']))
    {
        
        
    $name $_POST['name'];
        
    $visitor_email $_POST['email'];
        
    $visitor_q1 $_POST['q1'];
        
    $user_message $_POST['message'];
        
    ///------------Do Validations-------------
        
    if(empty($name)||empty($visitor_email))
        {
            
    $errors .= "\n Name and Email are required fields. ";    
        }
        if(
    IsInjected($visitor_email))
        {
            
    $errors .= "\n Bad email value!";
        }
        if(empty(
    $_SESSION['6_letters_code'] ) ||
          
    strcasecmp($_SESSION['6_letters_code'], $_POST['6_letters_code']) != 0)
        {
        
    //Note: the captcha code is compared case insensitively.
        //if you want case sensitive match, update the check above to
        // strcmp()
            
    $errors .= "\n The captcha code does not match!";
        }
        
        if(empty(
    $errors))
        {
            
    //send the email
            
    $to $your_email;
            
    $subject="New form submission";
            
    $from $your_email;
            
    $ip = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '';
            
            
    $body "A user  $name submitted the contact form:\n".
            
    "Full Name: $name\n".
            
    "Email: $visitor_email \n".
            
    "Gender: $gender \n".
            
    "Q1: $visitor_q1 \n".
            
    "Message: \n ".
            
    "$user_message\n".
            
    "IP: $ip\n";    
            
            
    $headers "From: $from \r\n";
            
    $headers .= "Reply-To: $visitor_email \r\n";
            
            
    mail($to$subject$body,$headers);
            
            
    header('Location: thank-you.html');
        }
    }

    // Function to validate against any email injection attempts
    function IsInjected($str)
    {
      
    $injections = array('(\n+)',
                  
    '(\r+)',
                  
    '(\t+)',
                  
    '(%0A+)',
                  
    '(%0D+)',
                  
    '(%08+)',
                  
    '(%09+)'
                  
    );
      
    $inject join('|'$injections);
      
    $inject "/$inject/i";
      if(
    preg_match($inject,$str))
        {
        return 
    true;
      }
      else
        {
        return 
    false;
      }
    }
    ?>
    ------------------------------------------------

    In the head

    HTML Code:
    <script language="JavaScript" src="scripts/gen_validatorv31.js" type="text/javascript"></script>


    -------------------------------------------------

    The form (In the body)

    Code:
    <?php
    if(!empty($errors)){
    echo "<p class='err'>".nl2br($errors)."</p>";
    }
    ?>
    <div id='contact_form_errorloc' class='err'></div>
    <form method="POST" name="contact_form" 
    action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>"> 
    <p>
    <label for='name'>Full Name: </label><br>
    <input type="text" name="name" value='<?php echo htmlentities($name) ?>'>
    </p>
    <p>
    <label for='email'>Email: </label><br>
    <input type="text" name="email" value='<?php echo htmlentities($visitor_email) ?>'>
      <p> 
      <p>
    <label for='q1'>Q1: </label><br>
    <input type="text" name="q1" value='<?php echo htmlentities($visitor_q1) ?>'>
      <p> 
      <p>
    <label for='gender'>Male: </label>
    &nbsp;&nbsp;&nbsp;
    <input type="radio" name="Gender" value='<?php echo htmlentities($male) ?>'/>
        <br />
    <label for='Gender'>Female:</label>&nbsp;
    <input type="radio" name="Gender" value='<?php echo htmlentities($female) ?>'/>
        <br />
      </p>
    
    <p>
    <label for='message'>Message:</label> <br>
    <textarea name="message" rows=8 cols=30><?php echo htmlentities($user_message) ?></textarea>
    </p>
    <p>
    <img src="captcha_code_file.php?rand=<?php echo rand(); ?>" id='captchaimg' ><br>
    <label for='message'>Enter the code above here :</label><br>
    <input id="6_letters_code" name="6_letters_code" type="text"><br>
    <small>Can't read the image? click <a href='javascript: refreshCaptcha();'>here</a> to refresh</small>
    </p>
    <input type="submit" value="Submit" name='submit'>
    </form>
    Last edited by jscheuer1; 10-18-2010 at 02:25 AM. Reason: format code

  2. #2
    Join Date
    Jul 2010
    Location
    Minnesota
    Posts
    256
    Thanks
    1
    Thanked 21 Times in 21 Posts

    Default

    You have defined the variable $gender anywhere so it has no value, hence why it doesn't show when the email is sent. Define it like you have the $_POST variable for the rest of the form.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •