0

Hi I have a radio button form made in bootstrap, I want to know what the server side code needs to be in order to send a email to my email with the forms result.

I want the user to fill in the form ( radio buttons )and then click submit,

When he clicks submit a new window must open that says for instance "thank you please enter email below to get results"

Then there must be a field that I will ad that asks for the email and then a get result button.

I want to send the results of the radio buttons with the corresponding answers(selection) from the mail they submitted to my email.

to be receive it like this for example:

From: the entered email

Date:

To: my email

Subject: Survey Results

Question 1 Yes

Question 2 No

etc etc

Here is the code I use for the HTML side:

<div class="container">
<form class="form-horizontal action="contactmail.php" method="post" id="form">
<fieldset>

<!-- Form Name -->
<legend><b style="color:red">Quick Survey</b></legend>

<!-- Multiple Radios -->
<div class="control-group">
  <label class="control-label" for="radios">Were you injured in a car or taxi accident?</label>
  <div class="controls">
    <label class="radio" for="radios-0">
      <input type="radio" name="Question 1" id="radios-0" value="Yes">
      Yes
    </label>
    <label class="radio" for="radios-1">
      <input type="radio" name="Question 1" id="radios-1" value="No">
      No
    </label>
  </div>
</div>

<!-- Multiple Radios -->
<div class="control-group">
  <label class="control-label" for="radios">Was it within the past 3 years?</label>
  <div class="controls">
    <label class="radio" for="radios-0">
      <input type="radio" name="Question 2" id="radios-0" value="Yes">
      Yes
    </label>
    <label class="radio" for="radios-1">
      <input type="radio" name="Question 2" id="radios-1" value="No">
      No
    </label>
  </div>
</div>

<!-- Multiple Radios -->
<div class="control-group">
  <label class="control-label" for="radios">Did you have serious injuries?</label>
  <div class="controls">
    <label class="radio" for="radios-0">
      <input type="radio" name="Question 3" id="radios-0" value="Yes">
      Yes
    </label>
    <label class="radio" for="radios-1">
      <input type="radio" name="Question 3" id="radios-1" value="no">
      no
    </label>
  </div>
</div>

<!-- Multiple Radios -->
<div class="control-group">
  <label class="control-label" for="radios">Were you in hospital because of the accident?</label>
  <div class="controls">
    <label class="radio" for="radios-0">
      <input type="radio" name="Question 4" id="radios-0" value="Yes">
      Yes
    </label>
    <label class="radio" for="radios-1">
      <input type="radio" name="Question 4" id="radios-1" value="No">
      No
    </label>
  </div>
</div>

<!-- Multiple Radios -->
<div class="control-group">
  <label class="control-label" for="radios">How many days did you spend in hospital?</label>
  <div class="controls">
    <label class="radio" for="radios-0">
      <input type="radio" name="Question 5" id="radios-0" value="1 Day">
      1 Day
    </label>
    <label class="radio" for="radios-1">
      <input type="radio" name="Question 5" id="radios-1" value="1-7 Days">
      1-7 Days
    </label>
    <label class="radio" for="radios-2">
      <input type="radio" name="Question 5" id="radios-2" value="7-14 Days">
      7-14 Days
    </label>
    <label class="radio" for="radios-3">
      <input type="radio" name="Question 5" id="radios-3" value="14-21 Days">
      14-21 Days
    </label>
    <label class="radio" for="radios-4">
      <input type="radio" name="Question 5" id="radios-4" value="21-28 Days">
      21-28 Days
    </label>
    <label class="radio" for="radios-5">
      <input type="radio" name="Question 5" id="radios-5" value="1 Month or more">
      1 Month or more
    </label>
  </div>
</div>

<!-- Multiple Radios -->
<div class="control-group">
  <label class="control-label" for="radios">Did you undergo surgery?</label>
  <div class="controls">
    <label class="radio" for="radios-0">
      <input type="radio" name="Question 6" id="radios-0" value="Yes">
      Yes
    </label>
    <label class="radio" for="radios-1">
      <input type="radio" name="Question 6" id="radios-1" value="No">
      No
    </label>
  </div>
</div>

<!-- Multiple Radios -->
<div class="control-group">
  <label class="control-label" for="radios">Do you still suffer as a result of the accident?</label>
  <div class="controls">
    <label class="radio" for="radios-0">
      <input type="radio" name="Question 7" id="radios-0" value="Yes">
      Yes
    </label>
    <label class="radio" for="radios-1">
      <input type="radio" name="Question 7" id="radios-1" value="No">
      No
    </label>
  </div>
</div>

<!-- Button -->
<div class="control-group">
  <label class="control-label" for="Submit"></label>
  <div class="controls">
    <button id="Submit" name="Submit" class="btn btn-info">Submit</button>
  </div>
</div>

</fieldset>
</form>


</div>

I will appreciate all the help

edit: It works now, here is the code i used ( Keep in mind trim is not needed )

<?php
/**
    if(isset($_POST['submit'])) {
        if (empty($_POST['email']) || empty($_POST['Question1']) || empty($_POST['Question2']) || empty($_POST['Question3']) || empty($_POST['Question4']) || empty($_POST['Question5']) || empty($_POST['Question6']) || empty($_POST['Question7'])) {
            $error = true;
        } 
        else {
**/         $email = trim($_POST['email']);
            $to = "Enteryourmail@domain.co.za,$email";

            $Question1 = trim($_POST['Question1']);
            $Question2 = trim($_POST['Question2']);
            $Question3 = trim($_POST['Question3']);
            $Question4 = trim($_POST['Question4']);
            $Question5 = trim($_POST['Question5']);
            $Question6 = trim($_POST['Question6']);
            $Question7 = trim($_POST['Question7']);
            $email = trim($_POST['email']);
            $phone = trim($_POST['phone']);
            $frommail = "info@mydomain.co.za";

            $subject = "Contact Form";

            $message =  "Were you injured in a car or taxi accident?: $Question1 \r\n Was it within the past 3 years?: $Question2 \r\n Did you have serious injuries?: $Question3 \r\n Were you in hospital because of the accident?: $Question4 \r\n How many days did you spend in hospital?: $Question5 \r\n Did you undergo surgery?: $Question6 \r\n Do you still suffer as a result of the accident?: $Question7 \r\n Email: $email \r\n Phone: $phone";
            $headers = "From:" . $frommail;
            $mailsent = mail($to, $subject, $message, $headers);

/**
       }
  } **/
?>
Erik Thiart
  • 381
  • 6
  • 17

1 Answers1

0

You have only the HTML so far.

Next things you need to learn:

It's very simple to learn. Then, if you have any doubt after reading, come back with your questions.

Community
  • 1
  • 1
Berriel
  • 12,659
  • 4
  • 43
  • 67
  • I appreciate the help so much I think i am getting this just one question so far. I see in this section [Radio Buttons with PHP Form Handling](http://stackoverflow.com/questions/5031768/radio-buttons-with-php-form-handling). They say i will need radios values: – Erik Thiart Nov 12 '14 at 12:38
  • First thing you need is to create an action to your form, so you can send the data from the form to a script (1st link). Then you need to get the values from the radio buttons (2nd link) and other inputs and send the email (3rd link) as you want. – Berriel Nov 12 '14 at 12:48
  • See I get that, but look at this example: Easy! Just add a value to your radio buttons. ' Email Phone' Since my value will always be Yes or No I don't know how I can make them unique for the 7 radio buttons. Sorry for the noob questions, I haven't really touched php so much yet. ( seriously wanting to find time and learn it ) – Erik Thiart Nov 12 '14 at 13:21
  • Well, your original question isn't about it, but what should be unique isn't the **attribute value**, but the **attribute name** and **id**. Remember to upvote if the answer helped you with your original question. – Berriel Nov 12 '14 at 13:28
  • I understand my original questions was not about that specifically, but after the links you provided that question came to mind and forms part of the original question is basically what does the code has to be to achieve the original question. Again how do I make those unique since both ID and name will be the same for each Question... – Erik Thiart Nov 12 '14 at 14:29
  • Each question has two radios and only one can be selected. – Erik Thiart Nov 12 '14 at 14:30
  • Yup, each radio 'group' must have the same **name**. You can assign `name='q1'` to question 1, `name='q2'` to question 2 and so on. Btw, your code already do that. On the php script that receives the form data, the variable `$_POST['q1']` will have one value, the `$_POST['q2']` another and so on... – Berriel Nov 12 '14 at 14:36
  • Omg thank you so much!!! Rodrigo that last part is all i needed to know is how to present the captured data in php from the html! – Erik Thiart Nov 14 '14 at 13:31
  • I can post a my code here for future people, It works seamlessly now. I really appreciate your help. – Erik Thiart Nov 14 '14 at 13:31
  • I need 15 rep to upvote your answer so I will just comment here so long that you where fantastic! – Erik Thiart Sep 15 '15 at 07:28