Greetings everyone,
I have a problem where the value for the student name and programme not appearing the email after I send the email through PHPMailer. I am using PHP PDO and I have checked that the student name and programme is under a form. Other values are appearing just fine in the email such as the image below:
I am not sure whether it is the quotation marks making problem or other things.
Below are my code for the student-appointment-form.php file:
<?php
require ("global-include-student.php");
require ('PHPMailer/PHPMailerAutoLoad.php');
require ('PHPMailer/smtp-credentials.php');
//timezone for Malaysia
date_default_timezone_set("Asia/Kuala_Lumpur");
//Condition when the submit button is clicked
if(isset($_POST["btnSubmit"])){
try
{
$appointment_date = date('Y-m-d',strtotime($_POST['appointment_date']));
//$appointment_date = date("Y-m-d H:i:s");
// Inserting the data into database
$insert_query = "INSERT INTO appointment (appointment_type, appointment_date, appointment_time, student_id, lecturer_id, field, venue, remarks, appointment_status)
VALUES ('".$_POST["appointment_type"]."',
'".$appointment_date."',
'".$_POST["appointment_time"]."',
'".$_POST["student_id"]."',
'".$_POST["lecturer_id"]."',
'".$_POST["field_id"]."',
'".$_POST["venue"]."',
'".$_POST["remarks"]."',
'".$_POST["appointment_status"]."'
)";
//PHPMailer set up
$field_name = $_POST['field_name'];
$lect_name = $_POST['lect_name'];
$lect_email = $_POST['lect_email'];
$student_name = $_POST['student_name'];
$programme = $_POST['programme'];
$output='<strong>Greetings from STULEC,</strong> <br/>
<p>There is an appointment request from ' . $student_name . ' who is in the ' . $programme . ' programme.</p>
The appointment details are such as below: <br/>
<ul>
<li>Appointment Type: '. $_POST['appointment_type'] .'</li>
<li>Appoinment Date: '. $_POST['appointment_date'] .'</li>
<li>Appointment Time: '. $_POST['appointment_time'] . '</li>
<li>Venue: '. $_POST['venue'] .' </li>
<li>Course Field: '. $_POST['field_name'] .' </li>
<li>Remarks: '. $_POST['remarks'] . '</li>
</ul>
</p>
<p>Please approve the appointment request by logging into STULEC. Thank you.';
$mail = new PHPMailer;
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtp.gmail.com'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = EMAIL; // SMTP username
$mail->Password = PASS; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587; // TCP port to connect to
$mail->setFrom('stulec#edu.my', 'STULEC'); //From sender
$mail->addAddress($lect_email, $lect_name); // Add a recipient
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = 'STULEC | Appointment Request from Student';
$mail->Body = $output;
$mail->CharSet = 'utf-8';
$mail->ContentType = 'text/html';
if (($db->query($insert_query)) && $mail->send())
{
echo "<script type= 'text/javascript'>alert('An appointment has been made with the lecturer. Please wait until the lecturer responds to your request.');";
echo 'window.location= "student-view-pending-appointment.php"';
echo "</script>";
}
else
{
echo "<script type= 'text/javascript'>alert('Error: The appoinment cannot be made!');";
echo 'window.location= "student-appointment-form.php"';
echo "</script>";
}
}
catch(PDOException $e)
{
echo $e->getMessage();
}
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>STULEC | Appointment Form</title>
</head>
<body class="hold-transition skin-blue sidebar-mini">
<div class="wrapper">
<!--Include header-->
<?php include 'include/header.php' ?>
<!--Include sidebar-->
<?php include 'include/sidebar.php' ?>
<!-- Content Wrapper. Contains page content -->
<div class="content-wrapper">
<!-- Content Header (Page header) -->
<section class="content-header">
<h1 align='center'>
<u>Appointment Form</u>
</h1>
</section>
<!-- Main content -->
<section class="content">
<div class="box box-default">
<div class="box-body">
<div class="row">
<div class="col-md-12">
<!-- form start -->
<form class="form-horizontal" action="" method="POST">
<?php
//select student details from the database
$sql = "SELECT username, name, role, department, programme, profile_pic, programme_name FROM users
LEFT JOIN programme AS programme ON programme.programme_id = users.programme
WHERE user_id = :user_id";
$stmt = $db->prepare($sql);
if ($stmt->execute(array('user_id' => $_SESSION['user_id'])))
{
while($row = $stmt->fetch())
{
//fetch the rows
$username = $row['username'];
$name = $row['name'];
$programme = $row['programme_name'];
echo "
<!--Name-->
<div class='form-group'>
<label for='Name' class='col-sm-2 control-label'>Name</label>
<div class='col-sm-10'>
<input type='text' class='form-control' name='student_name' id='student_name' value='". $row['name']."' disabled>
<input type='hidden' class='form-control' name='student_id' id='student_id' value=" . $row['username'] ." />
</div>
</div>
<!--Programme-->
<div class='form-group'>
<label for='Programme' class='col-sm-2 control-label'>Programme</label>
<div class='col-sm-10'>
<input type='text' class='form-control' name='programme' id='programme' value=" . $row['programme_name'] ." disabled>
</div>
</div>
";
}
}
?>
<!--Consultation Type-->
<div class='form-group'>
<label for='ConsultationType' class='col-sm-2 control-label'>Consultation Type</label>
<div class='col-sm-10'>
<select class='form-control' name='appointment_type'>
<option selected='selected' name='assignment_discussion' value='Assignment Discussion'>Assignment Discussion</option>
<option name='advisory_session' value='Advisory Session'>Advisory Session</option>
<option name='fyp_discuss' value='Final Year Project Discussion'>Final Year Project Discussion</option>
</select>
</div>
</div>
<!--Field name-->
<div class='form-group'>
<label for='Course' class='col-sm-2 control-label'>Course Field</label>
<div class='col-sm-10'>
<select class='form-control' name='field_id' id='field_id' required>
<option value=''>Please select a course field</option>
<?php
//Display field name
$select_field_query = "SELECT field_id, field_name FROM course_field
LEFT JOIN field_programme ON field_programme.field = course_field.field_id
LEFT JOIN users ON users.programme = field_programme.programme
LEFT JOIN programme ON programme.programme_id = field_programme.programme
WHERE field_programme.programme = :programme AND users.username = :student";
$field_statement = $db->prepare($select_field_query);
$field_statement->bindParam(':programme', $_SESSION['programme']);
$field_statement->bindParam(':student', $_SESSION['username']);
$field_statement->execute();
while ($row = $field_statement->fetch(PDO::FETCH_ASSOC))
{
echo
"<option value='" . $row['field_id'] . "'>" . $row['field_name'] . "</option>";
}
?>
</select>
</div>
</div>
<!--Hidden course field_name-->
<input type='hidden' id='field_name' name='field_name'>
<!--Lecturer name selection-->
<div class='form-group'>
<label for='Lecturer' class='col-sm-2 control-label'>Lecturer</label>
<div class='col-sm-10'>
<select class='form-control' name='lecturer_id' id='lecturer_id'>
<option>-</option>
</select>
</div>
</div>
<!--Hidden lecturer email-->
<input type='hidden' id='lect_email' name='lect_email'>
<!--Hidden lecturer name-->
<input type='hidden' id='lect_name' name='lect_name'>
<!-- Date -->
<div class='form-group'>
<label for='Date' class='col-sm-2 control-label'>Date</label>
<div class='col-sm-4'>
<div class='input-group date'>
<input type='text' class='form-control pull-right' name='appointment_date' id='datepicker' required>
<div class='input-group-addon'>
<i class='fa fa-calendar'></i>
</div>
</div><!-- /.input group -->
</div><!-- /.form group -->
</div>
<!-- Time -->
<div class='form-group'>
<label for='Time' class='col-sm-2 control-label'>Time</label>
<div class='col-sm-4'>
<div class='input-group time'>
<input type='text' class='form-control timepicker' name='appointment_time' id='timepicker' required>
<div class='input-group-addon'>
<i class='fa fa-clock-o'></i>
</div>
</div><!-- /.input group -->
</div>
</div><!-- /.form group -->
<!--Venue-->
<div class='form-group'>
<label for='Venue' class='col-sm-2 control-label'>Venue</label>
<div class='col-sm-10'>
<select class='form-control' name='venue'>
<option selected='selected' name='in_front_dpmt' value='In front of department'>In front of department</option>
<option name='library' value='Library'>Library</option>
<option name='consultation_room' value='Consultation Room'>Consultation Room</option>
</select>
</div>
</div>
<!--Remarks-->
<div class='form-group'>
<label for='Remarks' class='col-sm-2 control-label'>Remarks</label>
<div class='col-sm-10'>
<input type='text' class='form-control' name='remarks' id='remarks' placeholder='Eg: Related to the Local Area Network question' required>
</div>
</div>
<!--Hidden Appointment Status which is set as Pending when form is submitted-->
<input type="hidden" value="Pending" name="appointment_status">
<!--Submit button-->
<div class="box-footer">
<button type="submit" class="btn btn-success pull-right" name="btnSubmit" id="btnSubmit">Submit</button>
</div>
</form>
</div><!-- /.box -->
</div><!-- /.col -->
</div><!-- /.col -->
</div><!-- /.row -->
</div><!-- /.box-body -->
</div><!-- /.box -->
</div><!-- ./wrapper -->
<!-- Page script -->
<script>
$(function ()
{
//Change lecturer when different course field is selected
$("#field_id").change(function () {
if ($('#field_id option:selected').val() != "")
{
$.ajax({
type: 'POST',
url: 'ajax-field-lecturer.php',
data: { 'field_id' : $('#field_id option:selected').val() },
success: function(data) {
$('#lecturer_id').empty();
var lect = JSON.parse(data);
$.each(lect, function( index, lectObj )
{
if (index == 0)
{
$('#lect_email').val(lectObj.email);
$('#lect_name').val(lectObj.name);
$('#field_name').val(lectObj.field_name);
}
$('#lecturer_id').append("<option value='"+lectObj.username+"'>"+lectObj.name+"</option>");
});
},
error: function(data) {
alert(data);
}
});
}
else
{
$('#lecturer_id').empty();
}
});
//Change lecturer email when different the lecturer is selected
$("#lecturer_id").change(function () {
if ($('#lecturer_id option:selected').val() != "")
{
$.ajax({
type: 'POST',
url: 'ajax-email-lecturer.php',
data: { 'lecturer_id' : $('#lecturer_id option:selected').val() },
success: function(data) {
//alert(data);
$('#lect_email').empty();
var lect = JSON.parse(data);
$('#lect_email').val(lect[0].email);
},
error: function(data) {
alert(data);
}
});
}
else
{
$('#lect_email').empty();
}
});
//Show lecturer name
$("#lecturer_id").change(function () {
if ($('#lecturer_id option:selected').val() != "")
{
$.ajax({
type: 'POST',
url: 'ajax-name-lecturer.php',
data: { 'lecturer_id' : $('#lecturer_id option:selected').val() },
success: function(data) {
//alert(data);
$('#lect_name').empty();
var lect = JSON.parse(data);
$('#lect_name').val(lect[0].name);
},
error: function(data) {
alert(data);
}
});
}
else
{
$('#lect_name').empty();
}
});
//Show course field name
$("#field_id").change(function () {
if ($('#field_id option:selected').val() != "")
{
$.ajax({
type: 'POST',
url: 'ajax-field-name.php',
data: { 'field_id' : $('#field_id option:selected').val() },
success: function(data) {
//alert(data);
$('#field_name').empty();
var lect = JSON.parse(data);
$('#field_name').val(lect[0].field_name);
},
error: function(data) {
alert(data);
}
});
}
else
{
$('#field_name').empty();
}
});
//Date picker
$( "#datepicker" ).datepicker({
dateFormat: "yyyy-MM-dd"
});
//Timepicker
$('.timepicker').timepicker({
showInputs: false
})
})
</script>
</body>
</html>
Please guide me on how to solve this problem. Thank you.
In your form your student_name and programme fileds are disabled, and not posted.
Consider using hidden inputs to post values or change disable to readonly (not sure if it the latter works tho).
Related
I have a code that I have been trying to run for days without success, could anyone look at it and help figure where I am going crazy?
here is report.js:
$(document).ready(function() {
$('#navReport').addClass('active');
// order date picker
$('#startDate').datepicker();
// order date picker
$('#endDate').datepicker();
$('#getReportForm')
.unbind('submit')
.bind('submit', function() {
var startDate = $('#startDate').val();
var endDate = $('#endDate').val();
var personId = $('#personId').val();
if (startDate == '' || endDate == '' || personId == '') {
if (startDate == '') {
$('#startDate')
.closest('.form-group')
.addClass('has-error');
$('#startDate').after(
'<p class="text-danger">The Start Date is required</p>'
);
} else {
$('.form-group').removeClass('has-error');
$('.text-danger').remove();
}
if (endDate == '') {
$('#endDate')
.closest('.form-group')
.addClass('has-error');
$('#endDate').after(
'<p class="text-danger">The End Date is required</p>'
);
} else {
$('.form-group').removeClass('has-error');
$('.text-danger').remove();
}
if (personId == '') {
$('#personId')
.closest('.form-group')
.addClass('has-error');
$('#personId').after(
'<p class="text-danger">Person Name is required</p>'
);
} else {
$('.form-group').removeClass('has-error');
$('.text-danger').remove();
}
} else {
$('.form-group').removeClass('has-error');
$('.text-danger').remove();
var form = $(this);
$.ajax({
url: form.attr('action'),
type: form.attr('method'),
data: form.serialize(),
dataType: 'text',
success: function(response) {
var mywindow = window.open(
'',
'Child Behavior Management System',
'height=400,width=600'
);
mywindow.document.write('<html><head><title>Report</title>');
mywindow.document.write('</head><body>');
mywindow.document.write(response);
mywindow.document.write('</body></html>');
mywindow.document.close(); // necessary for IE >= 10
mywindow.focus(); // necessary for IE >= 10
mywindow.print();
mywindow.close();
} // /success
}); // /ajax
} // /else
console.log(personId, startDate, endDate);
return false;
});
});
Here is getReport.php:
<?php
require_once 'core.php';
if($_POST) {
$personId = $_POST['personId'];
$startDate = $_POST['startDate'];
$date = DateTime::createFromFormat('m/d/Y',$startDate);
$start_date = $date->format("Y-m-d");
$endDate = $_POST['endDate'];
$format = DateTime::createFromFormat('m/d/Y',$endDate);
$end_date = $format->format("Y-m-d");
$table = '';
$sql = "SELECT notes.note_id, notes.note_content, notes.person_id,
notes.note_date, notes.note_status, persons.persons_name
FROM notes INNER JOIN persons ON notes.person_id = persons.persons_id
WHERE notes.person_id = '$personId' AND notes.note_date
BETWEEN CAST('$start_date' AS DATE) AND CAST('$end_date' AS DATE)
AND notes.note_status = 1"
$query = $connect->query($sql);
$table = '
<table border="1" cellspacing="0" cellpadding="0" style="width:100%;">
<tr>
<th>Date</th>
<th>Note</th>
<th>Resident</th>
</tr>
<tr>';
while ($result = $query->fetch_assoc()) {
$table .= '<tr>
<td><center>'.$result['notes.note_date'].'</center></td>
<td><center>'.$result['notes.note_content'].'</center></td>
<td><center>'.$result['persons.persons_name'].'</center></td>
</tr>';
}
$table .= '
</tr>
</table>
';
echo $table;
}
?>
And here is report.php:
<?php require_once 'includes/header.php'; ?>
<div class="row">
<div class="col-md-12">
<div class="panel panel-default">
<div class="panel-heading">
<i class="glyphicon glyphicon-check"></i> Generate Report
</div>
<!-- /panel-heading -->
<div class="panel-body">
<form class="form-horizontal" action="php_action/getReport.php" method="post" id="getReportForm">
<div class="form-group">
<label for="personId" class="col-sm-2 control-label">Resident</label>
<div class="col-sm-10">
<select type="text" class="form-control" id="personId" placeholder="Resident" name="personId" >
<option value="">~~SELECT~~</option>
<?php
$sql = "SELECT persons_id, persons_name, persons_status FROM persons WHERE persons_status = 1";
$result = $connect->query($sql);
while($row = $result->fetch_array()) {
echo "<option value='".$row[0]."'>".$row[1]."</option>";
} // while ?>
</select>
</div>
</div> <!-- /form-group-->
<div class="form-group">
<label for="startDate" class="col-sm-2 control-label">Start Date</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="startDate" name="startDate" placeholder="Start Date" />
</div>
</div>
<div class="form-group">
<label for="endDate" class="col-sm-2 control-label">End Date</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="endDate" name="endDate" placeholder="End Date" />
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button type="submit" class="btn btn-success" id="generateReportBtn"> <i class="glyphicon glyphicon-ok-sign"></i>
Generate Report</button>
</div>
</div>
</form>
</div>
<!-- /panel-body -->
</div>
</div>
<!-- /col-dm-12 -->
</div>
<!-- /row -->
<script src="custom/js/report.js"></script>
<?php require_once 'includes/footer.php'; ?>
I would love to have expert solution to this. I have looked for solution almost the entire night but no joy. The popup is not firing when I select the preferred person, start and end dates based on the query.
I have a checkbox list. When I click on a checkbox, a modal appears with corresponding data coming from database. I have already done this. here are my codes.
db.php
<?php
$servername = "localhost";
$username = "root";
$password = "";
$db = "db";
$conn = mysqli_connect($servername, $username, $password,$db);
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
echo "Connected successfully <br/>";
?>
student.php
<body>
<form>
<label>
<input type="checkbox" value="1" name="name">
Ann
</label>
<label>
<input type="checkbox" value="2" name="name">
Sam
</label>
<label>
<input type="checkbox" value="3" name="name">
Amaa
</label>
</form>
<!--modal-->
<div id="myModal" class="modal fade" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Modal Header</h4>
</div>
<div class="modal-body"></div>
<div class="modal-footer">
<button type="submit" class="btn btn-default" id="submit" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
</body>
student.js
$(document).ready(function(){
$("input[type=checkbox][name=name]").change(function(){
if(this.checked) {
var value = $(this).val();
$.ajax({
url:"modal.php",
type:"POST",
data:{value:value},
success:function(modalBody){
$("#myModal .modal-body").html(modalBody);
$("#myModal").modal('show');
}
});
}
});
});
modal.php
<?php
if($_POST['value']){
$test = $_POST['value'];
include('db.php');
$sql = "SELECT subject FROM grade where name=".$value." ";
$res = mysqli_query($conn,$sql);
while($row = mysqli_fetch_assoc($res)){
echo "<input type='checkbox' name='subject[]' value='".$row['subject']."'>".$row['subject'];
echo "<br>";
}
}
?>
My problem is how to send selected checkbox values on the modal into the database?
Here are the way I tried.
new.js
$(document).ready(function(){
$("input[type=checkbox][name=name]").change(function(){
if(this.checked) {
var value = $(this).val();
$.ajax({
url:"modal.php",
type:"POST",
data:{test:value},
success:function(modalBody){
$("#myModal .modal-body").html(modalBody);
$("#myModal").modal('show');
}
});
}
});
$('#myModal submit').on('submit',function(){
var insert = [];
$('input[name=category[]]').each(function(){
if($(this).is(":checked")) {
insert.push($(this).val());
}
});
insert = insert.toString();
$.ajax({
url: "insert.php",
method: "POST",
data:{insert:insert},
success:function(data){
$('#result').html(data);
}
});
});
});
insert.php
<?php
if(isset($_POST["insert"])) {
include ('db.php');
$query = "INSERT INTO name_list(student_name) VALUES ('".$_POST["insert"]."')";
$result= mysqli_query($conn, $query);
echo "Data Inserted Successfully!";
}
?>
I tried a lot. Everytime name_list table fills with no values. can you help me to solve this?Again I want send selected checkbox values on the modal into database. Below values.
echo "<input type='checkbox' name='subject[]' value='".$row['subject']."'>"
First of all if there are more than one checkbox with the same name than the name must be an array like:
<form>
<input type="checkbox" name="bla[]" value="1" />
<input type="checkbox" name="bla[]" value="2" />
</form>
Now you can get there value in jquery like:
$(document).ready( function () {
$("input[name='bla[]']").each( function () {
if($(this).is(':checked'))
{
alert($(this).val());
// put this value in an array
}
});
});
Working Fiddle
this is my file php use jquery to send text from view to send_message.php based only for one id. i want change this code become send text from view to send_message.php to all id registered. you can see this code
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
});
function sendPushNotification(id){
var data = $('form#'+id).serialize();
$('form#'+id).unbind('submit');
$.ajax({
url: "send_message.php",
type: 'GET',
data: data,
beforeSend: function() {
},
success: function(data, textStatus, xhr) {
$('.txt_message').val("");
},
error: function(xhr, textStatus, errorThrown) {
}
});
return false;
}
</script>
</head>
<body>
<?php
include_once 'db_functions.php';
$db = new DB_Functions();
$users = $db->getAllUsers();
if ($users != false)
$no_of_users = mysql_num_rows($users);
else
$no_of_users = 0;
?>
<div class="container">
<h1>No of Devices Registered: <?php echo $no_of_users; ?></h1>
<hr/>
<ul class="devices">
<?php
if ($no_of_users > 0) {
?>
<?php
while ($row = mysql_fetch_array($users)) {
?>
<li>
<form id="<?php echo $row["id"] ?>" name="" method="post" onsubmit="return sendPushNotification('<?php echo $row["id"] ?>')">
<label>Name: </label> <span><?php echo $row["name"] ?></span>
<div class="clear"></div>
<label>Email:</label> <span><?php echo $row["email"] ?></span>
<div class="clear"></div>
<div class="send_container">
<textarea rows="3" name="message" cols="25" class="txt_message" placeholder="Type message here"></textarea>
<input type="hidden" name="regId" value="<?php echo $row["gcm_regid"]; ?>"/>
<input type="submit" class="send_btn" value="Send" onclick=""/>
</div>
</form>
</li>
<?php } ?>
<?php
} else { ?>
<li>
No Users Registered Yet!
</li>
<?php } ?>
</ul>
</div>
</body>
</html>
this code send input from "txt_message" to user based id and "gcm_regid" so one txt_message for one id, but i try to send same txt_message for multiple id. help me, thank yuo
I need a little help to send notification to all devices at once.
I know array need to be used for that but can't get the idea. A little hint will also work
DB table design
id gcm_regid name email created_at
Currently i have to fill out the form for all the devices and send notification one by one.
PHP code:
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"> </script>
<script type="text/javascript">
$(document).ready(function(){
});
function sendPushNotification(id){
var data = $('form#'+id).serialize();
$('form#'+id).unbind('submit');
$.ajax({
url: "send_message.php",
type: 'GET',
data: data,
beforeSend: function() {
},
success: function(data, textStatus, xhr) {
$('.txt_message').val("");
},
error: function(xhr, textStatus, errorThrown) {
}
});
return false;
}
</script>
</head>
<body>
<?php
include_once 'db_functions.php';
$db = new DB_Functions();
$users = $db->getAllUsers();
if ($users != false)
$no_of_users = mysql_num_rows($users);
else
$no_of_users = 0;
?>
<div class="container">
<h1>No of Devices Registered: <?php echo $no_of_users; ?></h1>
<hr/>
<ul class="devices">
<?php
if ($no_of_users > 0) {
?>
<?php
while ($row = mysql_fetch_array($users)) {
?>
<li>
<form id="<?php echo $row["id"] ?>" name="" method="post" onsubmit="return sendPushNotification('<?php echo $row["id"] ?>')">
<label>Name: </label> <span><?php echo $row["name"] ?></span>
<div class="clear"></div>
<label>Email:</label> <span><?php echo $row["email"] ?></span>
<div class="clear"></div>
<div class="send_container">
<textarea rows="3" name="message" cols="25" class="txt_message" placeholder="Type message here"></textarea>
<input type="hidden" name="regId" value="<?php echo $row["gcm_regid"] ?>"/>
<input type="submit" class="send_btn" value="Send" onclick=""/>
</div>
</form>
</li>
<?php }
} else { ?>
<li>
No Users Registered Yet!
</li>
<?php } ?>
</ul>
</div>
</body>
send_message.php
<?php
if (isset($_GET["regId"]) && isset($_GET["message"])) {
$regId = $_GET["regId"];
$message = $_GET["message"];
include_once './GCM.php';
$gcm = new GCM();
$registatoin_ids = array($regId);
$message = array("price" => $message);
$result = $gcm->send_notification($registatoin_ids, $message);
echo $result;
}
?>
EDIT: Or can anyone tell me how do i use checkbox for select all "id"s?
Hi really need some help...
First of all I know very little of jQuery / javascript, I learnt basic CSS a month back after having a website professionally built, then basic HTML, a few days ago I thought I would try my luck with jQuery but I am a total novis so if you answer please keep in mind I know almost nothing about these things - thanks!
I have been trying to make a new contact form, I have used bits of code from all over the net (so I know the code is probably very messy) anyway the resulting form seems to work fine in Chrome but in IE or FF or Safari on the submit it returns the 'Sorry, there has been a problem with this form' alert and nothing happens, I guess the PHP script is returning '1' to make this happen, but to be honest I am in over my head!
Below is the jquery....
$(function(){
//original field values
var field_values = {
//id : value
'firstname' : 'first name',
'lastname' : 'last name',
'email' : 'email address',
'phone' : 'phone number',
};
//inputfocus
$('input#lastname').inputfocus({ value: field_values['lastname'] });
$('input#firstname').inputfocus({ value: field_values['firstname'] });
$('input#email').inputfocus({ value: field_values['email'] });
$('input#phone').inputfocus({ value: field_values['phone'] });
//reset progress bar
$('#progress').css('width','0');
$('#progress_text').html('0% Complete');
//second_step
$('form').submit(function(){ return false; });
$('#submit_second').click(function(){
//remove classes
$('#second_step input').removeClass('error').removeClass('valid');
var emailPattern = /^[a-zA-Z0-9._-]+#[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;
var fields = $('#second_step input[type=text]');
var error = 0;
fields.each(function(){
var value = $(this).val();
if( value.length<1 || value==field_values[$(this).attr('id')] || ( $(this).attr('id')=='email' && !emailPattern.test(value) ) ) {
$(this).addClass('error');
$(this).effect("shake", { times:3 }, 50);
error++;
} else {
$(this).addClass('valid');
}
});
if(!error) {
//update progress bar
$('#progress_text').html('66% Complete');
$('#progress').css('width','226px');
//slide steps
$('#second_step').slideUp();
$('#third_step').slideDown();
} else return false;
});
$('#submit_third').click(function(){
//update progress bar
$('#progress_text').html('100% Complete');
$('#progress').css('width','339px');
//prepare the fourth step
var fields = new Array(
$('#firstname').val() + ' ' + $('#lastname').val(),
$('#email').val(),
$('#phone').val(),
$('#service').val(),
$('#location').val(),
$('#mirror').val(),
$('#from').val()
);
var tr = $('#fourth_step tr');
tr.each(function(){
//alert( fields[$(this).index()] )
$(this).children('td:nth-child(2)').html(fields[$(this).index()]);
});
//slide steps
$('#third_step').slideUp();
$('#fourth_step').slideDown();
});
$('#submit_fourth').click(function(){
//Get the data from all the fields
var firstname = $('input[name=firstname]');
var email = $('input[name=email]');
var lastname = $('input[name=lastname]');
var phone = $('input[name=phone]');
//organize the data properly
var data = 'firstname=' + firstname.val() + '&email=' + email.val() + '&lastname=' + lastname.val() + '&phone=' + phone.val() + '&service=' + $('select#service option:selected').val() + '&location=' + $('select#location option:selected').val() + '&mirror=' + $('select#mirror option:selected').val() + '&leadfrom=' + $('select#from option:selected').val();
//start the ajax
$.ajax({
//this is the php file that processes the data and send mail
url: "process.php",
//GET method is used
type: "GET",
//pass the data
data: data,
//Do not cache the page
cache: false,
//success
success: function (html) {
//if process.php returned 1/true (send mail success)
if (html==1) {
//hide the form
$('.summary').fadeOut('slow');
//show the success message
$('.success').fadeIn('slow');
$('#submit_fourth').attr("disabled", true);
window.location = "http://www.stackoverflow.com";
//if process.php returned 0/false (send mail failed)
} else alert('Sorry, there has been a problem with this form. Thank you');
}
});
//cancel the submit button default behaviours
return false;
});
//back button
$('.back').click(function(){
var container = $(this).parent('div'),
previous = container.prev();
switch(previous.attr('id')) {
case 'first_step' : $('#progress_text').html('0% Complete');
$('#progress').css('width','0px');
break;
case 'second_step': $('#progress_text').html('33% Complete');
$('#progress').css('width','113px');
break;
case 'third_step' : $('#progress_text').html('66% Complete');
$('#progress').css('width','226px');
break;
default: break;
}
$(container).slideUp();
$(previous).slideDown();
});
});
and the HTML...
<div class="outer-formbody">
<div class="formbody">
Close
<div id="container">
<form action="#" method="post">
<!-- #second_step -->
<div id="second_step">
<h3>Book your appointment</h3>
<div class="form">
<input type="text" name="firstname" id="firstname" value="first name" />
<label for="firstname">Your First Name.<span>*</span></label><!-- clearfix --><div class="clear"></div><!-- /clearfix -->
<input type="text" name="lastname" id="lastname" value="last name" />
<label for="lastname">Your Last Name.<span>*</span></label><!-- clearfix --><div class="clear"></div><!-- /clearfix -->
<input type="text" name="email" id="email" value="email address" />
<label for="email">Your email address (not shared).<span>*</span></label> <!-- clearfix --><div class="clear"></div><!-- /clearfix -->
<input type="text" name="phone" id="phone" value="phone number" />
<label for="email">Your contact number (not shared).<span>*</span></label>
</div> <!-- clearfix --><div class="clear"></div><!-- /clearfix -->
<input class="submit" type="submit" name="submit_second" id="submit_second" value="" />
</div>
<!-- #third_step -->
<div id="third_step">
<h3>Book your appointment</h3>
<div class="form">
<select id="service" name="service" class="required">
<option value="">Please Select</option>
<option>Power of Attorney</option>
<option>Property Trust</option>
<option>Disabled Trust</option>
<option>Discretionary Trust</option>
<option>Other Trust</option>
<option>Protection / Insurance</option>
<option>Other Service</option>
</select>
<label for="service">Select the service you require.<span>*</span></label> <!-- clearfix --><div class="clear"></div><!-- /clearfix -->
<select id="location" name="location" class="required">
<option value="">Please Select</option>
<option>Staffordshire</option>
<option>Shropshire</option>
<option>West Midlands</option>
<option>Shropshire</option>
<option>Leicestershire</option>
<option>Birmingham</option>
<option>Cheshire</option>
<option>Other</option>
</select>
<label for="location">Select your home county.<span>*</span></label> <!-- clearfix --><div class="clear"></div><!-- /clearfix -->
<select id="mirror" name="mirror" class="required">
<option value="">Please Select</option>
<option>Single</option>
<option>Couple</option>
</select>
<label for="country">Single or two documents (for a couple).<span>*</span></label> <!-- clearfix --><div class="clear"></div><!-- /clearfix -->
<select id="from" name="from" class="required">
<option value="">Please Select</option>
<option>NHS/School/Council</option>
<option>Friend/Family Member</option>
<option>Other Public Sector Employer</option>
<option>Private Sector Employer</option>
<option>Internet Advert</option>
<option>Google</option>
<option>Newspaper</option>
<option>NetMums</option>
<option>MumsNet</option>
<option>Other</option>
</select>
<label for="from">Where did you hear about us?<span>*</span></label>
</div><!-- clearfix --><div class="clear"></div><!-- /clearfix -->
<input class="back" type="button" value="" />
<input class="submit" type="submit" name="submit_third" id="submit_third" value="" />
</div>
<!-- #fourth_step -->
<div id="fourth_step">
<h3>Book your appointment</h3>
<div class="form">
<div class="success">
</br>
</br>
</br>
</br>
</br>
<h3>Booking Submitted. <span>Please Wait . . .</span></h3>
</div>
<div class="summary">
<h3>Summary</h3>
<table class="table">
<tr><td>Name</td><td></td></tr>
<tr><td>Email</td><td></td></tr>
<tr><td>Phone</td><td></td></tr>
<tr><td>Service</td><td></td></tr>
<tr><td>Location</td><td></td></tr>
<tr><td>Single/Couple</td><td></td></tr>
<tr><td>From</td><td></td></tr>
</table>
</div>
</div> <!-- clearfix --><div class="clear"></div><!-- /clearfix -->
<input class="back" type="button" value="" />
<input class="send submit" type="submit" name="submit_fourth" id="submit_fourth"value="" />
</div>
</form>
</div>
<div id="progress_bar">
<div id="progress"></div>
<div id="progress_text">0% Complete</div>
</div>
<div></div>
</div></div>
</div>
and the PHP script to process the form....
<?php
//Retrieve form data.
//GET - user submitted data using AJAX
//POST - in case user does not support javascript, we'll use POST instead
$firstname = ($_GET['firstname']) ? $_GET['firstname'] : $_POST['firstname'];
$email = ($_GET['email']) ?$_GET['email'] : $_POST['email'];
$lastname = ($_GET['lastname']) ?$_GET['lastname'] : $_POST['lastname'];
$phone = ($_GET['phone']) ?$_GET['phone'] : $_POST['phone'];
$service = ($_GET['service']) ?$_GET['service'] : $_POST['service'];
$location = ($_GET['location']) ?$_GET['location'] : $_POST['location'];
$mirror = ($_GET['mirror']) ?$_GET['mirror'] : $_POST['mirror'];
$leadfrom = ($_GET['leadfrom']) ?$_GET['leadfrom'] : $_POST['leadfrom'];
//flag to indicate which method it uses. If POST set it to 1
if ($_POST) $post=1;
//if the errors array is empty, send the mail
if (!$errors) {
//recipient
$to = 'Alex <clansey2004#yahoo.co.uk>';
//sender
$from = $firstname . ' <' . $email . '>';
//subject and the html message
$subject = 'Lead from ' . $firstname;
$message = '
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head></head>
<body>
</Br>
<table>
<tr><td>First Name</td><td>' . $firstname . '</td></tr>
<tr><td>Lastname</td><td>' . $lastname . '</td></tr>
<tr><td>Location</td><td>' . $location . '</td></tr>
<tr><td>Email</td><td>' . $email . '</td></tr>
<tr><td>Phone</td><td>' . $phone . '</td></tr>
<tr><td>Service</td><td>' . $service . '</td></tr>
<tr><td>Mirror</td><td>' . $mirror . '</td></tr>
<tr><td>Lead From</td><td>' . $leadfrom . '</td></tr>
</table>
</body>
</html>';
//send the mail
$result = sendmail($to, $subject, $message, $from);
//if POST was used, display the message straight away
if ($_POST) {
if ($result) echo 'Thank you! We have received your message.';
else echo 'Sorry, unexpected error. Please try again later';
//else if GET was used, return the boolean value so that
//ajax script can react accordingly
//1 means success, 0 means failed
} else {
echo $result;
}
//if the errors array has values
} else {
//display the errors message
for ($i=0; $i<count($errors); $i++) echo $errors[$i] . '<br/>';
echo 'Back';
exit;
}
//Simple mail function with HTML header
function sendmail($to, $subject, $message, $from) {
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
$headers .= 'From: ' . $from . "\r\n";
$result = mail($to,$subject,$message,$headers);
if ($result) return 1;
else return 0;
}
?>
I am sure I have made a silly mistake - any help would be greatly appreciated!!
Thanks
My guess is you need to urlescape the values with encodeURIComponent(), especially those with a slash inside.