SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Member
    Join Date
    Mar 2009
    Posts
    21
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Dynamic PHP Form

    Hi I need help with making a dynamic php form. What needs to happen is when a dropdown menu selection is made, the form then is arranged to send the form results to certain email addresses. So if I choose drop down menu selection "blue" "a@a.com b@b.com" receive the submitted form, and if selection "red" "c@c.com d@d.com" receive the form results. I've yet learned to make such dynamic form. Is there a form generator open source app that can help me with this? or can someone help me create this? Thanks

  2. #2
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,578
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    if ($_POST['some_form_element'] == "blue") {
      
    $email_to_send_to "a@a.com";
    } else if (
    $_POST['some_form_element'] == "red") {
      
    $email_to_send_to "c@c.com";

    Just a conditional

  3. #3
    SitePoint Member
    Join Date
    Mar 2009
    Posts
    21
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    would this also work for a cgi form like this one:

    <form action=../../cgi-bin/mailer.cgi method=post name="residential_request" id="residential_request">
    <input name=recipient type=hidden value="a@a.com, b@b.com">
    <input type=hidden
    value="Service Request" name=subject>
    <input type=hidden
    value="problem_category, first_last_name, email, area_code, contact_number, street_address, zip_code, urgency, preferred_date, descr_of_problem, preferred_time"
    name=required>
    <input type=hidden value=email
    name=print_config>
    <input type=hidden
    value=http://www.blabla.com/request/redirect_for_regular.htm
    name=redirect>
    <input type=hidden
    value=http://www.blabla.com/request/redirect_for_emergency.htm
    name=redirect_emer>
    <br>
    <table width="300" border="0" align="center" cellpadding="5" cellspacing="0" bgcolor="#FFFFFF">
    <tr bgcolor="#FFFFFF" class="readingtextbold">
    <td><div align="right"><span class="readingtextbold"> </span><span class="captionred">
    <select name="problem_category" size=1 id="select6">
    <option selected>Problem Category/option>
    <option value="AIR CONDITIONING">
    AIR CONDITIONING </option>
    <option value="ELECTRICAL">
    ELECTRICAL </option>
    <option value="PLUMBING">PLUMBING</option>
    <option value="Priority One">Priority One</option>
    </select>
    </span></div></td>
    <td>&nbsp;</td>
    <td>First, Last Name
    <input size=42 name=first_last_name></td>
    </tr>
    <tr bgcolor="#FFFFFF" class="readingtextbold">
    <td width="317"> <div align="right">Email Address
    <input size=40 name=email>
    </div></td>
    <td width="47">&nbsp; </td>
    <td width="356">Phone: <br> <input size=5 name=area_code>
    <input size=20 name=contact_number> </td>
    </tr>
    <tr bgcolor="#FFFFFF" class="readingtextbold">
    <td height="48" align=right> <div align="right"> Street
    Address
    <input size=42 name=street_address>
    </div></td>
    <td>&nbsp; </td>
    <td>Zip Code<br> <input size=10 name=zip_code></td>
    </tr>
    <tr bgcolor="#FFFFFF" class="readingtextbold">
    <td> <div align="right">
    <select size=1 name="urgency">
    <option selected>Choose Your Urgency </option>
    <option value="This is not urgent">This is not urgent
    </option>
    <option value="This is urgent">This is urgent </option>
    </select>
    </div></td>
    <td>&nbsp; </td>
    <td>Preferred Service Date (mm/dd/yy)
    <input size=42 name=preferred_date> </td>
    </tr>
    <tr bgcolor="#FFFFFF" class="readingtextbold">
    <td> <div align="right">Description of Problem<br>
    <textarea name=descr_of_problem cols=30 rows=7 id="textarea5"></textarea>
    </div></td>
    <td>&nbsp; </td>
    <td valign="top"><p>
    <select name=preferred_time size=1 id="select2">
    <option selected> Service/option>
    <option value="morning">Morning </option>
    <option value="afternoon">Afternoon</option>
    </select>
    </p>
    <p>&nbsp; </p>
    <p>
    <input type=submit value="Submit Query" name="submit information">
    <input name="reset" type=reset value=Reset>
    </p></td>
    </tr>
    <tr bgcolor="#FFFFFF" class="readingtextbold">
    <td valign="top"> <div align="right"> </div></td>
    <td valign="top">&nbsp; </td>
    <td valign="middle"> <div align="left"> </div></td>
    </tr>
    </table>
    </form>
    Last edited by larrpan; Oct 5, 2009 at 19:37. Reason: privacy

  4. #4
    SitePoint Member
    Join Date
    Mar 2009
    Posts
    21
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    can you recommend me a good php form to use?

  5. #5
    SitePoint Enthusiast
    Join Date
    Jan 2009
    Posts
    73
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Having the email address in the HTML form is not a good idea. The email address will be harvested by spam bots and you will start getting loads of spam messages.

    Use a form mail script that keeps the email address in the script itself(rather than the HTML form) or try writing a php form to email script.

  6. #6
    SitePoint Member
    Join Date
    Mar 2009
    Posts
    21
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That PHP Form to Email looks awesome. One last question, where can I place the code you kindly gave me in this form:

    <?php
    if(!isset($_POST['submit']))
    {
    //This page should not be accessed directly. Need to submit the form.
    echo "error; you need to submit the form!";
    }
    $name = $_POST['name'];
    $visitor_email = $_POST['email'];
    $message = $_POST['message'];

    //Validate first
    if(empty($name)||empty($visitor_email))
    {
    echo "Name and email are mandatory!";
    exit;
    }

    if(IsInjected($visitor_email))
    {
    echo "Bad email value!";
    exit;
    }

    $email_from = 'tom@amazing-designs.com';//<== update the email address
    $email_subject = "New Form submission";
    $email_body = "You have received a new message from the user $name.\n".
    "Here is the message:\n $message".

    $to = "tom@amazing-designs.com";//<== update the email address
    $headers = "From: $email_from \r\n";
    $headers .= "Reply-To: $visitor_email \r\n";
    //Send the email!
    mail($to,$email_subject,$email_body,$headers);
    //done. redirect to thank-you page.
    header('Location: thank-you.html');


    // Function to validate against any email injection attempts
    function IsInjected($str)
    {
    $injections = array('(\n+)',
    '(\r+)',
    '(\t+)',
    '(%0A+)',
    '(%0D+)',
    '(%08+)',
    '(%09+)'
    );
    $inject = join('|', $injections);
    $inject = "/$inject/i";
    if(preg_match($inject,$str))
    {
    return true;
    }
    else
    {
    return false;
    }
    }

    ?>

  7. #7
    SitePoint Member
    Join Date
    Mar 2009
    Posts
    21
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think that I'm almost there. I'm getting an error, can someone help me figure out what I'm doing wrong?

    error; you need to submit the form!
    Warning: Cannot modify header information - headers already sent by (output started at /public_html/testform/form-to-email.php:5) in
    /public_html/testform/form-to-email.php on line 93



    <?php
    if(!isset($_POST['submit']))
    {
    //This page should not be accessed directly. Need to submit the form.
    echo "error; you need to submit the form!";
    }
    $problem_category = $_POST ['problem_category'];
    $name = $_POST['first_last_name'];
    $area_code = $_POST['area_code'];
    $contact_number = $_POST['contact_number'];
    $street_address = $_POST['street_address'];
    $zip_code = $_POST['zip_code'];
    $urgency = $_POST['urgency'];
    $preferred_date = $_POST['preferred_date'];
    $descr_of_problem = $_POST['descr_of_problem'];
    $preferred_time = $_POST['preferred_time'];

    if ($_POST['problem_category'] == "RESIDENTIAL_AIR_CONDITIONING ") {
    $email_to_send_to = " info@didgeman.com";
    } else if ($_POST['problem_category'] == "RESIDENTIAL_ELECTRICAL ") {
    $email_to_send_to = "info@creativeinstincts.org";
    } else if ($_POST['problem_category'] == "RESIDENTIAL_PLUMBING") {
    $email_to_send_to = " info@bartonsprings.net";
    } else if ($_POST['problem_category'] == "Operations") {
    $email_to_send_to = "info@mediaintentions.com";
    }


    //Validate first
    if(empty($first_last_name)||empty($first_last_name))
    {
    echo "Your name is mandatory!";
    exit;
    }
    if(empty($problem_category)||empty($problem_category))
    {
    echo "Problem Category is mandatory!";
    exit;
    }if(empty($email)||empty($email))
    {
    echo "Your email address is mandatory!";
    exit;
    }if(empty($area_code)||empty($area_code))
    {
    echo "Your area code is mandatory!";
    exit;
    }if(empty($contact_number)||empty($contact_number))
    {
    echo "Your contact phone number is mandatory!";
    exit;
    }if(empty($street_address)||empty($street_address))
    {
    echo "Your Street Address is mandatory!";
    exit;
    }
    if(empty($zip_code)||empty($zip_code))
    {
    echo "Your zip code is mandatory!";
    exit;
    }
    if(empty($urgency)||empty($urgency))
    {
    echo "Your urgency is mandatory!";
    exit;
    }if(empty($preferred_date)||empty($preferred_date))
    {
    echo "Your preferred date is mandatory!";
    exit;
    }if(empty($descr_of_problem)||empty($descr_of_problem))
    {
    echo "Your description of problem is mandatory!";
    exit;
    }
    if(empty($preferred_time)||empty($preferred_time))
    {
    echo "Your preferred time is mandatory!";
    exit;
    }



    $email_from = 'info@didgeman.com';//<== update the email address
    $email_subject = "Residential Request Form";
    $email_body = "You have received a new message from the user $name.\n".
    "Here is the message:\n $message".

    $to = "info@didgeman.com";//<== update the email address
    $headers = "From: $email_from \r\n";
    $headers .= "Reply-To: $visitor_email \r\n";
    //Send the email!
    mail($to,$email_subject,$email_body,$headers);
    //done. redirect to thank-you page.
    header('Location: thank-you.html');


    // Function to validate against any email injection attempts
    function IsInjected($str)
    {
    $injections = array('(\n+)',
    '(\r+)',
    '(\t+)',
    '(%0A+)',
    '(%0D+)',
    '(%08+)',
    '(%09+)'
    );
    $inject = join('|', $injections);
    $inject = "/$inject/i";
    if(preg_match($inject,$str))
    {
    return true;
    }
    else
    {
    return false;
    }
    }

    ?>


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •