Forums

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

Home Forums Back End Form Won’t Submit

  • This topic is empty.
Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #45048
    LaurelBrittany
    Participant

    I am having trouble getting my form to submit. It was working until I added the code for the drop down menu, and now it won’t submit anymore. http://lwebdesigns.net/tools/forms/form.php

    <?php
    $errors = array();
    $missing = array();
    if (isset($_POST)) {
    $to = '[email protected]';
    $subject = 'Feedback from contact form';
    $expected = array('name', 'email', 'comments', 'gender', 'terms', 'extras', 'os');
    $required = array('name', 'email', 'comments', 'terms', 'os');
    if (!isset($_POST)) {
    $_POST = array();
    }
    $minimumChecked = 2;
    if (count($_POST) < $minimumChecked) {
    $errors = true;
    }
    if (!isset($_POST)) {
    $_POST = '';
    $errors = true;
    }
    $headers = "From: [email protected]";
    $headers .= "Content-type: text/plain; charset=utf-8";
    $authenticate = '[email protected]';
    require 'mail_process.php';
    if ($mailSent) {
    header('Location: thanks.php');
    exit;
    }
    }
    ?>
    <!DOCTYPE HTML>
    <html>
    <head>
    <meta charset="utf-8">
    <title>Contact Us</title>
    <link href="../styles.css" rel="stylesheet" type="text/css">
    </head>
    <body>
    <h1>Contact Us</h1>
    <?php if (($_POST && $suspect) || ($_POST && isset($errors))) { ?>
    <p class="warning">Sorry your mail could not be sent.</p>

    <?php } elseif ($errors || $missing) { ?>
    <p class="warning">Please fix the item(s) indicated.</p>
    <?php }?>
    <form name="contact" method="post" action="<?php echo $_SERVER; ?>">
    <p>
    <label for="name">Name:
    <?php if ($missing && in_array('name', $missing)) { ?>
    <p class="warning">Please enter your name</p>
    <?php } ?>
    </label>
    <input type="text" name="name" id="name"
    <?php
    if ($errors || $missing) {
    echo 'value="' . htmlentities($name, ENT_COMPAT, 'utf-8') . '"';
    }
    ?>
    >
    </p>
    <p>
    <label for="email">Email
    <?php if ($missing && in_array('email', $missing)) { ?>
    <p class="warning">Please enter your email address</p>
    <?php } elseif (isset($errors)) { ?>
    <p class="warning">Invalid email address</p>
    <?php } ?>
    </label>
    <input type="text" name="email" id="email"
    <?php
    if ($errors || $missing) {
    echo 'value="' . htmlentities($email, ENT_COMPAT, 'utf-8') . '"';
    }
    ?>
    >
    </p>
    <p>
    <label for="comments">Comments:
    <?php if ($missing && in_array('comments', $missing)) { ?>
    <p class="warning">You forgot to add your comments</p>
    <?php } ?>
    </label>
    <textarea name="comments" id="comments"><?php
    if ($errors || $missing) {
    echo htmlentities($comments, ENT_COMPAT, 'utf-8');
    }
    ?></textarea>
    </p>
    <fieldset><legend>Gender <?php
    if ($missing && in_array('gender', $missing)) {?>
    <p class="warning">Please select a value</p><?php } ?></legend><p>
    <input type="radio" name="gender" value="f" id="gender_f"
    <?php
    if ($_POST && $gender == 'f') {
    echo 'checked';
    }
    ?>
    >

    <label for="gender_f">Female</label>
    <input type="radio" name="gender" value="m" id="gender_m"
    <?php
    if ($_POST && $gender == 'm') {
    echo 'checked';
    }
    ?>
    >
    <label for="gender_m">Male</label>
    <input type="radio" name="gender" value="won't say" id="gender_0"
    <?php
    if (!$_POST || $gender == "won't say") {
    echo 'checked';
    }
    ?>
    >
    <label for="gender_0">Rather not say</label>
    </fieldset>
    </p>
    <fieldset><legend>Optional Extras: <?php if (isset($errors)) { ?>
    <p>Please select at least <?php echo $minimumChecked; ?></p>
    <?php } ?></legend><p>
    <input type="checkbox" name="extras[]" value="sun roof" id="extras_0"
    <?php
    if ($_POST && in_array('sun roof', $extras)) {
    echo 'checked';
    }
    ?>
    >
    <label for="extras_0">Sun roof</label>
    <br />
    <input type="checkbox" name="extras[]" value="aircon" id="extras_1"
    <?php
    if ($_POST && in_array('aircon', $extras)) {
    echo 'checked';
    }
    ?>
    >
    <label for="extras_1">Air conditioning</label>
    <br />
    <input type="checkbox" name="extras[]" value="automatic" id="extras_2"
    <?php
    if ($_POST && in_array('automatic', $extras)) {
    echo 'checked';
    }
    ?>
    >
    <label for="extras_2">Automatic transmission</label>
    </p></fieldset>
    <p>
    <label for="os">Operating system:<?php if ($missing && in_array('os', $missing)) { ?>
    <p class="warning">Please make a selection</p>
    <?php } ?></label>
    <select name="os" id="os">
    <option value="" <?php if (!$_POST || $os == '') {
    echo 'selected';
    } ?>>Please make a selection</option>
    <option value="Linux" <?php if ($_POST && $os == 'Linux') {
    echo 'selected';
    } ?>
    >Linux</option>
    <option value="Mac"<?php if ($_POST && $os == 'Mac') {
    echo 'selected';
    } ?>>Mac OS X</option>
    <option value="Windows"<?php if ($_POST && $os == 'Windows') {
    echo 'selected';
    } ?>>Windows</option>
    </select>
    </p>

    <p>
    <input type="checkbox" name="terms" id="terms" value="Agreed"
    <?php
    if ($_POST && $terms) {
    echo 'checked';
    }
    ?>
    >
    <label for="terms">I agree to the terms and conditions
    <?php if ($missing && in_array('terms', $missing)) { ?>
    <p>Please signify acceptance</p>
    <?php } ?>
    </label>
    </p>
    <p>
    <input type="submit" name="send" id="send" value="Send Comments">
    </p>
    </form>

    </body>
    </html>

    Check out this Pen!

    #136211
    LaurelBrittany
    Participant

    mailprocess.php

    <?php
    $suspect = false;
    $pattern = '/Content-Type:|Bcc:|CC:/i';

    function isSuspect($val, $pattern, &$suspect) {
    if (is_array($val)) {
    foreach ($val as $item) {
    isSuspect($item, $pattern, $suspect);
    }
    } else {
    if (preg_match($pattern, $val)) {
    $suspect = true;
    }
    }
    }

    isSuspect ($_POST, $pattern, $suspect);

    if (!$suspect) {
    foreach ($_POST as $key => $value) {
    $temp = is_array($value) ? $value : trim($value);
    if (empty($temp) && in_array($key, $required)) {
    $missing[] = $key;
    $$key = '';
    } elseif(in_array($key, $expected)) {
    $$key = $temp;
    }
    }
    }

    if (!$suspect & !empty($email)) {
    $validemail = filter_input(INPUT_POST, 'email', FILTER_VALIDATE_EMAIL);
    IF ($validemail) {
    $headers .= "rnReply-to: $validemail";
    } else {
    $errors = true;
    }
    }

    if (!$suspect && !$missing && !$errors) {
    $message = '';
    foreach ($expected as $item) {
    if (isset($$item) && !empty($$item)) {
    $val = $$item;
    } else {
    $val = 'Not selected';
    }
    if (is_array($val)) {
    $val = implode(', ', $val);
    }
    $item = str_replace(array('_', '-'), ' ', $item);
    $message .= ucfirst($item) . ": $valrnrn";
    }
    $message = wordwrap($message, 70);

    $mailSent = mail($to, $subject, $message, $headers, $authenticate);
    if (!mailsent) {
    $errors = true;
    }
    }
    Check out this Pen!

    #136258
    __
    Participant

    What “drop down menu”? Do you mean the `

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