/    Sign up×
Community /Pin to ProfileBookmark

setting subject from select option throws error in mailer.php

Depending on the selected option another div is shown requesting further information in this case table number. which on sending email should set the subject to the value from the select option and if the table number field is filled in the should append this onto the subject line

[code]
<label class=”label-input” for=”email”>Subject *</label>
<div class=”contactfld-input mailsubject validate-input” data-validate = “subject required”>
<select class=”input-fld subjectselect” id=”emailsubject” name=”subject” onchange=”” onclick=”return false;” id=””>
<option value=””>Choose …</option>
<option value=”Table Reservations”>Table Reservations</option>
<option value=”Bookings”>Bookings</option>
<option value=”Party Hall Enquiry”>Party Hall Enquiry</option>
<option value=”Party Hall Booking”>Party Hall Booking</option>
<option value=”Catering Enquiry”>Catering Enquiry</option>
<option value=”Catering Arrangments”>Catering Arrangments</option>
<option value=”Catering Services”>Catering Services</option>
<option value=”Menu Orders”>Menu Orders</option>
<option value=”Banqueting Service Enquiry”>Banqueting Service Enquiry</option>
<option value=”Banqueting Arrangments”>Banqueting Arrangments</option>
<option value=”Online Enquiry”>Online Enquiry</option>
<option value=”Online Orders”>Online Orders</option>
<option value=”Online Order Ammendment”>Online Order Ammendment</option>
<option value=”Thoughts and Feedback”>Thoughts &amp; Feedback</option>
<option value=”General Question”>General Question</option>
<option value=”Complaint”>Complaint</option>
</select>
<span class=”focus-input”>

</span>
</div>

<script type=”text/javascript”>
$(document).ready(function() {
$(‘#emailsubject’).change(function() {
if (($(this).val() == ‘Online Enquiry’) || ($(this).val() == ‘Online Orders’) || ($(this).val() == ‘Online Order Ammendment’) || ($(this).val() == ‘Complaint’)) {
$(“.add-informationrequired”).show();
} else {
$(“.add-informationrequired”).hide();
}
});
});
</script>

<div class=”add-informationrequired”>
<label class=”label-input” for=”tableno”>Table no/ Order Id </label>
<div class=”contactfld-input”>
<input class=”input-fld” id=”tableorder-idno” type=”text” name=”idno-tableorder” placeholder=””>
<span class=”focus-input”>

</span>
</div>
</div>
[/code]

[code]
function prepareFormSubmission() {
var name = $(“input[name=name]”).val();
var contactno = $(“input[name=phone]”).val();
var email = $(“input[name=email]”).val();
var subject = $(‘select[name=subject]’).val();
var tableno = $(“input[name=idno-tableorder]”).val();
var message = $(“textarea[name=message]”).val();
$.ajax({
type: “POST”,
url: “mailer.php”,
data: “name=” + name + “&phone=” + contactno + “&email=” + email + “$subject=” + subject + “&tableno=” + tableno + “&message=” + message,
success: function() {
$(“#contact-form”).trigger(“reset”);
},
error: function() {

}
});
}
[/code]

mailer.php

[code]
<?
$name = $_POST[‘name’];
$contactno = $_POST[‘phone’];
$email = $_POST[’email’];
$subject = $_POST[‘subject’];

if($subject == ‘Online Enquiry’ || $subject == ‘Online Orders’ || $subject == ‘Online Order Ammendment’ || $subject == ‘Complaint’) {
if(“” == trim($_POST[‘tableno’])){
$subject = $subject;
} else {
$tableno = $_POST[‘tableno’];
if($subject == ‘Online Enquiry’) {
$subject = “Online Enquiry Regarding order table number ” .$tableno . ” from website”;
}
if($subject == ‘Online Orders’) {
$subject = “Online Order, table number ” .$tableno . ” from website”;
}
if($subject == ‘Online Order Ammendment’) {
$subject = “Online Order Ammendment, table number ” .$tableno . ” from website”;
}
if($subject == ‘Complaint’) {
$subject = “Customer complaint, table number ” .$tableno . ” from website”;
}
}
}
$message = $_POST[‘message’];

$formcontent=”From: $name n Message: $message”;
$recipient = ” “; <– to email address here

$mailheader = “From: $email rn”;
mail($recipient, $subject, $formcontent, $mailheader) or die(“Error!”);
[/code]

but this throws the error:

[24-Jan-2020 04:14:23 UTC] PHP Notice: Undefined index: subject in /home/mnzsm9leak30/public_html/mailer.php on line 5

which is possibly the line

[code]$subject = $_POST[‘subject’]; [/code]

the xhr request is successfully made. Can someone please guide me/ provide a solution/ correct me if i’m wrong

Thanks

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@SempervivumJan 24.2020 — Error in this line:

`data: "name=" + name + "&amp;phone=" + contactno + "&amp;email=" + email + "$subject=" + subject + "&amp;tableno=" + tableno + "&amp;message=" + message,`

$ instead of & at subject
Copy linkTweet thisAlerts:
@nsathauthorJan 24.2020 — @Sempervivum#1613579

o snap missed that. Thanks
×

Success!

Help @nsath spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 4.29,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...