Jump to content

Ok, i'm stuck on form array elements into email message and database


simcoweb

Recommended Posts

I've been cruising right along in creating two contact forms and scripts that parse the forms, send emails to the respective destinations AND insert the data into a MySQL database. The 'contact' form works fine. The 'schedule an appointment' form works but does not insert the selected items into the database. And, i'm not sure how to include the results of those fields into the email message.

Here's the form code:

[code]<?php
echo <<<EOD
<form method="POST">
<table class="dl" cellpadding="5" cellspacing="1" width="95%" align="center">
  <tr>
    <td class="head" align="center" colspan="2">Schedule An Appointment</td>
  </tr>
  <tr>
    <td class="body" align="left">Name</td>
    <td class="body" align="center"><input type="text" name="name" value="{$_POST['name']}" /></td>
  </tr>
  <tr>
    <td class="body" align="left">Email Address</td>
    <td class="body" align="center"><input type="text" name="email" value="{$_POST['email']}" /></td>
  </tr>
  <tr>
    <td class="body" align="left">Phone</td>
    <td class="body" align="center"><input type="text" name="phone" value="{$_POST['phone']}" /></td>
  </tr>
  <tr>
    <td class="body" align="left">Appointment is for:</td>
    <td class="body" align="center"><select value="appt_for[]">
<option value="Myself">Myself</option>
<option value="My Son">My Son</option>
<option value="My Daughter">My Daughter</option>
<option value="Other">Other</option>
</select></td>
  </tr>
  <tr>
    <td class="body" align="left">Best Days For You (select all that apply):</td>
    <td class="body" align="center"><input type="checkbox" name="best_days[]" value="Monday">Monday
                                    <input type="checkbox" name="best_days[]" value="Tuesday">Tuesday <br>
                                    <input type="checkbox" name="best_days[]" value="Wednesday">Wednesday
                                    <input type="checkbox" name="best_days[]" value="Thursday">Thursday <br>
                                    <input type="checkbox" name="best_days[]" value="Friday">Friday
                                    <input type="checkbox" name="best_days[]" value="Saturday">Saturday
    </td>
  </tr>
  <tr>
    <td class="body" align="left">Best Time For You:</td>
    <td class="body" align="center"><select value="best_time">
<option value="Before Noon" selected name="best_time[]">Before Noon</option>
<option value="Afternoon before 5" name="best_time[]">Afternoon before 5</option>
<option value="Evenings after 5" name="best_time[]">Evenings after 5</option>
</select>
    </td>
  </tr>
  <tr>
    <td class="body" align="center" colspan="2">Additional Details:<br><textarea name="message" rows="8" cols="50">{$_POST['message']}</textarea></td>
  </tr>
  <tr>
    <td class="body" align="center" colspan="2"><img src="securimage_show.php"></td>
  </tr>
  <tr>
    <td class="body" align="left">Enter the security text shown above</td>
    <td class="body" align="center"><input type="text" name="imagetext" /></td>
  </tr>
  <tr>
    <td class="body" align="center" colspan="2"><input type="submit" name="submit" value="Send Form" /></td>
  </tr>
</table>
</form>
EOD;
?>[/code]

I have two 'SELECT' items and one 'MULTIPLE' item in checkboxes. I know how to write the code if I wish to print those to the browser (with a foreach statement) but not sure how to adapt these choices into insertion for the database. Right now, upon submit, those three fields produce this:

appt_for:  blank
best_days: array  (the word array)
best_time: blank

And, here's the code for the email message:

[code]<?php
    @mail($to, "Appointment request for " . $_POST['subject'],
    "Drew,\nOn " . date("r") . ", " . $_POST['name'] . " " . $_POST['email'] .
    " " . $_POST['phone'] ." sent the following message.\nWe need an appointment for " .
    $_POST['appt_for'] . " The best days for them are " .$_POST['best_days']. ". The best times are " .$_POST['best_time']. " Here are further instructions \n\n" . stripslashes($_POST['message']), "From: " . $_POST['email']);
?>[/code]

So, how to get those form elements to insert into the database and how to get the results of those form elements into the message. Thanks in advance for you help!
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.