Sticky forms

Discussion in 'PHP' started by Birthe_nielsen, Dec 15, 2010.

  1. #1
    Hello :)
    I have a problem with my sticky form - is used to work but when I added this: Subscribe to newsletter
    <input type="checkbox" name="newsletter" id="newsletter" value="1" <?php if(isset($_POST['newsletter']) == '1') echo "checked" ?>/> <p>

    Interested in sales material
    <input type="checkbox" name="salesmaterial" id="salesmaterial" value="1" <?php if(isset($_POST['salesmaterial']) == '2') echo "checked" ?>/> <p>

    The sticky forms stopped working.
    This is the whole code:

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

    <title>Subscribe</title>

    </head>

    <body>

    SUBSCRIBE TO NEWSLETTER OR SALES MATERIAL<p>

    <?php

    if(isset($_POST['submit']))
    {

    //form data
    $name = $_POST['name']; // required
    $lname = $_POST['lname']; // required
    $email= $_POST['email']; // required
    $country = $_POST ['country']; // required
    $newsletter = isset($_POST['newsletter']);
    $salesmaterial = isset($_POST['salesmaterial']);


    //validation

    $errorstring = "";

    if(!$name)
    $errorstring = $errorstring."Name<br>";

    if(!$lname)
    $errorstring = $errorstring."Last name<br>";

    if (!preg_match ('/^[\w.-]+@[\w.-]+\.[AZa-z]{2,6}$/', $_POST['email']))
    $errorstring = $errorstring."A valid email address<br>";

    if(!$country)
    $errorstring = $errorstring."Your country<br>";

    if(!isset($_POST['newsletter']) && (!isset($_POST['salesmaterial'])))
    $errorstring = $errorstring."Choose to order sales material or subscribe to newsletter<br>";

    if($errorstring!="")

    echo "Please fill out the following fields:<br>$errorstring";

    else{

    //connect to database

    require_once "connect_to_mysql.php";

    // Insert information into the table "customer"

    $mysql_query = "INSERT INTO main_table (name, lname, email, country, salesmaterial, newsletter, created)
    VALUES('$name', '$lname', '$email', '$country', '$salesmaterial', '$newsletter', now())";



    $mysql_result = @mysqli_query($myConnection, $mysql_query);

    if(!mysqli_affected_rows($myConnection) == 1) {
    echo mysqli_error($myConnection);
    }

    //replies

    echo "Thank you, <i>$name $lname</i> , for your order/subscription<p>";


    echo "We will send you our sales material and/or monthly newsletter at <i>$email</i>.<p>";

    }

    $_POST=array();


    } //closing submit

    ?>

    <!-- form code -->

    <form name="subscribe" action="subscribe.php" method="post"/>


    <!-- text -->

    *Name<input type="text" name="name" id="name" size="20" value='<?php if(isset($_POST['name'])) {
    echo $_POST['name'];} ?>'/> <p>

    *Last name<input type="text" name="lname" id="lname" size="20" maxlength="60" value='<?php if(isset($_POST['lname'])) {
    echo $_POST['lname'];} ?>'/> <p>


    *Email<input type="text" name="email" id="email" size="10" value='<?php if(isset($_POST['email'])) {
    echo $_POST['email'];} ?>'/><p>


    <!-- drop down menu. -->

    *Your country

    <select name="country" id="country">

    <option value="0" <?php if(isset($_POST['country']) && $_POST['country'] == 0) {
    echo 'selected="selected"';} ?>></option>

    <option value="Denmark" <?php if(isset($_POST['country']) && $_POST['country'] == 'denmark') {
    echo 'selected="selected"';} ?>>Denmark</option>

    <option value="Norway" <?php if(isset($_POST['country']) && $_POST['country'] == 'norway') {
    echo 'selected="selected"';} ?>>Norway</option>

    <option value="Sweden" <?php if(isset($_POST['country']) && $_POST['country'] == 'sweden') {
    echo 'selected="selected"';} ?>>Sweden</option>

    <option value="Other" <?php if(isset($_POST['country']) && $_POST['country'] == 'other') {
    echo 'selected="selected"';} ?>>Other</option>

    </select> <p>

    <!-- check boxes. -->

    Subscribe to newsletter
    <input type="checkbox" name="newsletter" id="newsletter" value="1" <?php if(isset($_POST['newsletter']) == '1') echo "checked" ?>/> <p>

    Interested in sales material
    <input type="checkbox" name="salesmaterial" id="salesmaterial" value="1" <?php if(isset($_POST['salesmaterial']) == '2') echo "checked" ?>/> <p>


    <!-- submit button. -->

    <input type="submit" name="submit" value="Send" />


    </form>


    </body>
    </html>

    I hope someone can help, it's such an annoying error :)
     
    Birthe_nielsen, Dec 15, 2010 IP
  2. kp_mastermind

    kp_mastermind Active Member

    Messages:
    885
    Likes Received:
    17
    Best Answers:
    0
    Trophy Points:
    58
    #2
    use $newsletter = trim($_POST['newsletter']);
    for both
     
    kp_mastermind, Dec 15, 2010 IP
  3. Birthe_nielsen

    Birthe_nielsen Peon

    Messages:
    6
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    It doesn't work :(
     
    Birthe_nielsen, Dec 15, 2010 IP