My html form isn't submitting an email [closed] - javascript

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 6 years ago.
Improve this question
I have a landing page (http://www.interiorswithaview.com/) that requires name, address, and phone#. After you submit the form directed to a thank you page with downloads: http://www.interiorswithaview.com/ThankYou.html
I also use a javascript (see below). I've used this template set in the past and I know its worked but now its not sending an email. I don't know if its outdated? Please help.
<script src="mail-form.js"></script>
<form method="POST" action="mailer.php" onsubmit="return ValidateRequiredFields();" name="mail">
<table width="235" height="400" border="0" bgcolor="#d1d3d4" align="center" cellpadding="0" cellspacing="0" style="font-size:13px; font-weight:bold; color:#58585b; padding:5px;">
<tbody>
<tr><td colspan="3"><img src="images/Form-header.png" width="200" height="63" alt="" align="center"/></td></tr>
<tr>
<td colspan="3">
<p align="center" style="padding:0 8px 0 8px;"><strong>Here are three informational guides to help you get started! To download these resources, just enter your information below.</strong></p>
<p>
<ul style="list-style: none; font-size: 16px; color: #d83e45;">
<li>Q & A</li>
<li>Case Study</li>
<li>Color Consultation</li>
</ul>
</p>
</td>
</tr>
<tr>
<td width="55" height="30" align="right" style="padding-right:6px;">Name:</td>
<td width="163" align="right">
<input name="Name" type="text" id="Name" size="23">
</td>
</tr>
<tr>
<td height="30" align="right" style="padding-right:6px;">Address:</td>
<td align="right"><input name="Address" type="text" id="Address" size="23"></td>
</tr>
<tr>
<td height="30" align="right" style="padding-right:6px;">Phone:</td>
<td align="right"><input name="Phone" type="text" id="Phone" size="23"></td>
</tr>
<tr>
<td height="5" align="right" style="padding-right:6px;"> </td>
<td align="right"> </td>
</tr>
<tr>
<td height="5" align="right" style="padding-right:6px;"> </td>
<td align="right"><input type="submit" name="submit" id="submit" value="Submit" /></td>
<td width="1"></td>
</tr>
</tbody>
</table>
</form>
PHP Code
<?php
if(isset($_POST['submit'])) {
$email_to = "email#gmail.com";
$subject = "New Landing Page Consult Lead";
$name_field = $_POST['Name'];
$address_field = $_POST['Address'];
$phone_field = $_POST['Phone'];
$body = "From: $name_field\n Address: $address_field\n Phone: $phone_field\n";
header('Location: ThankYou.html');
exit();
mail($to, $subject, $body, "From: $name_field");
}
else {
echo "what?";
}
?>
JavaScript
var FormName = "mail";
var RequiredFields = "Name,Phone,Address";
function ValidateRequiredFields() {
var FieldList = RequiredFields.split(",");
var BadList = new Array();
for(var i = 0; i < FieldList.length; i++) {
var s = eval('document.' + FormName + '.' + FieldList[i] + '.value');
s = StripSpacesFromEnds(s);
if(s.length < 1) {
BadList.push(FieldList[i]);
}
}
if(BadList.length < 1) {
return true;
}
var ess = new String();
if(BadList.length > 1) {
ess = 's';
}
var message = new String('\n\nThe following field' + ess + ' are required:\n');
for(var i = 0; i < BadList.length; i++) {
message += '\n' + BadList[i];
}
alert(message);
return false;
}
function StripSpacesFromEnds(s) {
while((s.indexOf(' ',0) == 0) && (s.length> 1)) {
s = s.substring(1,s.length);
}
while((s.lastIndexOf(' ') == (s.length - 1)) && (s.length> 1)) {
s = s.substring(0,(s.length - 1));
}
if((s.indexOf(' ',0) == 0) && (s.length == 1)) {
s = '';
}
return s;
}

Put the exit after the mail
header('Location: ThankYou.html');
mail($to, $subject, $body, "From: $name_field");
exit();

Try this!
Change your php code!
<?php
if(isset($_POST['submit'])) {
$email_to = "email#gmail.com";
$subject = "New Landing Page Consult Lead";
$name_field = $_POST['Name'];
$address_field = $_POST['Address'];
$phone_field = $_POST['Phone'];
$body = "From: $name_field\n Address: $address_field\n Phone: $phone_field\n";
mail($to, $subject, $body, "From: $name_field");
header('Location: ThankYou.html');
exit();
}
else {
echo "what?";
}
?>

Related

Take user id from php for change password

I have this code for change password on the personal page of the user on my website. The script working but the problem is that work's only on id "60". how I can take the id from the page and set in this code? my page is like this "www.example.com/area-personale.php?id=60". and why the script start immediately when I enter on the page and i prefer that it starts when I press on submit.
</script>
</head>
<body>
<form name="frmChange" method="post" action=""
onSubmit="return validatePassword()">
<div style="width: 500px;">
<div class="message"><?php if(isset($message)) { echo $message; } ?></div>
<table border="0" cellpadding="10" cellspacing="0"
width="500" align="center" class="tblSaveForm">
<tr class="tableheader">
<td colspan="2">Change Password</td>
</tr>
<tr>
<td width="40%"><label>Current Password</label></td>
<td width="60%"><input type="password"
name="currentPassword" class="txtField" /><span
id="currentPassword" class="required"></span></td>
</tr>
<tr>
<td><label>New Password</label></td>
<td><input type="password" name="newPassword"
class="txtField" /><span id="newPassword"
class="required"></span></td>
</tr>
<td><label>Confirm Password</label></td>
<td><input type="password" name="confirmPassword"
class="txtField" /><span id="confirmPassword"
class="required"></span></td>
</tr>
<tr>
<td colspan="2"><input type="submit" name="submit"
value="Submit" class="btnSubmit"></td>
</tr>
</table>
</div>
</form>
</body>
</html>
<?php
session_start();
$_SESSION["id_user"] = "60";
$conn = mysqli_connect("x", "x", "x", "x") or die("Connection Error: " . mysqli_error($conn));
?>
<?php
if (count($_POST) > 0) {
$result = mysqli_query($conn, "SELECT password FROM vm_users WHERE id_user='" . $_SESSION["id_user"] . "'");
$row = mysqli_fetch_array($result);
if ($_POST["currentPassword"] == $row["password"]) {
mysqli_query($conn, "UPDATE vm_users set password='" . $_POST["newPassword"] . "' WHERE id_user='" . $_SESSION["id_user"] . "'");
$message = "Password modificata";
} else
$message = "Current Password is not correct";
}
?>
<html>
<head>
<title>Change Password</title>
<link rel="stylesheet" type="text/css" href="styles.css" />
<script>
function validatePassword() {
var currentPassword,newPassword,confirmPassword,output = true;
currentPassword = document.frmChange.currentPassword;
newPassword = document.frmChange.newPassword;
confirmPassword = document.frmChange.confirmPassword;
if(!currentPassword.value) {
currentPassword.focus();
document.getElementById("currentPassword").innerHTML = "required";
output = false;
}
else if(!newPassword.value) {
newPassword.focus();
document.getElementById("newPassword").innerHTML = "required";
output = false;
}
else if(!confirmPassword.value) {
confirmPassword.focus();
document.getElementById("confirmPassword").innerHTML = "required";
output = false;
}
if(newPassword.value != confirmPassword.value) {
newPassword.value="";
confirmPassword.value="";
newPassword.focus();
document.getElementById("confirmPassword").innerHTML = "not same";
output = false;
}
return output;
}
I used this and now works!
$_SESSION["id_user"] = $_GET["id"]

How do I redirect a form after submission to the same page?

I want my form to be submitted, after submitting that values it should redirect to the form and display the values. I've tried many things... but no luck yet...
So I've decided to post here. It should be like most of the edit fields, the stored value or the submitted value should appear.
This is my code:
<form method="post" name="contentUpload" action="insertContent.php" enctype="multipart/form-data">
<table>
<tr id="small">
<td>Category</td>
<td>
<select name="contentCategory">
<<option value="1">World</option>
<option value="2">Health/Env/Scn</option>
<option value="3">Travel</option>
</select>
</td>
</tr>
<tr id="small">
<td>Title</td>
<td>
<input type="text" name="contentTitle" size="80">
</td>
</tr>
<tr id="small">
<td>Writer</td>
<td>
<input type="text" name="writer" size="80">
</td>
</tr>
<tr id="small">
<td>Upload Picture</td>
<td>
<input type="file" name="fileToUpload" id="fileToUpload">
</td>
</tr>
<tr>
<td id="small">Display Mode</td>
<td required>
<input type="radio" name="status" value="Online" /> Online
<input type="radio" name="status" value="Offline" /> Offline
</td>
</tr>
<tr>
<td id="small">Final Submission</td>
<td>
<input type="submit" name="submitContent" value="Update">
<input type="reset" name="resetContent" value="Reset">
</td>
</tr>
</table>
</form>
</div>
this is my addcontent.php
<?php include ( "./inc/connect.inc.php" ); ?>
<?php
session_start();
$target_dir = "new/Images/";
$file_name = $_FILES["fileToUpload"]["name"];
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
$uploadOk = 1;
$imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
if(isset($_POST["submitContent"]))
{
$check = getimagesize($_FILES["fileToUpload"]["tmp_name"]);
if($check !== false)
{
echo "File is an image - " . $check["mime"] . ".";
$uploadOk = 1;
}
else
{
echo "File is not an image.";
$uploadOk = 0;
}
}
// Check if $uploadOk is set to 0 by an error
if ($uploadOk == 0)
{
echo "Sorry, your file was not uploaded.";
// if everything is ok, try to upload file
}
else
{
if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file))
{
echo "The file ". basename( $_FILES["fileToUpload"]["name"]). " has been uploaded.";
}
else
{
echo "Sorry, there was an error uploading your file.";
}
}
if (isset($_POST['submitContent']))
{
$eid = $_SESSION['employeeId'];
$contentCategory = $_POST['contentCategory'];
$contentTitle = $_POST['contentTitle'];
$contentWriter = $_POST['writer'];
$displayMode = $_POST['status'];
$query = mysqli_query($con,"INSERT INTO contentdetails(employeeId,contentCategory,contentTitle,contentWriter,photo,displayMode,published_on)
VALUES('$eid','$contentCategory','$contentTitle','$contentWriter',
'$file_name','$displayMode',NOW())");
}
?>
in your form tag leave the action="" tag empty.
<?php
// Remove session_start() from this file. It should be before any html.
include 'insertContent.php';
if (isset($_POST['submitContent'])) {
foreach ($_POST as $p) {
echo $p . "<br>";
}
}
?>
<form method="post" name="contentUpload" action="" enctype="multipart/form-data">

My javascript validation just stopped working and I can't figure out why

I have been developing this page for a few days for a school project and it has been working perfectly up until about 10 minutes ago. I didn't change anything except adding an extra javascript validation. Now when I run my page and click "register" button, it registers with empty fields instead of popping up the appropriate alerts. Please help!
<?php
//Connect to database
include("dbconnect.php");
// SQL insertion if submit button is pressed
if (isset($_POST['Submit'])) {
$firstname = $_POST["firstname"];
$lastname = $_POST["lastname"];
$email = $_POST["email"];
$username = $_POST["username"];
$password1 = $_POST["password1"];
$class1 = $_POST["class1"];
$address = $_POST["address"];
$creditcard = $_POST["creditcard"];
$expiry = $_POST["expiry"];
$cvv = $_POST["cvv"];
$postcode = $_POST["postcode"];
$city = $_POST["city"];
$state = $_POST["state"];
$street = $_POST["street"];
$personcon = $conn;
$bbsSQL = "INSERT INTO TBLUSERS (FIRSTNAME, LASTNAME, EMAIL, USERNAME, PASSWORD, CLASS, ADDRESS, CREDITCARD, EXPIRY, CVV, POSTCODE, CITY, STATE, STREET) VALUES ('$firstname', '$lastname', '$email', '$username', '$password1', '$class1', '$address', '$creditcard', '$expiry', '$cvv', '$postcode', '$city', '$state', '$street')";
$personinfo = oci_parse($personcon, $bbsSQL);
oci_execute($personinfo);
oci_free_statement($personinfo);
oci_close($personcon);
//Send Email
$to = $email;
$subject = 'Registration Confirmation';
$message = 'Welcome, ' . $firstname . ' ' . $lastname . '.' . "\r\n" . "\r\n" . 'Username: ' . $username . "\r\n" . "\r\n" . 'Password: ' . $password1 . "\r\n" . "\r\n" . 'Class: ' . $class1 . "\r\n" . "\r\n";
$headers = 'From: fake#fake.com' . "\r\n" . 'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
//Pass the message to the login page after registration
$Message = urlencode("Thank you for your registration!");
header("Location:index.php?Message=" . $Message);
}
?>
<html>
<head>
<title>User Registration</title>
<link rel="stylesheet" type="text/css" href="style.css" />
<script type="text/javascript">
function validate()
{
//First Name
var fname = document.myForm.firstname.value;
var Vfname = /^[a-zA-Z]+$/;
if(!Vfname.test(fname)){
alert("Your last name can only contain letters.");
return false;
} else {
/* alert("Valid first name!"); */
}
//Last Name
var Lname = document.myForm.lastname.value;
var VLname = /^[a-zA-Z]+$/;
if(!VLname.test(Lname)){
alert("Your last name can only contain letters.");
return false;
} else {
/* alert("Valid last name!"); */
}
//Class
var cl = document.myForm.class1.value;
var Vcl = /^[a-zA-Z]{4}+[0-9]{3}+$/;
if (!Vcl.test(cl)){
alert("Your class must be 4 letters followed by 3 numbers.");
return false;
} else {
/* alert("Valid class!"); */
}
//Credit Card
var cc = document.myForm.creditcard.value;
var Vcc = /^[0-9]{10}+$/;
if (!Vcc.test(cc)) {
alert("Credit card number must be 10 digits.");
return false;
} else {
/* alert("Valid Credit Card!"); */
}
//Post Code
var pc = document.myForm.postcode.value;
var Vpc = /^[0-9]{4}+$/;
if (!Vpc.test(pc)) {
alert("Post code must be 4 numbers.");
return false;
} else {
/* alert("Valid Post Code!"); */
}
//Password Confirmation
var pwd1 = document.myForm.password1.value;
var pwd2 = document.myForm.password2.value;
if(pwd1!=pwd2 || pwd1=="" || pwd2==""){
alert("Password unmatched!");
return false;
}
else
alert("Password matched!");
}
}
</script>
</head>
<body>
<div class="author">
COMP344 Assignment 1 2015 <br>
Daniel Buskariol <br>
42446937
</div>
<div id="heading"> New Star Public School </div>
<br>
<form name="myForm" method="POST" onsubmit="return validate()">
<table style="width:40%" cellpadding="10" cellspacing="1" align="center">
<tr>
<th colspan="4">Enter Registration Details</th>
</tr>
<tr>
<td colspan="4"></td>
</tr>
<tr>
<td>First Name</td>
<td><input type="text" name="firstname" tabindex="1" /></td>
<td>Post Code</td>
<td><input type="text" name="postcode" tabindex="9" /></td>
</tr>
<tr>
<td>Last Name</td>
<td><input type="text" name="lastname" tabindex="2" /></td>
<td>Credit Card</td>
<td><input type="text" name="creditcard" tabindex="10" /></td>
</tr>
<tr>
<td>Email</td>
<td><input type="text" name="email" tabindex="3" /></td>
<td>Expiry</td>
<td><input type="text" name="expiry" tabindex="11" placeholder="MM/YY" /></td>
</tr>
<tr>
<td>Class</td>
<td><input type="text" name="class1" tabindex="4" /></td>
<td>CVV</td>
<td><input type="text" name="cvv" tabindex="12" /></td>
</tr>
<tr>
<td>Street Number</td>
<td><input type="text" name="address" tabindex="5" /></td>
<td>Username</td>
<td><input type="text" name="username" tabindex="13" /></td>
</tr>
<tr>
<td>Street Name</td>
<td><input type="text" name="street" tabindex="6" /></td>
<td>Password</td>
<td><input type="password" name="password1" tabindex="14" /></td>
</tr>
<tr>
<td>Suburb/City</td>
<td><input type="text" name="city" tabindex="7" /></td>
<td>Confirm</td>
<td><input type="password" name="password2" tabindex="15" /></td>
</tr>
<tr>
<td>State</td>
<td><input type="text" name="state" tabindex="8" /></td>
<td align="right"><input type="reset" name="Reset"/> </td>
<td><input type="submit" name="Submit" value="Register"/></td>
</tr>
</table>
</form>
<br>
<p> Already a member? Click here to login. </p>
</body>
</html>
Open up your developer console and it will point you to the error.
You have an extra { because you missed a { after the else. So either add a { or remove the extra }.
The regular expression is wrong because you have a + after the {3} and after the {4}. Get rid of them.
In a few places, you put a + quantifier in a regex after already providing an explicit count, e.g. var Vcl = /^[a-zA-Z]{4}+[0-9]{3}+$/; ({4}+ and {3}+). That's not legal in a regular expression. If you checked your browser console, you'd probably see a SyntaxError when the validation is performed.

How To Integrate Codeigniter Form Validation Library and file uploading in a form using jQuery AJAX ?

this is my controller file
below code is working only file uploading into path and no data is displaying in database when i gave inputs. Another doubt, It is not showing validation errors when i submit with empty inputs.
var $default_news_status = 1;
var $default_client_status = 1;
var $default_client_partner_flag = 0;
var $default_client_logo_display_flag = 1;
var $default_client_test_status = 0;
public function construct()
{
parent::__construct();
$this->load->helper(array('form', 'url', 'file'));
}
/*controlles vadmin/addnews*/
public function addnews()
{
//$status = "";
//$msg = "";
$userfile = 'userfile';
//echo '<br>entered into ajax if block.. ';
/******* extracting file extension ********/
$org_filename = $_FILES['userfile']['name'];
$path_parts = pathinfo($org_filename);
//$file_extension = $path_parts['extension'];
/***** end extracting file extension ******/
$this->load->library('form_validation');
$this->form_validation->set_rules('title', 'Title', 'trim|required|min_length[5]');
$this->form_validation->set_rules('description', 'Description', 'trim|required');
$this->form_validation->set_rules('url', 'URL', 'trim|required');
$this->form_validation->set_rules('userfile', 'Image', 'trim');
$this->form_validation->set_rules('postedon', 'Posted On', 'trim|required');
$this->form_validation->set_rules('source', 'Source','trim|required|min_length[5]|max_length[12]');
$this->form_validation->set_rules('expiredate', 'Expire Date', 'trim|required');
if($this->form_validation->run() == FALSE)
{
echo json_encode(array('status'=>0, 'msg' => validation_errors()));
}
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = 1024 * 1000;
//$config['file_name'] = 'client_'.time().'.'.$file_extension;
//echo "<pre>";
//print_r($_FILES);
$this->load->library('upload', $config);
if (!$this->upload->do_upload($userfile))
{
echo '<br>entered into upload failed block.. ';
$error = array('error' => $this->upload->display_errors());
echo json_encode($error);
}
else
{
echo '<br>entered into upload success block.. ';
/*$data = $this->upload->data();
echo "<pre>";
print_r($data);*/
/**** assignment of post data ******/
$title = $this->input->post('title');
$description = $this->input->post('description');
$url = $this->input->post('url');
$userfile = $this->input->post('userfile');
$postedon = $this->input->post('postedon');
$source = $this->input->post('source');
$expiredate = $this->input->post('expiredate');
$status = $this->default_news_status ;
/**** end assignment of post data ******/
/**** load news model to insert reocrd into table *****/
$this->load->model('vadmin/Newsmodel','',true);
$this->Newsmodel->addRequestForm();
/**** load news model to insert reocrd into table *****/
//print jsone response for ajax request
echo json_encode(array('status'=>0, 'msg' => 'Successfully Submitted'));
}
}
here is my view form
and js file is given below
<form method="post" action="" name="newsform" id="newsform" enctype= "multipart/form-data" >
<input type="hidden" value="" id="id" name="id" required="true">
<table width="580" cellpadding="5" cellspacing="5">
<tr>
<td width="130" align="left"><span class="required">*</span>Title</td>
<td align="left"><input name="title" type="text" id="title" style="width:250px;" value="<?php echo $news_title; ?>"/></td>
</tr>
<tr>
<td width="130" align="left"><span class="required">*</span>Description</td>
<td align="left"><textarea name="description" rows="8" cols="40" id="description" style="width:250px;" ><?php echo $news_description; ?></textarea></td>
</tr>
<tr>
<td width="130" align="left"><span class="required">*</span>URL</td>
<td align="left"><input name="url" type="text" id="url" style="width:250px;" value="<?php echo $news_url; ?>" /></td>
</tr>
<tr>
<td width="130" align="left"><span class="required">*</span>Image</td>
<td align="left"><input name="userfile" type="file" id="userfile" style="width:250px;" value="<?php echo $news_image; ?>" /></td>
<tr>
<td width="130" align="left"><span class="required">*</span>Posted On</td>
<td align="left"><input name="postedon" id="datepicker" style="width:250px;" value="<?php echo $news_posted_on; ?>" /></td>
</tr>
<tr>
<td width="130" align="left"><span class="required">*</span>Source</td>
<td align="left"><input name="source" type="text" id="source" style="width:250px;" value="<?php echo $news_source; ?>" /></td>
</tr>
<tr>
<td width="130" align="left"><span class="required">*</span>Expire Date</td>
<td align="left"><input name="expiredate" id="datepicker1" style="width:250px;" value="<?php echo $news_expire_date; ?>"/></td>
</tr>
<td colspan="2" align="left"><input type="submit" value="Submit" id="submit" onclick="return ajaxFileUpload();" />
<input type="reset" value ="reset" id="reset" /><span id="loading" >Please wait ..</span></td>
</tr>
</table>
<input type="hidden" name="nid" id="nid" value="<?php echo $news_id; ?>" />
</form>
here is my script
$.ajaxFileUpload
(
{
url:'<?php echo base_url();?>vadmin/ajax/addnews/',
secureuri:false,
fileElementId:'userfile',
dataType: 'json',
data: $("#newsform").serialize(),
beforeSend:function()
{
$("#loading").show();
},
complete:function()
{
$("#loading").hide();
},
success: function (resp)
{
if(resp.status == 0)
{
$('#message').css('color','red');
$('#message').html(resp.error).show(400);
}
if(resp.status == 1)
{
$('#message').css('color','green');
$('#message').html(resp.msg).show(400);
}
if(typeof(resp.error) != 'undefined')
{
if(resp.error != '')
{
alert(resp.error);
}else
{
alert(resp.msg);
}
}
},
/*error: function (resp, status, e)
{
alert('ajax error :: '+e);
} */
}
);
try like this
$data = $this->upload->data(); //remove comment
/*echo "<pre>";
print_r($data);*/
/**** assignment of post data ******/
$title = $this->input->post('title');
$description = $this->input->post('description');
$url = $this->input->post('url');
$userfile = $data['file_name']; // add this line
$postedon = $this->input->post('postedon');
$source = $this->input->post('source');
$expiredate = $this->input->post('expiredate');
$status = $this->default_news_status ;
for error try like this
if($this->form_validation->run() == FALSE)
{
echo json_encode(array('status'=>0, 'msg' => validation_errors()));
exit;
}

javascript checkbox select all, unselect all, invert selection

I meet a problem with a script i'm doing. actually I gave something like that because I'm doing a mail box for my intranet.
<script type="text/javascript">
function GereChkbox(conteneur, a_faire) {
var blnEtat=null;
var Chckbox = document.getElementById('box-table-a').firstChild;
while (Chckbox!=null) {
if (Chckbox.nodeName=="INPUT")
if (Chckbox.getAttribute("type")=="checkbox") {
blnEtat = (a_faire=='0') ? false : (a_faire=='1') ? true : (document.getElementById(Chckbox.getAttribute("id")).checked) ? false : true;
document.getElementById(Chckbox.getAttribute("id")).checked=blnEtat;
}
Chckbox = Chckbox.nextSibling;
}
}
</script><form>
<table width="100%" border="0" id='box-table-a'>
<tr>
<th scope="col" width="15%"><strong>Expéditeur</strong></th>
<th scope="col" width="60%"><strong>Message</strong></th>
<th scope="col" width="10%"><strong>Date</strong></th>
<th scope="col" width="15%"><strong>Actions</strong></th>
</tr><?php $sql="SELECT * FROM `messages` WHERE `id_destinataire`='".$_SESSION['login']."' AND `trash`='0' ORDER BY id DESC LIMIT ".$premiereEntree.", ".$messagesParPage."" ;
$result=mysql_query($sql) or die(__LINE__.mysql_error().$sql);
$i=0;
while($data=mysql_fetch_assoc($result)) { ?>
<tr>
<td align="left"><?php $req="SELECT * FROM `gestionnaire` WHERE `login`='".$data['id_expediteur']."'";
$result2=mysql_query($req) or die(__LINE__.mysql_error().$req);
$expediteur=mysql_fetch_assoc($result2); ?><img src="<?php if (!empty($expediteur['urlavatar'])) {echo $expediteur['urlavatar']; } else {echo "images/noAvatar.gif" ;} ; ?>" width="50px" height="50px" /><br /><?php echo $expediteur['nom'].' '.$expediteur['prenom'] ; ?></td>
<td><?php if($data['lu']=='0') { echo '<p align="left"><img src="images/Gnome-Mail-Unread-32.png" width="24px" height="24px" /><strong> '.$data['titre'].'</strong></p>';
$nbChar = 150; // Nb. de caractères sans '...'
if(strlen($data['message']) >= $nbChar)
$message = substr($data['message'], 0, $nbChar).' [...]';
echo '<p align="left"><i>'.$message.'</i></p>';
}
else { echo '<p align="left"><img src="images/Gnome-Emblem-Mail-32.png" width="24px" height="24px" /><strong> '.$data['titre'].'</strong></p>';
$nbChar = 150; // Nb. de caractères sans '...'
if(strlen($data['message']) >= $nbChar)
$message = substr($data['message'], 0, $nbChar).' [...]';
echo '<p align="left"><i>'.$message.'</i></p>';} ;
?></td>
<td><?php echo date('d-m-Y H:i',strtotime($data["date"])) ; ?></td>
<td><img src="images/email_open.png" alt="Lire le message" width="24px" height="24px" border="0" /> <img src="images/Gnome-Mail-Forward-32.png" alt="Transférer le message" width="24px" height="24px" border="0" /> <img src="images/mail-trash.png" alt="Supprimer ce message" width="24px" height="24px" border="0" /> <input type="checkbox" name="action[<?php echo ++$i; ?>]" id="checkbox<?php echo $i; ?>" /></td>
</tr>
<?php } ; ?>
</table>
<table width="100%" border="0">
<tr>
<td>Actions: <input type="button" value="Tout cocher" onClick="GereChkbox('div_chck','1');">
<input type="button" value="Tout décocher" onClick="GereChkbox('div_chck','0');">
<input type="button" value="Inverser la sélection" onClick="GereChkbox('div_chck','2');"></td>
<td> </td>
</tr>
</table>
</form>
In fact it does not really work because of the script and I have no error messages in the console.
Thank you verry much in advance for your help.
Kind regards.
Anyway, here's a function that toggles / checks / unchecks any checkboxes given to it:
function changeCheckboxes(list, value){
for(var i = list.length - 1 ; i >=0 ; i--){
list[i].checked = (typeof value === 'boolean') ? value : !list[i].checked ;
}
}
It accepts a nodelist or array of checkboxes as the first parameter. Use it as follows...
Toggle Checkboxes:
changeCheckboxes(allCheckboxes);
Check Checkboxes:
changeCheckboxes(allCheckboxes, true);
Uncheck Checkboxes:
changeCheckboxes(allCheckboxes, false);
To get allCheckboxes, you can do this:
var inputs = document.getElementsByTagName('input');
var allCheckboxes = [] ;
for (var j = inputs.length-1 ; j >= 0 ; j--){
if (inputs[j].type === 'checkbox'){
allCheckboxes.push(inputs[j]);
}
}

Categories

Resources