PHP form requiring code entry

Is anyone familair with a php form script that generates a
random letter/number combo? I don't know officially what that is
called but I have seen it on sites where you have to enter a code
to submit.

Captcha

Similar Messages

  • PHP Form - Required Fields

    I've got my form working great thanks to Joe and David (and
    others) in
    this group.
    I want to take it a step further by requiring three fields to
    be filled
    out. So I found this code to use in my thankyou2.php page:
    if (!($frmName && $frmemail && $frmphone))
    {echo "You must complete the
    form to send it"; } else {
    I *thought* that if I used it prior to the code that
    processes the rest
    of the page, and sends the admin e-mail, all would be swell.
    However,
    all I get is a blank page.
    I'm almost thinking now that maybe the code needs to go on my
    contact.php page rather than the thankyou.php page? That way,
    the error
    message could appear right on the contact page itself?
    I'm fairly new to this PHP stuff, so go easy
    www.paramount-const.com/contact.txt
    www.paramount-const.com/thankyou2.txt
    Dave

    sorry:
    header('Location:thankyoupage.php'.?name=$_POST['name']);
    should read:
    header('Location:thankyoupage.php?name='.$_POST['name']);
    i misplaced the dot and quote...
    (_seb_) wrote:
    > Dave Anderson wrote:
    >
    >> Shane H wrote:
    >>
    >>>
    http://www.geekministry.com/blog_article.php?id=40
    >>>
    >>> Kim provides an easy way to validate the form
    and also a field for
    >>> stopping spam (I use it on my website, works
    very well!) - all in PHP.
    >>>
    >>
    >>
    >> Shane, good catch! Here method is so simple...
    >>
    >> I installed it, but have a few PHP questions.
    >>
    >> Source:
    >> www.paramount-const.com/html/contact2.txt
    >> www.paramount-const.com/html/thankyou2.txt
    >>
    >> Live form:
    >>
    http://www.paramount-const.com/html/contact.php
    >>
    >> 1) Biggest issue:
    >> If the form is incorrectly filled out, the error
    messages are
    >> displayed at the top of the page. I'm not clever
    enough to figure out
    >> how to display the error message in the fieldset. I
    tried putting the
    >> php block of code in the fieldset, but it doesn't
    seem to matter.
    >> Maybe I can position it with CSS? or is there a
    different way?
    >>
    >> 2) Nice to do but not imperative:
    >> If the form is filled out properly, it redirects to
    my thankyou page.
    >> I would like to personalize the thank you if
    possible. I know there's
    >> a way to customize that page with a name variable,
    but I can't get it
    >> to work. I think what's happening is that I need to
    somehow pass a
    >> variable from the contact page to the thankyou page.
    I have this at
    >> the moment in my thankyou page:
    >>
    >> <?php echo 'Thank you,
    '.htmlentities($_POST['name']).'.'; ?>
    >>
    >> Thanks.
    >>
    >> Dave
    >
    >
    > when you click on the submit button of the form,
    basically the page
    > reloads, this time with all the info from the form, as
    $_POST info.
    > If all this info is correct, you redirect to the thank
    you page.
    > You need to pass some of the info to the thank you page
    (for example to
    > echo the name of the person who just applied).
    > SO, when the form is published and the page reloads, you
    need to store
    > this info, and pass it to the thankyou page.
    >
    > here's we go, scematically:
    >
    > <?php
    > if [form submitted]...
    > $name = [submitted name from form field];
    > [if everything in the form is correct and we redirect to
    thankyou
    > page:]
    >
    header('Location:thankyoupage.php'.?name=$_POST['name']);
    > }
    > ?>
    >
    > Then in thankyou page,
    >
    > $name = $_GET['name'];
    > echo $name;
    >
    >
    seb ( [email protected])
    http://webtrans1.com | high-end web
    design
    Downloads: Slide Show, Directory Browser, Mailing List

  • PHP forms & required fields

    i'm creating an inquiry form for a client hosting w/godaddy.
    Site is in DW using godaddy's php form mail script. script
    works fine for sending formmail.
    Is it possible to validate form fields in php? the customer
    wants to have the first name, email address, etc. being a required
    field or the form will not submit. godaddy support is clueless,
    they e-mailed a kb article on changing the form e-mail address as a
    solution.
    can anyone provide insight? thanx in advance!

    Sure it is. It's even possible to do it in javascript before
    the form gets
    submitted.
    Which DW are you using?
    Murray --- ICQ 71997575
    Adobe Community Expert
    (If you *MUST* email me, don't LAUGH when you do so!)
    ==================
    http://www.projectseven.com/go
    - DW FAQs, Tutorials & Resources
    http://www.dwfaq.com - DW FAQs,
    Tutorials & Resources
    ==================
    "donna_d" <[email protected]> wrote in
    message
    news:fn8468$r4n$[email protected]..
    > i'm creating an inquiry form for a client hosting
    w/godaddy.
    > Site is in DW using godaddy's php form mail script.
    script works fine for
    > sending formmail.
    >
    > Is it possible to validate form fields in php? the
    customer wants to have
    > the
    > first name, email address, etc. being a required field
    or the form will
    > not
    > submit. godaddy support is clueless, they e-mailed a kb
    article on
    > changing
    > the form e-mail address as a solution.
    >
    > can anyone provide insight? thanx in advance!
    >

  • Re: PHP Form - Required Fields

    Change this section of code:
    if(!count($Errors)) {
    $SendTo = "[email protected]";
    $Subject = "New Contact Form";
    $FromString = "From: ".$_POST['eaddress']."\r\n";
    $Indhold = "Dave, Someone filled out the contact form on the
    web site.
    Here is the information:\r\n\r\n";
    $Indhold .= "name: ".$_POST['name']."\r\n";
    $Indhold .= "e-mail: ".$_POST['eaddress']."\r\n";
    $Indhold .= "phone: ".$_POST['telefon_nr']."\r\n";
    $Indhold .= "subject: ".$_POST['subject']."\r\n\r\n";
    $Indhold .=
    "comment:\r\n".preg_replace("(\r\n|\r|\n)","\r\n",$_POST['comment'])."\r\n";
    $MailSuccess = mail($SendTo,$Subject,$Indhold,$FromString);
    header("Location: thankyou2.php");
    exit;***************************
    To this:
    if(!count($Errors)) {
    $SendTo = "[email protected]";
    $Subject = "New Contact Form";
    $FromString = "From: ".$_POST['eaddress']."\r\n";
    $Indhold = "Dave, Someone filled out the contact form on the
    web site.
    Here is the information:\r\n\r\n";
    $Indhold .= "name: ".$_POST['name']."\r\n";
    $Indhold .= "e-mail: ".$_POST['eaddress']."\r\n";
    $Indhold .= "phone: ".$_POST['telefon_nr']."\r\n";
    $Indhold .= "subject: ".$_POST['subject']."\r\n\r\n";
    $Indhold .=
    "comment:\r\n".preg_replace("(\r\n|\r|\n)","\r\n",$_POST['comment'])."\r\n";
    $name = [submitted name from form field];
    $MailSuccess = mail($SendTo,$Subject,$Indhold,$FromString);
    header('Location:thankyoupage.php?name='.$_POST['name']);
    exit;***************************
    That part of the code that I pasted above it creating those
    strings ONLY IF
    there are no errors, so you can just add in seb's code there.
    HTH, take care.
    Shane H
    [email protected]
    http://www.avenuedesigners.com
    =============================================
    Proud GAWDS Member
    http://www.gawds.org/showmember.php?memberid=1495
    Delivering accessible websites to all ...
    =============================================

    Ah - see now I put the formatting how I'd *like* the user to
    input it.
    Because I work with anyone in any loaction, naturally the
    format would be
    different.
    For my contact.php page - the "phone" field isn't a
    requirement, but for my
    quote.php it is a requirement and I just validate it just to
    make sure there
    is SOMETHING in the text field. Not the best way, but I trust
    a true future
    client will provide their phone number.
    Take care Dave, glad I could be of help.
    Shane H
    [email protected]
    http://www.avenuedesigners.com
    =============================================
    Proud GAWDS Member
    http://www.gawds.org/showmember.php?memberid=1495
    Delivering accessible websites to all ...
    =============================================
    "Dave Anderson" <[email protected]> wrote in
    message
    news:e68vpc$da9$[email protected]..
    > Shane H wrote:
    >> Dave -
    >>
    >> I've tweaked your code and got it working for you.
    Here are the pages in
    >> text:
    >>
    >> Source code (contact.php):
    >>
    http://www.avenuedesigners.com/tests/dave_source.html
    >>
    >> Source code (thankyoupage.php):
    >>
    http://www.avenuedesigners.com/tests/dave_thankyou_source.html
    >>
    >> HTH, take care.
    >>
    >
    >
    > Shane,
    >
    > Many thanks! I took a look at what you did to compare to
    what I had. I
    > couldn't tell what was different!? Anyhow, it works
    GREAT.
    >
    > I noticed on your site that you have a specific format
    for the phone
    > number. Would it look something like this?
    >
    > if(!trim($_POST['phone'])) $Errors[] = "Phone";
    >
    > change to this:
    >
    >
    if(!preg_match("/[0-9]{2,4}+-[0-9]{2,4}+-[0-9]{3,5}/",$_POST['telefon_nr']))
    > $Errors[] = "The phone number is typed wrong. (check the
    format)";
    >
    >
    > I tried it and it doesn't seem to care *what* I put in
    (alphanumeric). I'm
    > sure my code is bad, but I don't know what.
    >
    > Thanks for your help Shane!
    >
    > Dave

  • Code issue in php form - submit button not sending email

    Created a form that was originally supposed to open up to 2 pages depending on what was clicked. Clear would send you to an error page, and submit would send you to a thank you page. Decided that was a waste and so did not create the html pages. BUT, wanted the form info for the contact page.
    Here is the issue: it will not submit when submit is clicked. It clears when you click clear, but there's no email coming from the site via submit.
    Do I need to edit the php form code if I don't want the other pages? I've looked at what I have but I don't see if there is a form error or anything here. Here is the code for anyone who wants to have a look. Thanks in advance.
    <?php
    // get posted data into local variables
    $EmailFrom = "EMAIL FROM WEP PAGE - CONTACT - ";
    $EmailTo = "[email protected]";
    $Subject = "EMAIL FROM jennylowhar.com - CONTACT -";
    $name = Trim(stripslashes($_POST['name']));
    $telephone = Trim(stripslashes($_POST['telephone']));
    $email = Trim(stripslashes($_POST['email']));
    $comments = Trim(stripslashes($_POST['comments']));
    // validation
    $validationOK=true;
    if (Trim($name)=="") $validationOK=false;
    if (Trim($email)=="") $validationOK=false;
    if (!$validationOK) {
      print "<meta http-equiv=\"refresh\" content=\"0;URL=error.html\">";
      exit;
    // prepare email body text
    $Body = "";
    $Body .= "name: ";
    $Body .= $name;
    $Body .= "\n";
    $Body .= "telephone: ";
    $Body .= $telephone;
    $Body .= "\n";
    $Body .= "email: ";
    $Body .= $email;
    $Body .= "\n";
    $Body .= "comments: ";
    $Body .= $comments;
    $Body .= "\n";
    // send email
    $success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");
    // redirect to success page
    if ($success){
      print "<meta http-equiv=\"refresh\" content=\"0;URL=thankyou.html\">";
    else{
      print "<meta http-equiv=\"refresh\" content=\"0;URL=error.php\">";
    ?>

    I'm confused by that, but I know this works.
    $fname=STRIPSLASHES($_POST['fname']);
    $lname=STRIPSLASHES($_POST['lname']);
    $title=STRIPSLASHES($_POST['title']);
    $company=STRIPSLASHES($_POST['company']);
    $street=STRIPSLASHES($_POST['street']);
    $town=STRIPSLASHES($_POST['town']);
    $zip=STRIPSLASHES($_POST['zip']);
    $phone=STRIPSLASHES($_POST['phone']);
    $fax=STRIPSLASHES($_POST['fax']);
    $county=STRIPSLASHES($_POST['county']);
    $phone=STRIPSLASHES($_POST['phone']);
    $email=STRIPSLASHES($_POST['email']);
    $comments=STRIPSLASHES($_POST['comments']);
    $date=STRIPSLASHES($_POST['date']);
    $time=STRIPSLASHES($_POST['time']);
    $location=STRIPSLASHES($_POST['location']);
    $from="$email";
    $to="putemailhere";
    $subject="Submission from Contact Form";
    $msg= "This is a submission from yoururl.com.\n\n"
    . "Clients Name: $fname . $lname \n"
    . "Title: $title\n"
    . "Company Name: $company\n"
    . "Street Address: $street\n"
    . "Town:$town\n"
    . "Zip: $zip\n"
    . "Telephone: $phone\n"
    . "Email Address: $email\n"
    . "Comments: $comments\n";
    mail($to, $subject, $msg, 'From:' .$from);
    PS, go back and edit your origial post and REMOVE your email.
    Gary

  • PHP form layout issue

    Hi all, I have a basic php form on a page, it works great,
    and my email recieves the content as required, BUT, when the form
    submits and the page shows the forms content, it throws out my
    layout ocmpletely. My white maincontent dissapears, and the footer
    div is all misaligned, my code is attached. Can anyone help please?
    many thanks

    On Thu, 7 Feb 2008 16:34:22 +0000 (UTC), "simbull"
    <[email protected]> wrote:
    >Thanks for the response gary, I have tried that (and just
    did again), that
    >means the user is not presented with the php output,
    which I do want them to be
    >ideally. Anyhow, that aside, it still throws my layout
    out..?
    Impossible to give you a better answer without knowing what
    you want to
    accomplish, but it sounds like your layout might be too
    fragile.
    Gary

  • Need to add senders email address into the subject header of my PHP form (somehow)

    Hello one and all,
    I have a PHP form which is working fine and sends our support team an email with the subject header 'Support'.
    I have been asked to fix this form to include the senders email address into the Subject header so that the support team can filter them easier and reply quicker.
    Any help would be very much appreciated indeed. The form code is below, let me know if you need the whole page.
    Thanks in advance,
    Bradley
    My current form PHP part looks like this: (and the HTML part is below in blue)
    <?php
        if($_GET["action"] == "email")
            $msg = "The following person need support:\n\n";
            $msg = $msg . "First Name: " . $_POST["FirstName"] . " " . $_POST["LastName"] . "\n";
            $msg = $msg . "Tel: " . $_POST["Tel"] . "\n";
            $msg = $msg . "Email: " . $_POST["FROM"] . "\n";
            $msg = $msg . "Support: " . $_POST["Support"] . "\n";
            $msg = $msg . "Model: " . $_POST["Model"] . "\n";
            $msg = $msg . "Comments: " . $_POST["Comments"] . "\n";
            $to ="[email protected]";
            $subject = "Support";
            $from = "From: " . $_POST["FROM"];
            mail($to, $subject, $msg, $emailFrom, $from);
            header("Location:support2.php");
    ?>
    and the HTML part of the fom is like this:
    <form id="form1" name="form1" method="post" action="support.php?action=email">
      <table width="700" border="0" cellspacing="10" cellpadding="10">
        <tr>
          <td valign="middle" class="formtext">*First name:</td>
          <td width="455" valign="middle"><label>
            <input name="FirstName" type="text" class="form-textbox" id="FirstName" />
          </label></td>
        </tr>
        <tr>
          <td valign="middle" class="formtext">*Last name:</td>
          <td valign="middle"><input name="LastName" type="text" class="form-textbox" id="LastName" /></td>
        </tr>
        <tr>
          <td valign="middle" class="formtext">*Email:</td>
          <td valign="middle"><input name="FROM" type="text" class="form-textbox" id="FROM" /></td>
        </tr>
        <tr>
          <td valign="middle" class="formtext">*Telephone:</td>
          <td valign="middle"><input name="Tel" type="text" class="form-textbox" id="Tel" /></td>
        </tr>
        <tr>
          <td valign="middle" class="formtext"> </td>
          <td valign="middle"> </td>
        </tr>
        <tr>
          <td valign="middle" class="formtext">*Support required:</td>
          <td valign="middle"><label>
            <select name="Support" class="form-dropdown" id="Support">
              <option selected="selected">Please select...</option>
              <option value="Connection Issues">Connection Issues</option>
              <option value="Technical Issues">Technical Issues</option>
              <option value="Furniture Faults">Furniture Faults</option>
              <option value="Other">Other</option>
            </select>
          </label></td>
        </tr>
        <tr>
          <td valign="middle" class="formtext">Chair model:</td>
          <td valign="middle"><input name="Model" type="text" class="form-textbox" id="Model" /></td>
        </tr>
        <tr>
          <td valign="middle" class="formtext">*Please describe your issue:</td>
          <td valign="middle"><textarea name="Comments" rows="5" class="form-textarea" id="Comments"></textarea></td>
        </tr>
        <tr>
          <td valign="middle" class="maintext"> </td>
          <td valign="middle" class="maintext"></td>
        </tr>
        <tr>
          <td valign="middle"> </td>
          <td valign="middle"><label>
            <input name="Submit" type="submit" class="form-submit-button" value="Submit" />
          </label></td>
        </tr>
      </table>
      </form>

    MurraySummers you sir, are an absolute legend! This worked perfect straight off the bat!
    I really apreciate your lightning fast reply!
    Thanks again.
    Bradley

  • Php form processing script

    Hi. I got a program to write a php form processing script. My submit form is for photo submission to my domain email. I published to site and did a test to see if it works i got this error:
    Warning: require_once(F:\Domains\mydomain\mydomain.com\wwwroot/includes/Upload_Photos-lib.php): failed to open stream: No such file or directory in F:\Domains\mydomain\mydomain.com\wwwroot\Upload_Photos.php on line 24 Fatal error: require_once(): Failed opening required 'F:\Domains\mydomain\mydomain.com\wwwroot/includes/Upload_Photos-lib.php' (include_path='.;C:\php\pear') in F:\Domains\mydomain\mydomain.com\wwwroot\Upload_Photos.php on line 24
    What does this mean? How can i solve this so that i can process my form?

    See if the below form helps: You need to create a folder on your server named - upload - this is where any files uploaded will be stored (make sure the folder is writable. Also change the email address where the information that someone who has uploaded a file will go to. Look for the following in the code: $to ="XXXXXXXXXXXX.com";
    <!DOCTYPE html>
    <head>
    <meta charset="UTF-8" />
    <title>Untitled Document</title>
    <style type="text/css">
    #wrapper {
    width: 400px;
    margin: 0 auto;
    </style>
    </head>
    <body>
    <div id="wrapper">
    <?php if(isset($_POST['submit'])) {
    $name = trim($_POST['name']);
    if(empty($name)) {
    $error['name'] = "Please provide your name";
    $location = trim($_POST['location']);
    if(empty($location)) {
    $error['location'] = "Please provide your location";
    $email = trim($_POST['email']);
    if(empty($email)) {
    $error['email'] = "Please provide your email";
    $category_description = trim($_POST['category_description']);
    if(empty($category_description)) {
    $error['category_description'] = "Please provide the category or description";
    $terms_conditions = trim($_POST['terms_conditions']);
    if(empty($terms_conditions)) {
    $error['terms_conditions'] = "Please accept the terms & conditions";
    $allowedExts = array(
       "doc",
      "docx",
            "rtf",
            "txt",
            "pdf",
            "jpeg",
            "jpg",
    $allowedMimeTypes = array(
      'application/msword',
            'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
            'application/rtf',
            'application/x-rtf',
            'text/richtext',
            'text/rtf',
            'application/plain',
      'application/pdf',
      'image/gif',
      'image/jpeg',
    $extension = end(explode(".", $_FILES["file"]["name"]));
    if (empty($_FILES["file"]["name"])) {
        $selectFile = 'Please select a file to upload';
    elseif ( ! ( in_array($extension, $allowedExts ) ) ) {
      $fileTypeNotAllowed = 'File type not allowed';
    elseif ($_FILES["file"]["size"] > 2097152) {
      $fileTooLarge = 'Please provide a smaller file';
    elseif (file_exists("upload/" . $_FILES["file"]["name"])) {
    $fileExists = $_FILES["file"]["name"] . " already exists, Please change the file name ";
    elseif (in_array( $_FILES["file"]["type"], $allowedMimeTypes ) )
        if(!empty($_POST['terms_conditions'])) {
    move_uploaded_file($_FILES["file"]["tmp_name"], "upload/" . $_FILES["file"]["name"]);
        $fileName = $_FILES["file"]["name"];
        $fileUploadSuccessful = 'File uploaded successfully';
    $to = "XXXXXXXXXXXXX.com";
    $subject   = "Upload to website";
    $headers  = "From: $email\r\n";
    $headers .= "Reply-To: $email\r\n";
    $message = "Name: $name\n\n";
    $message .= "Location: $location\n\n";
    $message .= "Email Address: $email\n\n";
    $message .= "Category/Description: $category_description\n\n";
    $message .= "File: $fileName\n\n";
    mail($to, $subject, $message, $headers);
    $sent = "Mail was sent successfully";
    ?>
    <h1>Form</h1>
    <?php
    foreach ($error as $value) {
        echo "<p>".$value."</p>";
    if(isset($formFieldError)) {
    echo "<p>".$formFieldError."</p>";
    if(isset($selectFile)) {
    echo "<p>".$selectFile."</p>";
    if(isset($fileTypeNotAllowed)) {
    echo "<p>".$fileTypeNotAllowed."</p>";
    if(isset($fileTooLarge)) {
    echo "<p>".$fileTooLarge."</p>";
    if(isset($fileExists)) {
    echo "<p>".$fileExists."</p>";
    if(isset($fileUploadSuccessful)) {
    echo "<p>".$fileUploadSuccessful."</p>";
    ?>
    <form action="upload_file.php" method="post"
    enctype="multipart/form-data">
    <p>
    <label for="name">Name<br>
    <input type="text" name="name" id="name" value="<?php if(isset($name)) {echo $name; }  ?>"/>
    </label>
    </p>
    <p>
    <label for="location">Location<br>
    <input type="text" name="location" id="location" value="<?php if(isset($location)) {echo $location; }  ?>"/>
    </label>
    </p>
    <p>
    <label for="email">Email<br>
    <input type="text" name="email" id="email" value="<?php if(isset($email)) {echo $email; }  ?>" />
    </label>
    </p>
    <p>
    <label for="category_description">Category and Description<br>
    <input type="text" name="category_description" id="category_description" value="<?php if(isset($category_description)) {echo $category_description; }  ?>" />
    </label>
    </p>
    <p>
    <label for="file">File Attachment:<br>
    <input type="file" name="file" id="file" />
    </label>
    </p>
    <p>
    <label for="terms_conditions">Terms & Conditions:
    <input name="terms_conditions" type="checkbox" value="accept" <?php if(isset($_POST['terms_conditions'])) {echo "checked"; }  ?>> (Please check)
    </label>
    </p>
    <input type="submit" name="submit" value="Submit" />
    </form>
    </div>
    </body>
    </html>

  • PHP form strange behaviors

    I have a very basic PHP form coded and whenever I look at it in Live View the bottom third of the processing code appears at the top of the webpage. Uploaded the code does not appear on the webpage and the form works fine, except that the dropdown initial values I have set are ignored.
    The form URL:  http://affordableroofingcontractors.com/contact-us.php
    The dropdown code: (I want "select one" displayed but the form shows "Re-roofing" instead!?)
    <select name="service" id="service">
                <option value="0" selected="selected"
                <?php if (!$_POST ||$_POST['service'] =='0') {
        echo 'selected="selected"'; }?>>--select one--</option>
                <option value="Proactive Roof Maintenance"
                <?php if (!$_POST ||$_POST['service'] =='Proactive Roof Maintenance') {
        echo 'selected="selected"'; }?>>Proactive Roof Maintenance</option>
                <option value="Roof Repairs"
                 <?php if (!$_POST ||$_POST['service'] =='Roof Repairs') {
        echo 'selected="selected"'; }?>>Roof Repairs</option>
                <option value="Re-roofing"
                 <?php if (!$_POST ||$_POST['service'] =='Re-roofing') {
        echo 'selected="selected"'; }?>>Re-roofing</option>
              </select>
    The processing code:
    <?php
    if (array_key_exists('submit', $_POST)){
    //mail processing script
    // remove escape characters from POST array
    if (PHP_VERSION < 6 && get_magic_quotes_gpc()) {
      function stripslashes_deep($value) {
        $value = is_array($value) ? array_map('stripslashes_deep', $value) : stripslashes($value);
        return $value;
      $_POST = array_map('stripslashes_deep', $_POST);
    if (!empty($_POST['area'])) {
      $to = '[email protected]';
      $subject = 'SUSPECTED BOT SUBMISSION from ACI quote form';
    } else {
    $to = '[email protected]';
    $subject = 'ACI CONTACT FORM';
    //list expected fields
    $expected = array('name','company','phone','email','service','building','comments');
    //set required fields
    $required = array('name','email','phone');
    //create empty array for any missing fields
    $missing = array();
    //assume there is nothing suspect
    $suspect = false;
    //create a pattern to locate suspect phrases
    $pattern = '/Content-Type:|Bcc:|Cc:/i';
       // function to check for suspect phrases
      function isSuspect($val, $pattern, &$suspect) {
      // if the variable is an array, loop through each element and pass it recursively back to the same function
    if (is_array($val)) {
          foreach ($val as $item) {
         isSuspect($item, $pattern, $suspect);
        else {
          // if one of the suspect phrases is found, set Boolean to true
       if (preg_match($pattern, $val)) {
            $suspect = true;
    //check the Post array and any subarrays for suspect content
    isSuspect($_POST, $pattern, $suspect);
    if ($suspect) {
    $mailSent = false;
    unset($missing);
    } else {
    //process POST variables
    foreach ($_POST as $key => $value){
    //assign to temporary variable and strip whitespace if not an array
    $temp = is_array($value) ? $value : trim($value);
    //if empty and required, add to $missing array
    if (empty($temp) && in_array($key, $required)) {
      array_push($missing, $key);
    } elseif (in_array($key, $expected)) {
    //otherwise, assign to a variable of the same name as $key
      ${$key} = $temp;
    //validate the email address
    if (!empty($email)) {
    // regex to identify illegal characters in email address
    $checkEmail = '/^[^@]+@[^\s\r\n\'";,@%]+$/';
    //reject the email address if it doesn't match
    if (!preg_match($checkEmail, $email)){
      $suspect = true;
      $mailSent = false;
      unset($missing);
    //go ahead only if not suspect and all required fields OK
    if (!$suspect && empty($missing)) {
    //build the message
    $message = "Name: $name\r\n\r\n";
    $message .= "Company: $company\r\n\r\n";
    $message .= "Phone: $phone\r\n\r\n";
    $message .= "Email: $email\r\n\r\n";
    $message .= "Service Needed: $service\r\n\r\n";
    $message .= "Type of Building: $building\r\n\r\n";
    $message .= "Comments: $comments";
    //limit line length to 70 characters
    $message = wordwrap($message, 70);
    //create additional headers
    $headers = "From: $email>\r\n";
    $headers .= 'Content-Type: text/plain; charset=utf-8';
    if (!empty($email)) {
      $headers .= "\r\nReply-To: $email";
    //send it
    $mailSent = mail($to, $subject, $message, $headers);
    if ($mailSent) {
    //$missing is no longer needed if email is sent, so unset it
    unset($missing);
    ?>

    Hi!
    To select php form you should create a  menu,  fill out the type of "choice of one item of many" or "Select multiple  items from the many." Must be inside FORM element and have at the start  or end tags. It contains several elements OPTION, otherwise it makes no  sense.
    Example:
    <HTML> <body>
    <form method='post' action='all.php'>
         Color Scheme: <br>
        <SELECT NAME="color">
          <OPTION VALUE="Standard" SELECTED> </ OPTION>
          <OPTION VALUE='Brick'> Brick </ OPTION>
          <OPTION VALUE='Gray Mouse'> Gray Mouse </ OPTION>
          <OPTION VALUE='Ship Bottom'> Ship Bottom </ OPTION>
          <OPTION VALUE='Black Night'> Black Night </ OPTION>
          <OPTION VALUE='White Light'> White Light </ OPTION>
          <OPTION VALUE='Yellow List'> Yellow List </ OPTION>
          <OPTION VALUE='Pink Myth'> Pink Myth </ OPTION>
          <OPTION VALUE='Green USD'> Green USD </ OPTION>
          <OPTION VALUE='Standard'> Standard </ OPTION>
        </ SELECT>
    <input type='submit' name='submit' value='go'>
    </ form>
    </ body> </ HTML>2

  • PHP form/Captcha alternative

    I have a php form that works fine. In part: <form method="post" action="sendmail.php">
    Now, to add some security to it I created a required field: What is 6 plus 6? A bot can't fill in 12, right? So then the form doesn't go to the sendmail.php file. Is there some reason this won't work? It seems so absurdly simple.

    So then the form doesn't go to the sendmail.php file. Is there some reason this won't work? It seems so absurdly simple.
    Hard to comment without seeing the code.
    Please paste the entire page code (HTML and PHP) here so we can see how it's coded..

  • PHP Form Validation and Radio Group

    Hi David,
    I'm trying to set the initial state of a radio group to none.
    Please look at the file http://ecopethandbags.com/contact.php. The initial state is set to "No"
    In Dreamweaver, I've set the initial state to "Unchecked"
    I don't understand the code for the radio buttons in my file (see attachment).
    What I am trying to do is to have the radio group initially unchecked but required.
    I have 2 questions:
    1) - How can I control the initial status of the radio group when I use the PHP form validation?
    2) - How can I set the validation so, when one of the radio buttons is not checked by the user, a warning flag like "Please make a choice" comes up.
    Thank you much!

    Just change the following section of code:
    <?php
    if (!$_POST || isset($missing) && $_POST['subscribe'] == 'n') {
      echo 'checked="checked"';
    } ?>
    Remove the !$_POST || like this:
    <?php
    if (isset($missing) && $_POST['subscribe'] == 'n') {
      echo 'checked="checked"';
    } ?>
    The checked="checked" will be inserted into the code only if the form has been submitted, but neither radio button has been selected.

  • PHP form submission Problem

    Dear all,
    PHP enquiry form submission some error is comes
    "Parse error: syntax error, unexpected T_STRING in /home/newtocli/public_html/en45/send_form_email.php on line 11"
    Please help me
    WEBLINK
    PHP goes like this
    <!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>PHP Form</title>
    </head>
    <body><?php
    if(isset($_POST['email'])) {
        // EDIT THE 2 LINES BELOW AS REQUIRED
        $email_to = "[email protected]";
        $email_subject = "Your email subject line";
        function died($error) {
            // your error code can go here
            echo "We are very sorry, but there were error(s) found with the form you submitted. ";
            echo "These errors appear below.<br /><br />";
            echo $error."<br /><br />";
            echo "Please go back and fix these errors.<br /><br />";
            die();
        // validation expected data exists
        if(!isset($_POST['first_name']) ||
            !isset($_POST['email']) ||
            !isset($_POST['telephone']) ||
                        !isset($_POST['company_name']) ||
            !isset($_POST['comments'])) {
            died('We are sorry, but there appears to be a problem with the form you submitted.');      
        $first_name = $_POST['first_name']; // required
        $email_from = $_POST['email']; // required
        $telephone = $_POST['telephone']; // not required
              $last_name = $_POST['company_name']; // required
        $comments = $_POST['comments']; // required
        $error_message = "";
        $email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
      if(!preg_match($email_exp,$email_from)) {
        $error_message .= 'The Email Address you entered does not appear to be valid.<br />';
        $string_exp = "/^[A-Za-z .'-]+$/";
      if(!preg_match($string_exp,$first_name)) {
        $error_message .= 'The First Name you entered does not appear to be valid.<br />';
      if(!preg_match($string_exp,$company_name)) {
        $error_message .= 'The Last Name you entered does not appear to be valid.<br />';
      if(strlen($comments) < 2) {
        $error_message .= 'The Comments you entered do not appear to be valid.<br />';
      if(strlen($error_message) > 0) {
        died($error_message);
        $email_message = "Form details below.\n\n";
        function clean_string($string) {
          $bad = array("content-type","bcc:","to:","cc:","href");
          return str_replace($bad,"",$string);
        $email_message .= "First Name: ".clean_string($first_name)."\n";
        $email_message .= "Email: ".clean_string($email_from)."\n";
        $email_message .= "Telephone: ".clean_string($telephone)."\n";
              $email_message .= "Company Name: ".clean_string($company_name)."\n";
        $email_message .= "Comments: ".clean_string($comments)."\n";
    /* Redirect visitor to the thank you page */
    header('Location:gt.html');
    exit();
    // create email headers
    $headers = 'From: '.$email_from."\r\n".
    'Reply-To: '.$email_from."\r\n" .
    'X-Mailer: PHP/' . phpversion();
    @mail($email_to, $email_subject, $email_message, $headers); 
    ?>
    <!-- include your own success html here -->
    Thank you for contacting us. We will be in touch with you very soon.
    <?php
    ?>
    </body>
    </html>

    some error now
    Parse error: syntax error, unexpected T_STRING in /home/newtocli/public_html/send_form_email.php on line 5
    My form like this
    <form name="contactform" method="post" action="send_form_email.php">
                                                                                                                                                <div class="field text">
                                                            <input  type="text" name="first_name" maxlength="50" size="30" value="Name*:">
                                                            </div>
                                                                                                                                                <div class="field text">
                                                            <input  type="text" name="email" maxlength="80" size="30" value="E-mail*:">
                                                           </div>
                                                                          <div class="clear"><!-- --></div>
                                                                                                                                                <div class="field text">
                                                            <input  type="text" name="telephone" maxlength="30" size="30" value="Phone.:">
                                                            </div>
                                                                                                                                                <div class="field text">
                                                            <input  type="text" name="company_name" maxlength="50" size="30" value="Company:">
                                                            </div>
                                                                          <div class="clear"><!-- --></div>
                                                                          <div class="field textarea"><div>
                                                                            <textarea  name="comments"></textarea>
                                </div></div>
                                                                          <div class="submit">
                                                                                    <p>* - Required fields</p>
                                                                                    <input type="submit" value="Send" />
                                                                          </div>
                                                                </form>

  • Need help with PHP form with checkboxes, radio buttons and file attachment

    Hi guys,
    I'm having a nightmare with this PHP form where a user can fill it in, attach a doc/pdf and submit. After trying to sort it out with previous code I've used, I've stripped it out and think I should just start again in the hope you geniuses can help!
    Here is the HTML of contact.php:
    <form action="" method="post" name="contact" id="contact">
        <p>Job Title:*<br />
        <input name="position" type="text" /></p>
        <p>Nationality:*<br />
        <select name="nationality">
          <option value="">-- select one --</option>
          <option value="Afghan">Afghan</option>
          <option value="Albanian">Albanian</option>
          <option value="Algerian">Algerian</option>
          <option value="Zambian">Zambian</option>
          <option value="Zimbabwean">Zimbabwean</option>
        </select>
        </p>
        <p>Which country are you currently living in?*<br />
        <select name="country">
        <option value="">-- select one --</option>
        <option value="United Kingdom">United Kingdom</option>
        <option value="Afghanistan">Afghanistan</option>
        <option value="Africa">Africa</option>
        <option value="Zambia">Zambia</option>
        <option value="Zimbabwe">Zimbabwe</option>
        </select>
        </p>
        <label class="radio" for="checkRight">Yes/No question?</label><br />
        <input class="radio" type="radio" name="right" value="Yes" /> Yes
        <input class="radio" type="radio" name="right" value="No" /> No
        <input class="radio" type="radio" name="right" value="N/A" /> Not applicable
        <p>Yes/No question?<br />
        <select name="continue">
        <option value="">-- select one --</option>
        <option value="Yes">Yes</option>
        <option value="No">No</option>
        </select>
        </p>
        <p>Select your resorts:<br />
        Resort 1<input name="res1" type="checkbox" value="Resort 1" />
        Resort 2<input name="res2" type="checkbox" value="Resort 2" />
        Resort 3<input name="res3" type="checkbox" value="Resort 3" />
        Resort 4<input name="res4" type="checkbox" value="Resort 4" />
        Resort 5<input name="res5" type="checkbox" value="Resort 5" />
        Resort 6<input name="res6" type="checkbox" value="Resort 6" />   
        </p>
        <p>Don't send form unless this is checked:* <input type="checkbox" name="parttime" value="Yes" /></p>
        <p>Date of arrival: <input name="arrive" id="datepick" /><br />
        Date of departure: <input name="depart" id="datepick2" /></p>
        <script type="text/javascript" src="assets/scripts/datepickr/datepickr.js"></script>
        <link href="assets/scripts/datepickr/datepickr.css" rel="stylesheet">
        <script type="text/javascript">
        new datepickr('datepick');
        new datepickr('datepick2', {
        </script>
        <p>Name:*<br />
        <input name="name" type="text" /></p>
        <p>E-mail:*<br />
        <input name="email" type="text" /></p>
        <p>Telephone:*<br />
        <input name="telephone" type="text" class="ctextField" /></p>
        <p>Upload CV (Word of PDF formats only):<br />
        <input type="file" name="cv" class="textfield"></p>
        <p><input name="submit" value="Submit Enquiry" class="submitButton" type="submit" /><div style="visibility:hidden; width:1px; height:1px"><input name="url" type="text" size="45" id="url" /></div></p>
    </form>
    By the way, the date boxes work so excuse the Javascript in there!
    To prevent SPAM I've used a trick where there's a hidden URL field which must be left blank for the form to submit which you can see in the PHP.
    Below is where I'm at with the PHP which is placed above the header of contact.php...
    <?php
    if (array_key_exists('submit', $_POST)) {
        $position = $_POST['position'];
        $arrive = $_POST['arrive'];
        $nationality = $_POST['nationality'];
        $parttime = $_POST['parttime'];
        $depart = $_POST['depart'];
        $name = $_POST['name'];
        $email = $_POST['email'];
        $telephone = $_POST['telephone'];
    $to = "[email protected]";
    $subject = "Recruitment Application";
    $message = $headers;
    $message .= "Name: " . $_POST["name"] . "\r\n";
    $message .= "E-mail: " . $_POST["email"] . "\r\n";
    $headers  = "MIME-Version: 1.0\r\n";
    $headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
    $headers .= "Reply-To: " . $_POST["email"] . "\r\n";
    $headers .= 'From: My Website <[email protected]>' . "\r\n";
    $message= "
    $url = stripslashes($_POST["url"]);
    if (!empty($url)) {
    header( 'Location: http://www.go-away-spam-robots.com' );
    exit();
    if (!isset($warning)) {
    mail($to, $subject, $message, $headers);
    header( 'Location: http://www.mywebsite.co.uk/sent.php' );
    ?>
    I would like to make pretty much all the field compulsory so if a field is left empty (other than the hidden URL field), a warning message is displayed next to that field.
    Also I would like the file upload field to attach to the email that is sent to me and have the results come through to me in a table format.
    Can anyone help me get my form working?
    Thank you and I hope to hear from you!
    SM

    Hi Nancy,
    Great stuff, thank you for the reply.
    I've managed to get the Formm@iler working and running as I need it to.
    The only thing I'm struggling with is when the user clicks submit, they are taken to a page of whatever results the form returned but it is just a white background with Times New Roman text.
    How can I have it so the user is taken to the form results in the websites' page layout?
    I tried sending them to a generic 'thank you' page by adding the following code but it just took them there whatever the results of the form so that's no good...! I have a feeling it's a bit more complicated than that...
    header( 'Location: http://www.nofussbus.co.uk/test/sent.php' );
    Thank you for your help!

  • Can you auto-attach files in a PHP form?

    Hi there,
    Have been looking over everywhere for a solution to my problem. I am going to try and be as clear as I can about the problem.
    I have had some experience making simple PHP forms that let the user put their name, email, subject and body text and send it in an email using the form.
    But for a project I am currently undertaking - the client has requested a form that will pre-attach a particular document to the email when it is sent. All the user has to do is input the email address of the adressee and their name/email address and all the other fields are custom made (i.e. subject, body text) - and the email will be sent to the selected recepient with the file already attached.
    I was envisaging the PHP script would collect the reference for a file that is already sitting on the web server and attach it in the function.
    Is there anyway to do this? Because if it isn't I may as well tell the client to go and use outlook - because the web form will really have no purpose.
    Thanks in advance

    Hi have proceeded along the path of inserting links
    into PHP generated email but I am having trouble in outputting the body message in HTML - All I get out
    in the output email is the HTML tags with the text (plain text).
    Did some research and found out that I have to determine the content type/charset.
    I have tried to do this in my PHP but to no avail. Also I am not getting the email or name of the sender in the email that is generated....
    Anyway, there is the PHP code (and it's not that tight but it works):
    AND SOME DEFAULT TEXT THAT WILL CONTAIN LINKS TO NECESSARY FILES TO DOWNLOAD:
    link to PDF '.$field_message; $headers = 'From: '.$cf_yremail."\r\n"; $headers .= 'Reply-To: '.$cf_yremail."\r\n"; /* If your e-mail is not valid show error message */ if (!preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/", $mail_to)) { ?>
    Any help on this would be much appreciated....
    Thanks

  • Php form problem and question

    I am a new web designer who is not code savey yet. Anyway
    during the various sites i have designed i have used 3 different
    forms that process and email it to me using a seperate php form, 1
    in flash, 2 from a standard html form on a windows server. All have
    been uploaded, to the site, tested and worked fine. 2 are in old
    sites, one in my current site. Recently all 3 forms stopped working
    and while they looked like they worked fine they no longer actually
    sent anything. I had a big email arguement with my host and finally
    they added this line into my php script "ini_set
    ("sendmail_from","[email protected]");" email address is example here
    and they added another form to my site called "php4-cgi-fcgi.ini."
    Then my curent form started working again. I haven't changed
    anything, and of course the host never informed me of any changes.
    So why did this need to be added for my form to work again? Does
    this mean they upgraded to another version or something? Ihad a big
    arguement with them because they refused to tell me what they did
    that stopped all my forms from working, they kept acting like it
    was me or my provider that caused the problem, when i am positive
    we were not the problem. Any thoughts?

    doing a google on "ini_set ("sendmail_from" gives a lot of
    info.
    summary- the form script you are using is probably not
    setting a default
    "FROM" email address, so the host has phpmail() reject it as
    possible spam
    abuse.
    The .ini files the host added to your site correct the
    problem. They change
    values for php to use within your hosting domain.
    What php script are you using to send the emails? It is
    probably out of date
    if it doesn't address this issue.
    Off Topic: suggest never arguing with hosting support. Even
    it the person at
    the other end of the phone is an 18 year old drone not
    earning their salt.
    Move the site if needed. Develop social engineering skills to
    get things
    done.
    Alan
    Adobe Community Expert, dreamweaver
    http://www.adobe.com/communities/experts/

Maybe you are looking for

  • HT4152 replace video card

    Hi, I'm 99% sure my video card needs to be replaced. When I try to turn the machine on, you hear it boot up, but the screen won't come on. I tried a couple of reset options I find online, but that didn't work. I hooked it up to a monitor and the scre

  • Windows 7 refuses to install on HD

    HiReinstalling win 7 on a replacement hd (Not new but fully operational) I get to part of setup where it wants me to choose partition. I choose part 1 (136.6GB) when click next i get "Setup was unable to create a new system partitionor locate an exis

  • Supplier Registration in EBP

    I have done all settings as per configuration guide for supplier registration in Strategic sourcing scenario. When the supplier regiters himself, His registration entry is visible in the screen suppliers application in Buyers account. Here we can als

  • MAC address of DB or Client machine

    Dear, Can U please tell me how to get MAC address of Database or Client Machine via PL/SQL or routine used in PL/SQL envoirment. Thanks FAHAD AZIZ KHAN

  • Can I reference static class vars via a string?

    Hi all, I am trying to set the value of some static vars but I need to reference the class with a string rather than a proper constructor. In AS3 I can do this with: var ref:Class = getDefinitionByName(classDefinitionAsString) as Class; ref[varNameAs