0

Hey all, I have an HTML form on my website which currently only uses text boxes and a submit button to send to a .php file and then to my email. I'm trying to replace one of these text boxes with a drop down (select, option) menu.

Here is my HTML form:

<form id="ajax-contact-form" action="javascript:alert('success!');">
<label>Name:*</label><INPUT class="textbox" type="text" name="name" value=""><br />

<label>E-Mail:*</label><INPUT class="textbox" type="text" name="email" value=""><br />

<label>Number Desired:*</label><INPUT class="textbox" type="text" name="numberdesired" value=""><br />

<label>Message:</label><TEXTAREA class="textbox" NAME="message" ROWS="7" COLS="40"></TEXTAREA><br /><br />


<INPUT class="textbox" type="hidden" name="subject" value="Form Submission" >

<label>Human Verification:*<br />
<?=$_SESSION['n1']?> + <?=$_SESSION['n2']?> =</label><input type="text" name="captcha" id="captcha" /><br />


<label>&nbsp;</label><INPUT class="button" type="submit" name="submit" value="Send Message">
</form>

Here is the php file that it sends to:

<?php
/*
Credits: Bit Repository
URL: http://www.bitrepository.com/
*/

include 'config.php';

session_name("fancyform");  /* starting the session */
session_start();


$post = (!empty($_POST)) ? true : false;

if ($post) {
    include 'functions.php';

    $email = trim($_POST['email']);
    $name = stripslashes($_POST['name']);
    $subject = stripslashes($_POST['subject']);
    $captcha = stripslashes($_POST['captcha']);
    $numberdesired = stripslashes($_POST['numberdesired']);
    $message = stripslashes($_POST['message']);

    $error = '';

    // Check name
    if (!$name) {
        $error .= 'Please enter your name.<br />';
    }

    // Check email
    if (!$email) {
        $error .= 'Please enter an e-mail address.<br />';
    }

    if ($email && !ValidateEmail($email)) {
        $error .= 'Please enter a valid e-mail address.<br />';
    }

    if (!$numberdesired) {
        $error .= 'Please enter the number desired.<br />';
    }

    if ((int)$_POST['captcha'] != $_SESSION['expect'])
        $error .= 'Wrong verification number.';

    //Send the Name, Email, and Message in a formated version.
    $email_message = "The following message was sent to you from....\n\n";

    function clean_string($string) {
        $bad = array("content-type","bcc:","to:","cc:","href");
        return str_replace($bad,"",$string);
    }
    $email_message .= "Email: ".clean_string($email)."\n";
    $email_message .= "Gamertag: ".clean_string($name)."\n";
    $email_message .= "Credits Desired: ".clean_string($numberdesired)."\n";
    $email_message .= "Message: ".clean_string($message)."\n";

    if (!$error)    {
        $mail = mail(WEBMASTER_EMAIL, $subject, $email_message,
            "From: ".$name." <".$email.">\r\n"
            ."Reply-To: ".$email."\r\n"
            ."X-Mailer: PHP/" . phpversion());

        if ($mail) {
            echo 'OK';
        }
    }
    else {
        echo '<div class="notification_error">'.$error.'</div>';
    }
}
?>

Now I'm fairly new at PHP. I don't think the 'stripslashes' will read a drop down menu. Is there something else I can use?

1
  • 1
    Note that stripslashes() is just for working around the PHP/server misconfiguration magic_quotes (see PHP manual for better solution.) Commented Dec 16, 2010 at 4:07

1 Answer 1

3

The value from the current menu selection will be returned in your $_POST variable.

The fact that the text came from a pulldown menu rather than a textbox makes no difference to your php program.

The only "input" field which beheaves at all differently is "checkbox". The $_POST variable will not returned at all if none of the selections are checked.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.