开发者

Make PHP read drop down list in HTML form

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 va开发者_JAVA百科lid 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?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜