I can not make a formcontact working - contacts

I am a beginner , i try to make my website and i encountered a problem with my contacting form. What i want to know if i make something wrong with what i doing or is a problem from my host.
I have this form:
<div id="frmdiv_cform">
<script src="../code.jquery.com/jquery-1.10.1.min.js" tppabs="http://code.jquery.com/jquery-1.10.1.min.js"></script>
<script>
$("#contactForm").submit(function(event)
{
/* stop form from submitting normally */
event.preventDefault();
/* get some values from elements on the page: */
var $form = $( this ),
$submit = $form.find( 'button[type="submit"]' ),
name_value = $form.find( 'input[name="name"]' ).val(),
email_value = $form.find( 'input[name="email"]' ).val(),
message_value = $form.find( 'textarea[name="message"]' ).val(),
car1_value = $form.find( 'input[name="car1"]' ).val(),
car2_value = $form.find( 'input[name="car2"]' ).val(),
whereused_value = $form.find( 'input[name="whereused"]' ).val(),
phone_value = $form.find( 'input[name="phone"]' ).val(),
whenrequired_value = $form.find( 'input[name="whenrequired"]' ).val(),
url = $form.attr('action');
/* Send the data using post */
var posting = $.post( url, {
name: name_value,
email: email_value,
message: message_value,
car1: car1_value,
car2: car2_value,
whereused: whereused_value,
phone: phone_value,
whenrequired: whenrequired_value
});
posting.done(function( data )
{
/* Put the results in a div */
$( "#contactResponse" ).html(data);
/* Change the button text. */
$submit.text('Sent, Thank you');
/* Disable the button. */
$submit.attr("disabled", true);
});
});
</script>
<form id="contactForm" method="POST" action="contact.php" >
<fieldset id="frmWrap_cform">
<div class="control-group">
<label class="control-label" for="car1">Vehicle</label>
<input id="car1" class="formcontrol formcontrol95" type="text" maxlength="250" placeholder="Required" required="" value=''>
</div>
<input id="car2" class="formcontrol formcontrol95" type="text" maxlength="250" placeholder="(optional)">
<div class="control-group">
<label class="control-label" for="whereused">Garage</label>
<input id="whereused" class="formcontrol formcontrol95" type="text" maxlength="50" placeholder="Required" required="">
</div>
<div class="control-group">
<label class="control-label" for="custname">Your name</label>
<input id="name" class="formcontrol formcontrol95" type="text" maxlength="50" placeholder="Required" required="">
</div>
<div class="control-group">
"custphone">Your phone number</label>
<input id="phone" class="formcontrol formcontrol95" type="text" maxlength="50" placeholder="Required" required="">
</div>
<div class="control-group">
<label class="control-label" for="custemail">Your email</label>
<input id="email" class="formcontrol formcontrol95" type="text" maxlength="250" placeholder="Required" required="">
</div>
<label>When is required?</label>
<input id="whenrequired" class="formcontrol formcontrol95" type="text" maxlength="250">
<label>Comments / exact requirements:</label>
<textarea id='message' rows='3' class='formcontrol formcontrol95' placeholder='e.g. specific options/engine/transmission you require, delivery required etc'></textarea>
<label class="checkbox"><input type="checkbox" id="addtomailing"> Please tick here</label>
<hr style="margin:2px 0 7px 0;">
<button id="comments_cform" data-item-id="-999" type="submit" class="btn btn-primary btn-submit-version-form">Send enquiry</button>
</fieldset>
</form>
I look on the internet and i try many solution.
What should i have it contact.php?
All the things that i try its nit working.
Only this code send me a blank email .
<?php
$car1 = $_POST['car1'];
$car2 = $_POST['car2'];
$companyname = $_POST['companyname'];
$name = $_POST['name'];
$phone = $_POST['name'];
$email = $_POST['name'];
$country = $_POST['name'];
$zipcode = $_POST['name'];
$street = $_POST['name'];
$message = $_POST['name'];
$to = "XXX#XXX.com";
$subject = "Mailer";
$message = "";
$headers = "From: $email";
if( mail($to,$subject,$message,$headers) )
{
echo "<h2>Thank you for your comment</h2>";
}
else
{
echo "<h2>Sorry, there has been an error</h2>";
}
?>
Thank you in advance

Related

update in codeigniter 3, it's run but database didnt changed

i dont understand with my code. it's run, and work. but when i see in database didnt changed.
here's my controller, function perbarui for get id data, get the data id from model (MMobil).
public function perbarui($id = NULL){
$this->load->model('merek');
$this->load->library('form_validation');
$data['merk'] = $this->merek->getList();
$data['detail'] = $this->MMobil->detail($id);
$submit = $this->input->post('submit');
print_r($data);
if ($submit) {
$nomor_kendaraan = $this->input->post('nomor_kendaraan');
$nomor_mesin = $this->input->post('nomor_mesin');
$id_merek = $this->input->post('id_merek');
$tahun_beli = $this->input->post('tahun_beli');
$nama_mobil = $this->input->post('nama_mobil');
$this->form_validation->set_rules('nama_mobil', 'Nama_Mobil', 'required');
$this->form_validation->set_rules('nomor_kendaraan', 'Nomor_Kendaraan', 'required');
$data['detik'] = $this->MMobil->setData($nomor_kendaraan, $nomor_mesin, $id_merek, $tahun_beli, $nama_mobil);
if ($this->form_validation->run() == FALSE) {
$data['errors'] = TRUE;
}else{
$data['detail'] = $this->MMobil->detail($id);
print_r($data);
}
//redirect('Master');
}
$this->load->view('master-detail-mobil', $data);
}
here's my models. function setData for storage variable after click submit. function edit get id data and get variable arrayData from function setData
public function setData($nomor_kendaraan, $nomor_mesin, $id_merek, $tahun_beli, $nama_mobil){
$this->nomor_kendaraan = $nomor_kendaraan;
$this->nomor_mesin = $nomor_mesin;
$this->id_merek = $id_merek;
$this->tahun_beli = $tahun_beli;
$this->nama_mobil = $nama_mobil;
}
public function edit($id){
$arrayData = array(
'nomor_kendaraan' => $this->nomor_kendaraan,
'nomor_mesin' => $this->nomor_mesin,
'id_merek' => $this->id_merek,
'tahun_beli' => $this->tahun_beli,
'nama_mobil' => $this->nama_mobil,
);
$this->db->where('nomor_mesin', $id);
return $this->db->update($this->table,$arrayData);
}
here's my views
<?php $this->load->view('header.php'); ?>
<?php
echo"<h4>UPDATE DATA</h4>";
?>
<form class="form-horizontal" role="form" method="post" action="<?php echo site_url()?>/Master/perbarui/">
<div class="form-group">
<label class="control-label col-sm-2" for="noken">Nomor Kendaraan :</label>
<div class="col-sm-10">
<input type="text" class="form-control" name="nomor_kendaraan" value="<?php
echo #$detail->nomor_kendaraan;
?>">
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-2" for="nomes">Nomor Mesin :</label>
<div class="col-sm-10">
<input type="text" class="form-control" name="nomor_mesin" value="<?php
echo #$detail->nomor_mesin;
?>">
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-2" for="merk">Merek Mobil :</label>
<div class="col-sm-10">
<select class="form-control" name="id_merek">
<?php foreach ($merk as $mrk) :?>
<option value="<?php echo $mrk->id_merek ?>">
<?php
echo $mrk->nama_merek;
?>
</option>
<?php endforeach?>
</select>
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-2" for="thn">Tahun Beli :</label>
<div class="col-sm-10">
<input type="text" class="form-control" name="tahun_beli" value="<?php
echo #$detail->tahun_beli; ?>">
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-2" for="namo">Nama Mobil :</label>
<div class="col-sm-10">
<input type="text" class="form-control" name="nama_mobil" value="<?php
echo #$detail->nama_mobil; ?>">
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-2" for="nomes"></label>
<div class="col-sm-2">
<input type="submit" class="form-control" name="submit" value="simpan">
</div>
</div>
</form>
<?php $this->load->view('footer.php'); ?>
and here my pictures before click submit and after click submit. i typed print_r for see the data array. if you see data array detail before click submit, there is data in detail. but after click submit data array detail gone.
enter image description here enter image description here

Undefined array key error in Codeigniter 4 even when var_dump() is showing data

This is my Controller Code:
public function edit_manpower($Manpower_id=null)
{
$session = session();
$db = \Config\Database::connect();
$builder = $db->table('Manpower');
$builder->select('Manpower.*');
$builder->where('Manpower_id', $Manpower_id);
$query = $builder->get();
$data['row'] = $query->getResultArray();
return view("admin/update_manpower_form",$data);
}
This is my View Code where the error arises:
<form action = "<?php echo site_url('Admin/updatemanpower/'.$row['Manpower_id']);?>" method=
"post" enctype="multipart/form-data">
<input type="hidden" name="_method" value="PUT"/>
<div class="form-group">
<div class=required-field><label for="Name">NAME:</label></div>
<input type="text" class="form-control" placeholder="Enter name" id="Name" value="<?php echo
$row['Name'];?>" name="Name" autocomplete="off">
</div>
<br>
<div class="form-group">
<div class=required-field><label for="Contact_no">CONTACT NUMBER:</label></div>
<input type="text" class="form-control" placeholder="Enter phone number" id="Contact_no"
value="<?php echo $row['Contact_no'];?>" name="Contact_no" autocomplete="off">
</div>
<br>
When I place the following line at the top of View, the required data is displayed:
<?php var_dump($row); ?>
The error message displayed is:
Undefined array key "Manpower_id"
APPPATH\Views\admin\update_manpower_form.php at line 65
64 <br><br>
65 <form action = "<?php echo site_url('Admin/updatemanpower/'.$row['Manpower_id']);?>"
method= "post" enctype="multipart/form-data">
66 <input type="hidden" name="_method" value="PUT"/>
I am unable to find what I am doing wrong. Kindly help.
Your $row maybe an Object array.
#std[]

CRUD Angular App

its a crud app i am inputting user info into a form and then saving it in an array and then rendering it into a table .I can add more rows with different user data . And i can delete a certain row from the table . I also have a edit button but i don't have no idea how to do that.
Register.html file
<div class="container">
<h2 class="page-header">Register</h2>
<form (ngSubmit)="onRegisterSubmit()" [formGroup] = "form">
<div class="form-group">
<label>Full Name</label>
<input type="text" [(ngModel)]="fullname" formControlName="fullname" class="form-control" >
</div>
<div class="form-group">
<label>Username</label>
<input type="text" [(ngModel)]="username" formControlName="username" class="form-control" >
</div>
<div class="form-group">
<label>Email</label>
<input type="text" [(ngModel)]="email" formControlName="email" class="form-control" >
</div>
<div class="form-group">
<label>Password</label>
<input type="password" [(ngModel)]="password" formControlName="password" class="form-control">
</div>
<input type="submit" class="btn btn-primary" value="Submit" [disabled]="!form.valid">
</form>
<br>
<br>
<table border="2" class="table table-striped">
<tr>
<th>Full Name</th>
<th>Username</th>
<th>Email</th>
<th>Password</th>
<th>Delete</th>
<th>Edit</th>
</tr>
<div > </div>
<tr *ngFor="let user of userDetails">
<td>{{user.username}}</td>
<td>{{user.username}}</td>
<td>{{user.email}}</td>
<td>{{user.password}}</td>
<td><button (click)="userDelete()">X</button></td>
<td><button (click)="userEdit()">Edit</button></td>
</tr>
</table>
</div>
Register.ts file
export class RegisterComponent implements OnInit {
fullname : string;
username : string;
email : string;
password : string;
userDetails:Array<object>;
constructor(
private validateService: ValidateService,
private flashMessage:FlashMessagesService)
{ }
form;
ngOnInit() {
this.userDetails=[];
this.form = new FormGroup({
fullname : new FormControl("", Validators.required),
username : new FormControl("", Validators.required),
email : new FormControl("", Validators.required),
password : new FormControl("", Validators.required)
});
}
onRegisterSubmit(){
let user = {
fullname : this.fullname ,
username : this.username,
email : this.email ,
password : this.password
}
this.userDetails.push(user);
if(!this.validateService.validateRegister(user)){
this.flashMessage.show('Please fill in all fields', {cssClass: 'alert-danger', timeout: 3000});
return false;
}
// Validate Email
if(!this.validateService.validateEmail(user.email)){
this.flashMessage.show('Please use a valid email', {cssClass: 'alert-danger', timeout: 3000});
return false;
}
}
userDelete(){
this.userDetails.pop();
}
userEdit(){
//No logic
}
}
Validation service file
export class ValidateService {
constructor() { }
validateRegister(user){
if(user.fullname == undefined || user.email == undefined || user.username == undefined || user.password == undefined){
return false;
} else {
return true;
}
}
validateEmail(email){
const re = /^(([^<>()\[\]\\.,;:\s#"]+(\.[^<>()\[\]\\.,;:\s#"]+)*)|(".+"))#((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
return re.test(email);
}
}
To hardcode new values is simple:
<tr *ngFor="let user of userDetails; index as i">
<td>{{user.username}}</td>
<td>{{user.username}}</td>
<td>{{user.email}}</td>
<td>{{user.password}}</td>
<td><button (click)="userDelete()">X</button></td>
<td><button (click)="userEdit(i)">Edit</button></td>
</tr>
userEdit(i) {
let editUser = this.userDetails[i];
editUser = { fullname: 'Tadas Blynda', etc. }
}
But what you need is probably this:
<div>
<form (ngSubmit)="onRegisterSubmit()" [formGroup] = "form" [hidden]="clicked">
<div class="form-group">
<label>Full Name</label>
<input type="text" [(ngModel)]="fullname" formControlName="fullname" class="form-control" >
</div>
<div class="form-group">
<label>Username</label>
<input type="text" [(ngModel)]="username" formControlName="username" class="form-control" >
</div>
<div class="form-group">
<label>Email</label>
<input type="text" [(ngModel)]="email" formControlName="email" class="form-control" >
</div>
<div class="form-group">
<label>Password</label>
<input type="password" [(ngModel)]="password" formControlName="password" class="form-control">
</div>
<input type="submit" class="btn btn-primary" value="Submit" [disabled]="!form.valid">
</form>
</div>
<div>
<form (ngSubmit)="onEditSubmit()" [formGroup] = "form" [hidden]="!clicked">
<div class="form-group">
<label>Full Name</label>
<input type="text" [(ngModel)]="fullname" formControlName="fullname" class="form-control"
placeholder="userDetails[editIndex]?.fullname" >
</div>
<div class="form-group">
<label>Username</label>
<input type="text" [(ngModel)]="username" formControlName="username" class="form-control" >
</div>
<div class="form-group">
<label>Email</label>
<input type="text" [(ngModel)]="email" formControlName="email" class="form-control" >
</div>
<div class="form-group">
<label>Password</label>
<input type="password" [(ngModel)]="password" formControlName="password" class="form-control">
</div>
<input type="submit" class="btn btn-primary" value="Submit" [disabled]="!form.valid">
</form>
</div>
<br>
<br>
<table border="2" class="table table-striped">
<tr>
<th>Full Name</th>
<th>Username</th>
<th>Email</th>
<th>Password</th>
<th>Delete</th>
<th>Edit</th>
</tr>
<div > </div>
<tr *ngFor="let user of userDetails; index as i">
<td>{{user.fullname}}</td>
<td>{{user.username}}</td>
<td>{{user.email}}</td>
<td>{{user.password}}</td>
<td><button (click)="userDelete()">X</button></td>
<td><button (click)="clickEdit(i)">Edit</button></td>
</tr>
</table>
And
export class AppComponent {
fullname : string;
username : string;
email : string;
password : string;
clicked = false;
userDetails:Array<object>;
form;
ngOnInit() {
this.userDetails=[];
this.form = new FormGroup({
fullname : new FormControl("", Validators.required),
username : new FormControl("", Validators.required),
email : new FormControl("", Validators.required),
password : new FormControl("", Validators.required)
});
}
onRegisterSubmit(){
let user = {
fullname : this.fullname ,
username : this.username,
email : this.email ,
password : this.password
}
this.userDetails.push(user);
}
editIndex = null;
clickEdit(i){
this.clicked = !this.clicked;
this.editIndex = i;
}
onEditSubmit() {
let editUser = {
fullname : this.fullname ,
username : this.username,
email : this.email ,
password : this.password
}
this.userDetails[this.editIndex] = editUser;
this.clicked = !this.clicked;
}
}
Let me know please, if any issues.

Confirmation message in same page after submission

I buy a Dreamweaver template and it comes with a Form page.But when I submit the message it sends me to another page with only text in it.
So I want to change it, so it can display a message after the submit buttom.
This is the CONTACT FORM inserted in a HTML page:
<div class="col-sm-6 col-xs-12">
<div class="status alert alert-success contact-status"></div>
<form id="main-contact-form" class="contact-form" name="contact-form" method="post" action="sendemail.php" role="form">
<div class="row">
<!-- Name Field Starts -->
<div class="col-md-6">
<div class="form-group">
<label for="name" class="sr-only">Nombre: </label>
<input type="text" class="form-control" name="name" id="name" required placeholder="NOMBRE">
</div>
</div>
<!-- Name Field Ends -->
<!-- Email Field Starts -->
<div class="col-md-6">
<div class="form-group">
<label for="email" class="sr-only">Correo Electrónico: </label>
<input type="text" class="form-control" name="email" id="email" required placeholder="EMAIL">
</div>
</div>
<!-- Email Field Ends -->
<!-- Phone No Field Starts -->
<div class="col-md-6">
<div class="form-group">
<label for="phoneno" class="sr-only">Teléfono: </label>
<input type="text" class="form-control" name="phoneno" id="phoneno" required placeholder="TELÉFONO (10 DÍGITOS)">
</div>
</div>
<!-- Phone No Field Ends -->
<!-- Message Field Starts -->
<div class="col-xs-12">
<div class="form-group">
<label for="message" class="sr-only">Mensaje: </label>
<textarea class="form-control" rows="8" name="message" id="message" required placeholder="MENSAJE"></textarea>
</div>
</div>
<!-- Message Field Ends -->
<div class="col-xs-12">
<input type="submit" class="btn btn-lg btn-block btn-secondary text-uppercase" value="Enviar Mensaje">
</div>
</div>
</form>
</div>
<!-- Contact Form Ends -->
And this is the sendemail.php
<?php
header('Content-type: application/json');
$status = array(
'type'=>'success',
'message'=>'Email sent!'
);
$name = #trim(stripslashes($_POST['name']));
$email = #trim(stripslashes($_POST['email']));
$phoneno = #trim(stripslashes($_POST['phoneno']));
$subject = #trim(stripslashes($_POST['subject']));
$message = #trim(stripslashes($_POST['message']));
$email_from = $email;
$email_to = 'myemail#domain.com';
$body = 'Name: ' . $name . "\n\n" . 'Email: ' . $email . "\n\n" . 'Phone NO: ' . $phoneno . "\n\n" . 'Subject: ' . $subject . "\n\n" . 'Message: ' . $message;
$success = #mail($email_to, $subject, $body, 'From: <'.$email_from.'>');
echo json_encode($status);
die;
?>
Hopping you can help me

Form not passing data to php file while using bootstrap

I am trying to create a modal that will allow a user to enter some data and then have php send an email with this data.
I have a form in the modal and the php sends the email however I cannot seem to get/use the data within the form as it doesn't seem to recover anything when I use the $_POST. Can someone please help as this is driving me mad.
Code is listed below
<!-- Modal -->
<div class="modal fade" id="modalform" tabindex="-1" role="dialog"
aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<!-- Modal Header -->
<div class="modal-header">
<button type="button" class="close"
data-dismiss="modal">
<span aria-hidden="true">×</span>
<span class="sr-only">Close</span>
</button>
<h4 class="modal-title" id="myModalLabel">
Submit your details to have a Sales Assistant call you back
</h4>
</div>
<!-- Modal Body -->
<div class="modal-body">
<form role="form" method="post" action="enquire.php">
<div class="form-group">
<label for="InputName">Your Name</label>
<input type="text" class="form-control"
id="InputName" placeholder="Your Name"/>
</div>
<div class="form-group">
<label for="InputCar">Car Type</label>
<input type="text" class="form-control"
id="InputCar" placeholder="Car you are interested in"/>
</div>
<div class="form-group">
<label for="InputContact">Phone Number</label>
<input type="text" class="form-control"
id="InputContact" placeholder="A number for us to contact you on"/>
</div>
<button type="submit" class="btn btn-default" value="submit">Submit</button>
</form>
</div>
<!-- Modal Footer -->
<div class="modal-footer">
<h4>Alternatively you can call us on </h4>
</div>
</div>
</div>
php
<?php
$InputName = $_POST['InputName'];
$InputCar = $_POST['InputCar'];
$InputContact = $_POST['InputContact'];
$from = "made up email address";
$to = "another made up email address";
$subject = "Enquiry from web page";
$message = "$InputName is interested in $InputCar. Contact them on $InputContact";
$headers = "From: $from \r\n";
$headers .= "Reply-To: $from \r\n";
$headers .= "Return-Path: $from\r\n";
$headers .= "X-Mailer: PHP \r\n";
mail($to, $subject, $message, $headers);
if(mail($to,$subject,$message,$headers))
{
echo "Mail sent OK";
}
else
{
echo "Error sending email!";
}
?>
Your forms were all wrong.. This is how the form should be.
<form action="" method="post">
<div class="form-group">
<label>Your Name</label>
<input type="text" class="form-control" name="name" placeholder="Your Name">
</div>
<div class="form-group">
<label>Car Type</label>
<input type="text" class="form-control" name="car" placeholder="Car you are interested in">
</div>
<div class="form-group">
<label>Phone Number</label>
<input type="text" class="form-control" name="phone" placeholder="A number for us to contact you on">
</div>
<input type="submit" class="btn btn-default" value="submit" name="send">
</form>
Your PHP should then be:
if (isset($_POST['send'])) {
$InputName = $_POST['name'];
$InputCar = $_POST['car'];
$InputContact = $_POST['phone'];
// do code
}
EDIT: under form action="" you need to add your PHP file again.