Jump to content
Larry Ullman's Book Forums

Grafica

Members
  • Posts

    8
  • Joined

  • Last visited

Posts posted by Grafica

  1. Hi. I'm using xampp 1.8.0 with Windows 7 SP1, 32 bit OS, and coding HTML5 and CSS3. I'm just learning PHP, and I created a contact form. I'm using Javascript to check if the form was filled out properly, so I didn't use some of the code shown in the book, and I did not scrub the date, time, and priority fields. The error message is: Parse error: syntax error, unexpected '&&' (T_BOOLEAN_AND), expecting ')' on the line that reads: if (!empty($scrubbed['name']) && !empty($scrubbed['email']) && !empty($scrubbed['tel'] && !empty($scrubbed['description']) ). Thanks.

     

    <?php

    if ($_SERVER['REQUEST_METHOD'] == 'POST')

    {

    function spam_scrubber($value)

    {

    $very_bad = array('to:', 'cc:', 'bcc:', 'content-type:', 'mime-version:', 'multipart-mixed:', 'content-transfer-encoding:');

     

    foreach ($very_bad as $v) {

    if (stripos($value, $v) !== false) return '';

    }

     

    $value = str_replace(array( "\r", "\n", "%0a", "%0d"), ' ', $value);

     

    return trim($value);

    }

     

    $scrubbed = array_map('spam_scrubber', $_POST);

     

    if (!empty($scrubbed['name']) && !empty($scrubbed['email']) && !empty($scrubbed['tel'] && !empty($scrubbed['description']) )

    {

    $body = "Name: {$scrubbed['name']}\nEmail: {$scrubbed['email']}\nPhone: {$scrubbed['tel']}\nPriority: {$_POST['priority']}\nDate: {$_POST['date']}\nTime: {$_POST['s2Time1']}\nDescription: {$scrubbed['description']}";

     

    $body = wordwrap($body, 70);

     

    mail('mail@yahoo.com', 'Contact Form Submission', $body, "From: {$scrubbed['email']}");

     

    echo '<p>Thank you for your request. A member of our staff will be contacting you shortly.</p>';

     

    $scrubbed = array();

    }

     

    ?>

     

    <div id="form">

    <div id="contain">

     

    <form action="RequestAppt2.php" method="post">

     

    <table class="form_demo">

    <tr>

    <td>

    <label>Name</label>

    </td>

    <td>

    <input class="input_full" type="text" id="name" name="name" required="required" />

    </td>

    </tr>

    <tr>

    <td><label for="email">

    Email

    </label>

    </td>

    <td>

    <input class="input_full" type="email" id="email" name="email" required="required" />

    </td>

    </tr>

    <tr>

    <td>

    <label for="tel">

    Phone

    </label>

    </td>

    <td>

    <input class="input_full" type="tel" id="tel" name="tel" required="required" />

    </td>

    </tr>

    <tr>

    <td><label for="priority_normal">

    Priority

    </label>

    </td>

    <td>

    <input type="radio" name="priority" id="priority_urgent" value="Urgent">

    <label for="priority_urgent">

    Urgent

    </label>

     

     

    <input type="radio" name="priority" id="priority_normal" value="Normal" checked="checked">

    <label for="priority_normal">

    Normal

    </label>

     

     

    </td>

    </tr>

    <tr>

    <td>

    <label for="date">Enter a date:</label>

    </td>

    <td>

    <input class="input_xlarge" type="text" id="date" name="date" required="required" />

     

    <script>

    (function($){

    var pickerOpts = {

    minDate: new Date(),

    maxDate: "+3m,",

    showButtonPanel: true,

    showOn: "button",

     

    buttonImage: "images/cal.png",

    };

    $("#date").datepicker(pickerOpts);

    })(jQuery);

    </script>

    </td></tr>

    <tr><td>Enter a time: </td>

    <td><input id="time1" name="s2Time1" />

     

    <script type="text/javascript">

    $('#time1').ptTimeSelect({ popupImage: 'Select Time' });

    </script>

    </td>

    </tr>

     

    <tr>

    <td>

    <label for="description">

    Reason for<br />

    appointment

    </label>

    </td>

    <td>

    <textarea id="description" name="description" rows="3" required="required"></textarea>

    </td>

    </tr>

     

    </table>
  2. Hi. I'm using xampp 1.8.0 with Windows 7 SP1, 32 bit OS, and coding HTML5 and CSS3. I'm just learning PHP, and I created a contact form for a dentist's Website, so that patients can request appointments. An email should go to the dentist and display the information that the user entered. (I only coded the 'name' and 'description' to be in the email so far, since this is just a test.) I'm using Javascript to check if the patient filled out the form properly, so I didn't use some of the code shown on pg. 332 of the book. There is an error on the first line: Parse error: syntax error, unexpected 'POST' (T_STRING), expecting ']'. Can someone tell me what's wrong? Thanks.

    <?php

    if ($_SERVER['REQUEST_METHOD] == 'POST'

    {

    body = "Name: ($POST['name']}\n\nComments: {$_POST['description']}";

     

    $body = wordwrap($body, 70);

     

    mail('mail@yahoo.com', 'Contact Form Submission', $body, "From: {$_POST['email']}");

     

    echo 'Thank you for your request. A member of our staff will be contacting you shortly.';

     

    $_POST = array();

    }

     

    ?>

     

    <div id="form">

    <div id="contain">

     

    <form action="EmailConf.php" method="post">

     

    <table class="form_demo">

    <tr>

    <td>

    <label>Name</label>

    </td>

    <td>

    <input class="input_full" type="text" id="name" name="name" required="required" />

    </td>

    </tr>

    <tr>

    <td><label for="email">

    Email

    </label>

    </td>

    <td>

    <input class="input_full" type="email" id="email" name="email" required="required" />

    </td>

    </tr>

    <tr>

    <td>

    <label for="tel">

    Phone

    </label>

    </td>

    <td>

    <input class="input_full" type="tel" id="tel" name="tel" required="required" />

    </td>

    </tr>

    <tr>

    <td><label for="priority_normal">

    Priority

    </label>

    </td>

    <td>

    <input type="radio" name="priority" id="priority_urgent" value="Urgent">

    <label for="priority_urgent">

    Urgent

    </label>

     

     

    <input type="radio" name="priority" id="priority_normal" value="Normal" checked="checked">

    <label for="priority_normal">

    Normal

    </label>

     

     

    </td>

    </tr>

    <tr>

    <td>

    <label for="date">Enter a date:</label>

    </td>

    <td>

    <input class="input_xlarge" type="text" id="date" name="date" required="required" />

     

    <script>

    (function($){

    var pickerOpts = {

    minDate: new Date(),

    maxDate: "+3m,",

    showButtonPanel: true,

    showOn: "button",

     

    buttonImage: "images/cal.png",

    };

    $("#date").datepicker(pickerOpts);

    })(jQuery);

    </script>

    </td></tr>

    <tr><td>Enter a time: </td>

    <td><input id="time1" name="s2Time1" />

     

    <script type="text/javascript">

    $('#time1').ptTimeSelect({ popupImage: 'Select Time' });

    </script>

    </td>

    </tr>

     

    <tr>

    <td>

    <label for="description">

    Reason for<br />

    appointment

    </label>

    </td>

    <td>

    <textarea id="description" name="description" rows="3" required="required"></textarea>

    </td>

    </tr>

     

    </table>

    <hr />

    <p class="clearfix">

    <input type="submit" value="Submit" class="float_left" />

    <input type="reset" value="Reset" class="float_right">

    </p>

     

    </form>
×
×
  • Create New...