Hello all,
PHP I am a complete beginner, but I’m trying to. I have a form with PHP control where is INPUT and SELECT.
I do not know if I wrote well checking and send a SELECT. If it is not so please help me fix it.
:-[ :-[
[php]
Please select an option from the select box.
'; } else { echo 'You have selected: ', $_POST['title'], '.
'; } if (empty($_POST["name"])) { $nameErr = "Must enter the Name!"; } else { $name = test_input($_POST["name"]); if (!preg_match("/^[a-zA-Z ]*$/",$name)) { $nameErr = "Only letters and white space allowed"; } } if (empty($_POST["email"])) { $emailErr = "Must enter the name Email!"; } else { $email = test_input($_POST["email"]); if (!filter_var($email, FILTER_VALIDATE_EMAIL)) { $emailErr = "Invalid email format"; } } if (empty($_POST["comment"])) { $commentErr = "Must enter the name comment"; } else { $comment = test_input($_POST["comment"]); if (!preg_match("/^[a-zA-Z ]*$/",$comment)) { $commentErr = "Only letters and white space allowed"; } } if ($titleErr=="" AND $nameErr=="" AND $emailErr=="" AND $commentErr=="") { $to = "@ my mail"; $from = $_POST['email']; $title = $_POST['title']; $name = $_POST['name']; $subject = "Info from"; $subject2 = "Copy of your form submission"; $comment = $title . " " . $name . " " . "\n\n" . $_POST['comment']; $comment2 = "Here is a copy of your comment " . $name . "\n\n" . $_POST['comment']; $headers = "From:" . $from; $headers2 = "From:" . $to; mail($to,$subject,$comment,$headers); mail($from,$subject2,$comment2,$headers2); header("Location: thanks.html"); } } function test_input($data) { $data = trim($data); $data = stripslashes($data); $data = htmlspecialchars($data); return $data; } ?>[/php]
[sup]
Write us what you need to know * required field. Title: <select name="title">
<option value="0"> choose </option>
<option value="1"> Mr </option>
<option value="1"> Mrs </option>
<option value="1"> Ms </option>
<option value="1"> Miss </option>
</select>
<br><br>
Name: <input type="text" name="name" size="30" value="<?php echo $name;?>">
<span class="error"><big> * </big> <?php echo $nameErr;?></span><span id="example"> / First Name and Last Name / </span>
<br><br>
E-mail: <input type="text" name="email" size="40" value="<?php echo $email;?>">
<span class="error"><big> * </big> <?php echo $emailErr;?></span>
<br><br>
Comment:<span class="error" style="position:relative; top:2px;"><big> * </big></span>
<br><br>
<textarea name="comment" rows="7" cols="55"> <?php echo $comment;?></textarea>
<span class="error"><?php echo $commentErr;?></span>
<br>
<p class="navod"> Turn the picture into the correct position ! </p>
<div id = "rocaptcha_placeholder" ></div>
<script type = "text/javascript" src = "http://rocaptcha.com/api/js/?key=... my key ..." ></script>
<script type = "text/javascript" >
RoCaptcha . init ( "rocaptcha_placeholder" );
</script>
<br>
<input type="submit" name="submit" value="Submit" id="send">
</fieldset>
[/sup]
Thank you to all for your help