I am using Opencart version 2.1.0.1. There is nothing changed in the contact form much. The contact form is sending the data in the GET method but it is supposed to send the data in POST method as the validations are being done for POST data.
Can someone please tell me what could be the issue. https://www.ijminc.com/index.php?route=information/contact is the website link for the contact page I am talking about.
if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) {
// echo $this->request->post['is_redirect'];
if(empty($this->request->post['is_redirect'])){
$mail = new Mail();
$mail->protocol = $this->config->get('config_mail_protocol');
$mail->parameter = $this->config->get('config_mail_parameter');
$mail->smtp_hostname = $this->config->get('config_mail_smtp_hostname');
$mail->smtp_username = $this->config->get('config_mail_smtp_username');
$mail->smtp_password = html_entity_decode($this->config->get('config_mail_smtp_password'), ENT_QUOTES, 'UTF-8');
$mail->smtp_port = $this->config->get('config_mail_smtp_port');
$mail->smtp_timeout = $this->config->get('config_mail_smtp_timeout');
$mail->setTo($this->config->get('config_email'));
$mail->setFrom($this->request->post['email']);
$mail->setSender(html_entity_decode($this->request->post['name'], ENT_QUOTES, 'UTF-8'));
$mail->setSubject(html_entity_decode(sprintf($this->language->get('email_subject'), $this->request->post['name']), ENT_QUOTES, 'UTF-8'));
$mail->setText($this->request->post['enquiry']);
$mail->send();
$this->response->redirect($this->url->link('information/contact/success'));
}
In contact.tpl, the form code is as
<form action="<?php echo $action; ?>" method="post" enctype="multipart/form-data" class="form-horizontal">
<fieldset>
<legend><?php echo $text_contact; ?></legend>
<div class="form-group required">
<label class="col-sm-2 control-label" for="input-name"><?php echo $entry_name; ?></label>
<div class="col-sm-10">
<input type="text" name="name" value="<?php echo $name; ?>" id="input-name" class="form-control" />
<?php if ($error_name) { ?>
<div class="text-danger"><?php echo $error_name; ?></div>
<?php } ?>
</div>
</div>
<div class="form-group required">
<label class="col-sm-2 control-label" for="input-email"><?php echo $entry_email; ?></label>
<div class="col-sm-10">
<input type="text" name="email" value="<?php echo $email; ?>" id="input-email" class="form-control" />
<?php if ($error_email) { ?>
<div class="text-danger"><?php echo $error_email; ?></div>
<?php } ?>
</div>
</div>
<div class="form-group required">
<label class="col-sm-2 control-label" for="input-enquiry"><?php echo $entry_enquiry; ?></label>
<div class="col-sm-10">
<textarea name="enquiry" rows="10" id="input-enquiry" class="form-control"><?php echo $enquiry; ?></textarea>
<?php if ($error_enquiry) { ?>
<div class="text-danger"><?php echo $error_enquiry; ?></div>
<?php } ?>
</div>
</div>
<?php echo $captcha; ?>
</fieldset>
<div class="buttons">
<div class="pull-right">
<input class="btn btn-primary" type="submit" value="<?php echo $button_submit; ?>" />
</div>
</div>
</form>
Note : I have been working on this issue for 2 days now and did a lot of google search. I couldn't get any relevant answer that could solve my problem. If you guys have any link that could solve my issue, please post it.
Thanks for the help in advance.
Related
Hi Guys could please check my code I have written, the problem is it won't update the data in DB, it just reloading and not giving any error.
Here is my update.php
if (isset($_POST['update']) && isset($_POST['update']) != "") {
$name = $_POST['c_name'];
$mobile = $_POST['c_mob'];
$dDate = $_POST['d_date'];
$frame = $_POST['frame'];
$size = $_POST['size'];
$lense = $_POST['lense'];
$descr = $_POST['descr'];
$paid = $_POST['paid'];
$remains = $_POST['remains'];
$refer = $_POST['c_refer'];
}
$setquery = "UPDATE `dep_sale` SET c_name='$name', c_mob='$mobile', d_date='$dDate', frame='$frame', size='$size', lense='$lense', descr='$descr',c_refer='$refer', paid='$paid', remains='$remains' WHERE id='".$_POST["id"]."'";
mysqli_query($link, $setquery);
header("location: reports.php");
And here is the HTML
<form method="POST" action="update.php">
<div class="row">
<div class="col-lg-4 col-md-4">
<input type="hidden" name="id" />
<input type="text" class="form-control" value="<?php echo $row['c_name']; ?>" required id="c_name" name="c_name" placeholder="Name..."/>
</div>
<div class="col-lg-4 col-md-4">
<input type="phone" class="form-control" value="<?php echo $row['c_mob']; ?>" required id="c_mob" name="c_mob" placeholder="Mobile..."/>
</div>
<div class="col-lg-4 col-md-4">
<input type="text" class="form-control" value="<?php echo $row['d_date']; ?>" required id="d_date" name="d_date" onfocus="(this.type='date')" placeholder="Delivery Date..."/>
</div>
</div>
<br>
<div class="row">
<div class="col-lg-4 col-md-4">
<input type="text" class="form-control" value="<?php echo $row['frame']; ?>" required id="frame" name="frame" placeholder="Frame..."/>
</div>
<div class="col-lg-4 col-md-4">
<input type="text" class="form-control" value="<?php echo $row['size']; ?>" required id="size" name="size" placeholder="Size..."/>
</div>
<div class="col-lg-4 col-md-4">
<input type="text" class="form-control" value="<?php echo $row['lense']; ?>" required id="lense" name="lense" placeholder="Lense..."/>
</div>
</div>
<br>
</form>
There is no problem in connection because i am fetching and inserting data perfectly.Please help me guys.Thanks
To see the errors set the following at first lines:
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
Your if is wrong. Try this:
if (isset($_POST['update']) && $_POST['update'] != "") {
Or more shorter version
if (!empty($_POST['update'])) {
Hope this helped you!
Here below is my code, i get strange results, for example the POST is not being caught by the PHP. If i add ($_SERVER['REQUEST_METHOD'] == 'POST') it is still not caught. It hould be a simple POST, what did i do wrong? The best i get out of this is the error message:
$url_message = 'Something went wro, please try again.';
Please help
if(isset($_POST["submit"])) {
$btc = $_POST['bitcoin'];
$eur = $_POST['euro'];
echo '1';
echo $btc;
echo '2';
echo $eur;
if($btc != "" && $eur != ""){
$user_idr = $_GET['id'];
$user_idreal = $LS->get_CU();
echo $LS->get_CU();
echo $user_idr;
if($user_idr == $user_idreal){
echo 'jemoder';
$cur = $btc;
$eur = $eur;
$user = $user_id;
$datetime = date('Y-m-d H:i:s');
$ip = $_SERVER['REMOTE_ADDR'];
if($LS->store_val($cur, $eur, $user, $datetime, $ip) != false){
$url_message = 'Gelukt';
header('Location: home.php?id=' . $header_n . '&mas=' . $url_message);
}else{
$url_message = 'niet gelukt';
header('Location: home.php?id=' . $header_n . '&mas=' . $url_message);
}
}else{
$header_n = $LS->get_CU();
$url_message = 'Something went wro, please try again.';
header('Location: home.php?id=' . $header_n . '&mas=' . $url_message);
}
}else{
$header_n = $LS->get_CU();
$url_message = 'Some fields were left blank.';
header('Location: home.php?id=' . $header_n . '&mas=' . $url_message);
}
}else{
echo 'hallo';
}
?>
<div class="col-md-9">
<div class="span9">
<div class="space-6"></div>
<div class="row-fluid">
<div class="span12">
<form class="form-horizontal formproperties" action="<?php echo $_SERVER['PHP_SELF'] ?>#form-textfield" method="POST">
<fieldset>
<div class="container">
<div class="row-fluid">
<div class="col-xs-12 col-sm-12 col-lg-12">
<div class="col-xs-12 col-sm-12 col-lg-6 logintextsupport text-center">
<h3 class="text-left">Buy <?php echo $form_titel;?></h3>
<hr />
<div class="form-group">
<label class="col-md-1 control-label" for="password"></label>
<div class="col-md-9">
<input id="<?php echo $form_id;?>" name="<?php echo $form_name;?>" type="text" placeholder="<?php echo $form_placeholder;?> *" class="form-control input-md" required="">
</div>
</div>
<div class="form-group">
<label class="col-md-1 control-label" for="password"></label>
<div class="col-md-9">
<input id="euro" name="euro" type="text" placeholder=" *" class="form-control input-md" required="">
</div>
</div>
<legend>Payment Method</legend>
<div class="form-group">
<label class="col-md-1 control-label" for="password"></label>
<div class="col-md-5">
<input type="radio" name="radio" id="radio1" /> <label for="radio1" class="inline">iDeal</label><br />
</div>
<div class="col-md-4">
<input type="radio" name="radio" id="radio3" /> <label for="radio3" class="inline">Ban Contact</label>
</div>
</div>
<hr />
<div class="form-group loginboxsupport">
<label class="col-md-12 col-lg-12" for="proceed"></label>
<div class="col-md-12 col-lg-12">
<button id="proceed" type="submit" name="submit" class="btn btn-success buttonali">SUBMIT</button>
</div>
</div>
<div style="height:0.5vw;"></div>
</div>
</div>
</div>
</div>
</fieldset>
</form>
The problem was in the HTML code, at the action there is the following code
action="<?php echo $_SERVER['PHP_SELF'] ?>#form-textfield"
So the action would be a link to itself, nothing on it. Had to add a user ID:
?id=<?php echo $user_id ?>
The complete action became:
action="<?php echo $_SERVER['PHP_SELF'] ?>?id=<?php echo $user_id ?>#form-textfield"
The total start of the form:
<form class="form-horizontal formproperties" action="home.php?id=<?php echo $user_id ?>#form-textfield" method="POST">
Outputted a row from a table ,am now trying to add some of the contents to another table using a form which is inside the outputted row but its not inserted to the database. am not getting an error.
Here is my view
<?php
foreach ($h->result() as $row)
{?>
<div class="row invoice-info">
<div class="col-sm-1 invoice-col">
</div>
<div class="col-sm-3 invoice-col">
<img src="<?php echo base_url()?>/res/images/goods/1.png">
</div>
<div class="col-sm-4 invoice-col">
<address>
Description: <?php echo $row->description;?><br>
Location Address: <?php echo $row->l_area;?><br>
Destination Address: <?php echo $row->d_area;?><br>
Date: <?php echo $row->dom;?><br>
Time: <?php echo $row->tom;?>
</address>
</div>
<div class="col-sm-2 invoice-col">
<address>
</address>
</div><!-- /.col -->
<div class="col-sm-2 invoice-col">
<form action="<?php echo site_url('truckeraccount_ctrl/bid'); ?>" method="post">
<input type="hidden" class="form-control" name="truckerid" value="<?php
$truckerid = $this->session->userdata('truckerid');
echo $truckerid; ?>" required>
<input type="hidden" class="form-control" name="luggage_id" value="<?php echo $row->luggage_id;?>" placeholder="Bid">
<input type="text" class="form-control" name="bid_amount" placeholder="Bid">
<button type="submit" class="btn bg-orange btn-flat margin">Place Bid</button>
</div>
</div>
My model
function bid($data){
$query=$this->db->update('bids',$data);
return $query;
}
My controller
public function bid(){
$this->load->database();
$this->load->model('Truckeraccount_model');
$data['a']=$this->Truckeraccount_model->accepted_bid();
$data['b']=$this->Truckeraccount_model->picked_loads();
$data['h']=$this->Truckeraccount_model->loads();
$data['g']=$this->Truckeraccount_model->notification();
$data['i']=$this->Truckeraccount_model->return_loads();
$data['accepted_return_loads']=$this->Truckeraccount_model->accepted_return_loads();
$data['bid_amount']=$this->Truckeraccount_model->bid_amount(); $this->load->library('form_validation');
$this->form_validation->set_error_delimiters('<div class="error">', '</div>');
$this->form_validation->set_rules('bid_amount', 'bid_amount', 'required|min_length[1]|max_length[50]');
if ($this->form_validation->run() == FALSE) {
$this->load->view('header');
$this->load->view('truckeraccount_view',$data);
$this->load->view('footer');
} else {
$data = array(
'truckerid' => $this->input->post('truckerid'),
'luggage_id' => $this->input->post('luggage_id'),
'bid_amount' => $this->input->post('bid_amount'),
);
$this->Truckeraccount_model->bid($data);
$data['message'] = '';
redirect('truckeraccount_ctrl/');
}
}
<form action="<?php echo site_url('truckeraccount_ctrl/bid'); ?>" method="post">
<input type="hidden" class="form-control" name="truckerid" value="<?php
$truckerid = $this->session->userdata('truckerid');
echo $truckerid; ?>" required>
<input type="hidden" class="form-control" name="luggage_id" value="<?php echo $row->luggage_id;?>" placeholder="Bid">
<input type="text" class="form-control" name="bid_amount" placeholder="Bid">
<button type="submit" class="btn bg-orange btn-flat margin">Place Bid</button>
</form>
I have simple code thats not working. I made validation for checkbox and I get error:
Unable to access an error message corresponding to your field name accept_terms_checkbox.(accept_terms)
This is my code:
Controller:
public function formularz2()
{
$this->load->helper(array('form', 'url'));
$this->load->library('form_validation');
$data['szkolenia'] = $this->Szkolenie_m->pobierz();
//VALIDATION!!
$this->form_validation->set_rules('imie', 'Imię', 'required');
$this->form_validation->set_message('required', 'Błąd: wypełnij powyższe pole');
$this->form_validation->set_rules('accept_terms_checkbox', 'checkbox', 'callback_accept_terms');
//CALLBACK FUNCTION!!
function accept_terms()
{
if ($this->input->post('accept_terms_checkbox'))
{
return TRUE;
}
else
{
$error = 'Please read and accept our terms and conditions.';
$this->form_validation->set_message('accept_terms', $error);
return FALSE;
}
}
//Po przesłaniu danych
if (!empty($_POST))
{
$konsultant = $this->uri->segment(3);
$dane = array(
'email1' => $this->input->post('email'),
'imie' => $this->input->post('imie'),
'nazwisko' => $this->input->post('nazwisko'),
'nazwa_firmy' => $this->input->post('firma'),
'konsultant_id' => $konsultant,
);
//Trzeba jeszcze tutaj ogarnąć wrzucanie pivotów zaznaczonych checkboxów
$boxes = $_POST['formChecks'];
$N = count($boxes);
$ostatni_id = $this->Osoby_m->ostatni_id();
for($i=0; $i < $N; $i++)
{
$this->Osoby_m->nowy_wpis_formularz($boxes[$i]);
}
//Pobrać id dodanej osoby = policzyć ile osób w bazie +1
$this->Osoby_m->nowa_osoba($dane);
}
if ($this->form_validation->run() == FALSE)
{
$this->load->view('formularz', $data);
}
else
{
$this->load->view('wyslano_formularz');
}
}
My View:
<?php echo form_open(); ?>
<div class="form-group">
<label for="email" class="col-sm-2 control-label">Email:</label>
<div class="col-sm-10">
<input type="email" class="form-control" id="email" name="email" placeholder="Email" value="<?php echo set_value('email'); ?>">
<p class="help-block"><?php echo form_error('email'); ?></p>
</div>
</div>
<div class="form-group">
<label for="imie" class="col-sm-2 control-label">Imię:</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="imie" name="imie" placeholder="Imię" value="<?php echo set_value('imie'); ?>">
<p class="help-block"><?php echo form_error('imie'); ?></p>
</div>
</div>
<div class="form-group">
<label for="nazwisko" class="col-sm-2 control-label">Nazwisko: </label>
<div class="col-sm-10">
<input type="text" class="form-control" id="nazwisko" name="nazwisko" placeholder="Nazwisko" value="<?php echo set_value('nazwisko'); ?>">
<p class="help-block"><?php echo form_error('nazwisko'); ?></p>
</div>
</div>
<div class="form-group">
<label for="firma" class="col-sm-2 control-label">Firma:</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="firma" name="firma" placeholder="Firma" value="<?php echo set_value('firma'); ?>">
<p class="help-block"><?php echo form_error('firma'); ?></p>
</div>
</div>
<div class="col-sm-12" style="margin-bottom: 30px; margin-top: 30px;"> <h3>Wybierz interesujące Cię szkolenia</h3></div>
<div class="form-group">
<label class="col-sm-2 control-label">Szkolenia:</label>
<div class="col-sm-10">
<?php foreach ($szkolenia as $szkolenie): ?>
<div class="checkbox">
<label><input id="szkolenie<?php echo $szkolenie->id; ?>" type="checkbox" name="formChecks[]" value="<?php echo $szkolenie->id; ?>"> <?php echo $szkolenie->nazwa_szkolenia; ?></label>
<br>
</div>
<?php endforeach; ?>
</div>
</div>
//CALLBACK CHECKBOX
<div class="form-group">
<div class="col-sm-12" style="margin-top: 50px;">
<input type="checkbox" name="accept_terms_checkbox" value="1"/> Zgadzam się na otrzymywanie maili od firmy Gamma<br>
<p><?php echo form_error('accept_terms_checkbox') ?></p>
</div>
</div>
<button type="submit" class="btn btn-lg btn-success" style="margin-top: 50px;">Odbierz Voucher</button>
<?php echo form_close(); ?>
In order to use your own callback method with codeigniter's validation class, you must declare the method. IN your case ( add this to your controller or a helper etc...):
public function accept_terms($user_input){
if($user_input != ""){
return True;
}else{
$this->form_validation->set_message('accept_terms_checkbo', 'The %s field can not be empty"');
return False;
}
I fixed this error by simple validation without callback function. I figure out that I don't need callback function for Terms of Services checkbox.
$this->form_validation->set_rules('accept_terms_checkbox', 'Checkbox', 'required');
$this->form_validation->set_message('required', 'You need to accept Terms of Services');
I really hope you can help me.
I've done a form, where I can opt if a client I'm adding to the database is "Active or "Inactive", using a dropdown select box.
My code saves all the data correctly to the datbase, but when I want to edit the client, the option displays always as "Active", ignoring the value from the database.
I have 2 files:
edita_clientes.php - the form where I can edit the clients values
salvar_edicao.php - the file that saves the edition.
Here are the codes:
edita_clientes.php:
<?php
#ini_set('display_errors', '1');
error_reporting(E_ALL);
$id = $_GET["id_cliente"];
settype($id, "integer");
mysql_connect("localhost", "root", "");
mysql_select_db("sistema");
$resultado = mysql_query("select * from tabela where id_cliente = $id");
$dados = mysql_fetch_array($resultado);
mysql_close();
?>
<form id="edita_pj" name="edita_pj" method="post" action="salvar_edicao.php">
<input type="hidden" name="id_cliente" id="id_cliente" value="<?php echo $id;?>" />
<div class="box-body">
<div class="form-group">
<label>Razão Social</label>
<input type="text" name="razao" id="razao" class="form-control" value="<?php echo $dados["razao"];?>" />
</div>
<div class="form-group">
<label>Nome Fantasia</label>
<input type="text" name="fantasia" id="fantasia" class="form-control" value="<?php echo $dados["fantasia"];?>" />
</div>
</div>
<div class="box-body">
<div class="form-group">
<label>CNPJ</label>
<input type="text" name="cnpj" id="cnpj" class="form-control" data-inputmask='"mask": "999.999.999-99"' data-mask value="<?php echo $dados["cnpj"];?>">
</div>
</div>
<div class="box-body">
<div class="row">
<div class="col-xs-9">
<label>Logradouro</label>
<input type="text" name="logradouro" id="logradouro" class="form-control" value="<?php echo $dados["logradouro"];?>">
</div>
<div class="col-xs-3">
<label>Número</label>
<input type="text" name="numero" id="numero" class="form-control" value="<?php echo $dados["numero"];?>">
</div>
</div>
</div>
<div class="box-body">
<div class="row">
<div class="col-xs-9">
<label>Bairro</label>
<input type="text" name="bairro" id="bairro" class="form-control" value="<?php echo $dados["bairro"];?>">
</div>
<div class="col-xs-3">
<label>CEP</label>
<input type="text" name="cep" id="cep" class="form-control" data-inputmask='"mask": "99999-999"' data-mask value="<?php echo $dados["cep"];?>">
</div>
</div>
</div>
<div class="box-body">
<div class="row">
<div class="col-xs-10">
<label>Cidade</label>
<input type="text" name="cidade" id="cidade" class="form-control" value="<?php echo $dados["cidade"];?>">
</div>
<div class="col-xs-2">
<label>UF</label>
<input type="text" name="uf" id="uf" class="form-control" value="<?php echo $dados["uf"];?>">
</div>
</div>
</div>
<div class="box-body">
<div class="row">
<div class="col-xs-9">
<label>E-mail</label>
<input type="text" name="email" id="email" class="form-control" value="<?php echo $dados["email"];?>">
</div>
<div class="col-xs-3">
<label>Telefone</label>
<input type="text" name="telefone" id="telefone" class="form-control" data-inputmask='"mask": "(99) 9999.9999"' data-mask value="<?php echo $dados["telefone"];?>"/>
</div>
</div>
</div>
<div class="box-body">
<div class="row">
<div class="col-xs-9">
<label>Contato</label>
<input type="text" name="contato" id="contato" class="form-control" value="<?php echo $dados["contato"];?>">
</div>
<div class="col-xs-3">
<label>Estado</label>
<select class="form-control" name="estado" id="estado" value=""><?php echo $dados["estado"];?>
<option>Ativo</option>
<option>Inativo</option>
</select>
</div>
</div>
<div class="form-group">
<label>Observações</label>
<textarea class="form-control" name="obs" id="obs" rows="6" ><?php echo $dados["obs"];?>
</textarea>
</div>
</div>
<div class="box-footer">
<button type="submit" name="Submit" class="btn btn-primary">Salvar</button>
</div>
</form>
salvar_edicao.php:
<?php
#ini_set('display_errors', '1');
error_reporting(E_ALL);
$razao = $_POST["razao"];
$fantasia = $_POST["fantasia"];
$cnpj = $_POST["cnpj"];
$logradouro = $_POST["logradouro"];
$numero = $_POST["numero"];
$bairro = $_POST["bairro"];
$cep = $_POST["cep"];
$cidade = $_POST["cidade"];
$uf = $_POST["uf"];
$email = $_POST["email"];
$telefone = $_POST["telefone"];
$contato = $_POST["contato"];
$estado = $_POST["estado"];
$obs = $_POST["obs"];
$id = $_POST["id_cliente"];
mysql_connect("localhost", "root", "");
mysql_select_db("sistema");
mysql_query("UPDATE tabela SET razao = '$razao', fantasia = '$fantasia', cnpj = '$cnpj', logradouro = '$logradouro', numero='$numero', bairro='$bairro', cep='$cep', cidade = '$cidade', uf='$uf', email = '$email', telefone = '$telefone', contato = '$contato', estado = '$estado', obs = '$obs' WHERE tabela.id_cliente = $id");
mysql_close();
header("Location: consulta.php");
?>
You need to add 'selected' to the option that you want to be selected, based on a value from the form/db. Here is an example using $value as the option value that you want selected.
<select class="form-control" name="estado" id="estado">
<option <?php echo $value == 'Ativo' ? selected : '' ?>>Ativo</option>
<option <?php echo $value == 'Inativo' ? selected : '' ?>>Inativo</option>
</select>
Also, your <select> tag does not require a 'value' element..
The HTML select element does not have a value attribute. For the select to do what you want you need to add the selected attribute to the option you want selected. It's always showing as 'Active' because that's the first option and it is the default.
The resulting post-php HTML will need to look something like this stripped back example for 'Inactive' to be selected.
<select>
<option>Active</option>
<option selected>Inactive</option>
</select>
Thank's for all the help!
The solution I've found was:
<?php
$resultado = mysql_query("select * from tabela where id_cliente = $id");
$dados = mysql_fetch_array($resultado);
$query = mysql_query("SELECT * FROM estado");
?>
And the html part:
<select class="form-control" name="estado" id="estado">
<option selected="selected"><?php echo $dados["estado"];?></option>
<option value="Ativo">Ativo</option>
<option value="Inativo">Inativo</option>
</select>