cant update DB with PDO/SQL it make fields blank - sql

My problem is that when i try to update my DB table (hold) it makes all fields blank.
im using three files a config to connect.This is the config.php file.
<?php
$hostname='localhost';
$username='root';
$password='kv5772';
try {
$db = new PDO("mysql:host=$hostname;dbname=gade",$username,$password);
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); // <== add this line
echo 'Connected to Database<br/>';
}
catch(PDOException $e)
{
echo $e->getMessage();
}
?>
Then there is a print page print.php. With a delete button. It works. But the edit dont.
<?php include "config.php" ?>
<?php
$sql = "SELECT * FROM hold";?>
<table>
<tr>
<td>hold</td>
<td>leder</td>
<td>telefon</td>
<td>mail</td>
</tr>
<?php
foreach($db->query($sql) as $row){
?>
<tr>
<td><input name="hold" type="text" placeholder="<?php echo "{$row['hold']}";?>"/></td>
<td><input name="leder" type="text" placeholder="<?php echo "{$row['leder']}";?>"/></td>
<td><input name="telefon" type="text" placeholder="<?php echo "{$row['telefon']}";?>"/></td>
<td><input name="email" type="text" placeholder="<?php echo "{$row['email']}";?>"/></td>
<td>
<form action="formupdatecode.php" method="post">
<input type="hidden" name="action" value="edit" />
<input type="hidden" name="id" value="<?php echo $row['id'] ?>" />
<input type="submit" value="edit" />
</form>
</td>
<td>
<form action="slet.php" method="post">
<input type="hidden" name="action" value="delete" />
<input type="hidden" name="id" value="<?php echo $row['id'] ?>" />
<input type="submit" value="delete" />
</form>
</td>
</tr>
</table>
<?php
}
$db = null;
?>
The edit button is connected to formupdatecode.php.
<?php include "config.php" ?>
<?php
$sql = "UPDATE hold SET hold = :hold,
leder = :leder,
telefon = :telefon,
email = :email
WHERE id = :id";
$stmt = $db->prepare($sql);
$stmt->bindParam(':id', $_POST['id'], PDO::PARAM_INT);
$stmt->bindParam(':hold', $_POST['hold'], PDO::PARAM_STR);
$stmt->bindParam(':leder', $_POST['leder'], PDO::PARAM_STR);
$stmt->bindParam(':telefon', $_POST['telefon'], PDO::PARAM_STR);
$stmt->bindParam(':email', $_POST['email'], PDO::PARAM_STR);
if($stmt->execute()){
echo "Successfully redigeret hold";
}// End of if profile is ok
else{
print_r($stmt->errorInfo()); // if any error is there it will be posted
$msg=" Database problem, please contact site admin ";
}
?>

Your HTML code has a problem with the location of the input tags.
Your edit/input fields are located outside the form and will not be included in the POST back to the server.

Related

Php 7 error for a simple form getting Object of class mysqli could not be converted to int

The code gets error saying Object of class mysqli could not be converted to int. When i try to load the page i get this error,i checked other questions but it was not helpful
<?php
$conn = mysqli_connect("localhost", "root", "", "coinlion");
if ($conn == 0) {
echo "could not connect";
} else {
mysqli_select_db("coinlion");
echo "connected";
}
?>
<form method="post">
<style>
#newlink {
width: 600px
}
</style>
<div id="newlink">
<div>
<table border=0>
<tr>
<td> Link URL:</td>
<td><input type="text" name="linkurl" value="" required></td>
</tr>
<tr>
<td> Link Description:</td>
<td><textarea name="linkdesc" cols="50" rows="5" required></textarea>
</td>
</tr>
</table>
</div>
</div>
<p>
<br>
<input type="submit" name="submit1">
<input type="reset" name="reset1">
</p>
php code
<?php
if (isset($_POST['submit1'])) {
$linkurl = $_POST['linkurl'];
$linkdesc = $_POST['linkdesc'];
mysqli_query($conn, "insert into
test(linkurl,linkdesc)values('$_POST[linkurl]','$_POST[linkdesc]')");
echo "data inserted";
}
?>
Well the issue was with the line if($conn==0) ,This value was taken as an integer so the error occured and an Connection variable to Mysqli_select_db was missing , after fixing it , the code ran successfully

how to Get cat id and expertise value in my controler

This is my controller and I am trying to get category id and expertise data from my database field. Everything is working, but the problem is that I'm not getting the category id. The problem occurs when I am trying to print all record on my view controller. here is my part of code $cat_id =Yii::$app->request->get('categori_id');.
//start premium adviser section
public function actionPremiumsearch()
{
if(isset($_GET['login-button1']))
{
$model=new UserDetail();
$request = Yii::$app->request;
$post = $request->get();
$cat_id =Yii::$app->request->get('categori_id');
//var_dump($cat_id);exit;
//print_r($cat_id);exit;
$expertise =Yii::$app->request->get('expertise');
//print_r($expertise);exit;
//var_dump($cat_id);exit;
//$cat = $request->cat_id();
//echo $cat;
//print_r($post);
//$cat_id = $request->get('categori_id');
//echo $cat_id;
//$cat_id = $post['categories']['categori_id'];
//echo $cat_id;exit;
//print_r($cat_id);exit;
//print_r($post);
//$cat_id = $post['categori_id'];
//print_r($cat_id);
//$service_id = $post['Service']['id'];
//echo $service_id.' '.$expertise.' '.$cat_id;
//exit;
//echo "button1";
$query = new Query;
// compose the query
$query->select('kpt_users.*,kpt_user_details.*,kpt_user_services.*')
->from('kpt_users')
->join( 'INNER JOIN',
'kpt_user_details',
'kpt_user_details.user_id =kpt_users.id'
)
->join( 'LEFT JOIN',
'kpt_user_services',
'kpt_user_services.user_id= kpt_users.id'
)
//->Where(['kpt_users.user_role_id' =>$role_id,'kpt_user_services.service_id'=>$service_id])
->Where('kpt_users.status = 1')
->andWhere('kpt_users.user_role_id = 2')
//->andFilterWhere(['like', 'kpt_user_services.service_id', $this->service_id])
//->andFilterWhere(['like', 'kpt_user_details.categori_id', $this->categori_id])
//->andFilterWhere(['like', 'kpt_user_details.expertise', $this->expertise])
//->andWhere(['like', 'kpt_user_services.service_id', $service_id])
//->andWhere(['like', 'kpt_user_details.categori_id', $categori_id])
// ->andWhere(['like', 'kpt_user_details.expertise', $expertise])
//->andWhere('kpt_user_details = 2')
//->andWhere(['like', 'categori_id', $cat_id])
//->andWhere(['like', 'name', 'alex'])
//->andWhere(['like','kpt_user_services.service_id'=>$service_id,'kpt_user_details.categori_id'=>$cat_id])
->limit(2);
// build and execute the query
$rows = $query->all();
//var_dump($rows);exit;
return $this->render('personalinsurance', [
'result' => $rows,
'model' => $model,
]);
}
if(isset($_GET['login-button2'])){
//echo "kanak";
//echo "button1";
$query = new Query;
// compose the query
$query->select('kpt_users.*,kpt_user_details.*,kpt_user_services.*')
->from('kpt_users')
->join( 'INNER JOIN',
'kpt_user_details',
'kpt_user_details.user_id =kpt_users.id'
)
->join( 'LEFT JOIN',
'kpt_user_services',
'kpt_user_services.user_id= kpt_users.id'
)
//->Where(['kpt_users.user_role_id' =>$role_id,'kpt_user_services.service_id'=>$service_id])
->limit(4);
// build and execute the query
$rows = $query->all();
//var_dump($rows);exit;
return $this->render('corporateinsurance', [
'result' => $rows,
]);
}
if(isset($_GET['login-button3'])){
//echo "kanak3";
//echo "button1";
$query = new Query;
// compose the query
$query->select('kpt_users.*,kpt_user_details.*,kpt_user_services.*')
->from('kpt_users')
->join( 'INNER JOIN',
'kpt_user_details',
'kpt_user_details.user_id =kpt_users.id'
)
->join( 'LEFT JOIN',
'kpt_user_services',
'kpt_user_services.user_id= kpt_users.id'
)
//->Where(['kpt_users.user_role_id' =>$role_id,'kpt_user_services.service_id'=>$service_id])
->limit(4);
// build and execute the query
$rows = $query->all();
//var_dump($rows);exit;
return $this->render('sbasedplanning', [
'result' => $rows,
]);
}
if(isset($_GET['login-button4'])){
// echo "kanak4";
//echo "button1";
$query = new Query;
// compose the query
$query->select('kpt_users.*,kpt_user_details.*,kpt_user_services.*')
->from('kpt_users')
->join( 'INNER JOIN',
'kpt_user_details',
'kpt_user_details.user_id =kpt_users.id'
)
->join( 'LEFT JOIN',
'kpt_user_services',
'kpt_user_services.user_id= kpt_users.id'
)
//->Where(['kpt_users.user_role_id' =>$role_id,'kpt_user_services.service_id'=>$service_id])
->Where(['kpt_users.user_role_id' =>$role_id,'kpt_user_details.categori_id'=>$category_id])
->limit(4);
// build and execute the query
$rows = $query->all();
//var_dump($rows);exit;
return $this->render('taxplanning', [
'result' => $rows,
]);
}
}
This is my view controller with the foreach-loop. When I am trying to print the record, the category ID is missing. How can I get all data with category ID?
<?php foreach ($result as $rows):
$path = Yii::$app->params['imagePath'];
// print_r ($rows);exit;
?>
<?php $first_name = $rows['first_name'];
//echo $first_name;exit;
$agency_name = $rows['agency_name'];
$seller_name = $rows['seller_name'];
$reff_no = $rows['reff_no'];
$credentials = $rows['credentials'];
$photo = $rows['photo'];
$contact = $rows['contact'];
//echo $contact;exit;
$year_exp = $rows['year_exp'];
$expertise = $rows['expertise'];
$gender = $rows['gender'];
$title = $rows['title'];
$rnf = $rows['reff_no'];
$user_name = $rows['user_name'];
$user_email = $rows['user_email'];
$first_name = $rows['first_name'];
$user_id = $rows['user_id'];
$user_role_id = $rows['user_role_id'];
$service_id1 = $rows['service_id'];
//print_r( $service_id1);
// $service_name = $rows['service_name'];
$credentials = $rows['credentials'];
//echo "User Name: {$user_name}" . "<br>";
//echo "Ratings: {$rating}" . "<br>";
// echo "RNF: {$reff_no}" . "<br>";
//echo "Service Name: {$title}" . "<br>";
//echo "Service id: {$service_id}" . "<br>";
//echo "user role id: {$user_role_id}" . "<br>";
?>
<div class="parent">
<div class="col-lg-12 no-padding">
<div class="col-lg-6">
<div class="big-image">
<?php if($rows['photo']){ ?>
<img src=<?php echo $path; ?><?php echo $rows['photo']; ?> />
<?php } else { ?>
<?php echo Html::img('#web/images/banner/product-main.png'); ?>
<?php } ?>
<?php //echo Html::img('#web/images/banner/product-main.png'); ?></div>
</div>
<div class="col-lg-6">
<div class="product-name">
<h2><?php //echo $first_name?></h2>
<h2><a target="_blank" href="index.php?r=userslisting/user&id=<?php echo $rows['user_id']; ?>"><?php echo $rows['first_name'];?></a> </h2>
</div>
<div class="rating-point">
<p>Reating 4.5/5</p>
</div>
<div class="star">
<span><?php echo Html::img('#web/images/banner/star-full.png'); ?></span>
<span><?php echo Html::img('#web/images/banner/star-full.png'); ?></span>
<span><?php echo Html::img('#web/images/banner/star-full.png'); ?></span>
<span><?php echo Html::img('#web/images/banner/star-hafe.png'); ?></span>
<span><?php echo Html::img('#web/images/banner/star-0.png'); ?></span>
</div>
<div class="rating-point rnf">
<p class="pro-title">RNF</p>
<p class="pro-head-1"><?php echo $rnf?></p>
</div>
<div class="rating-point rank">
<p class="pro-title">Rank/Title</p>
<p class="pro-head-1"><?php echo $title?></p>
</div>
<div class="rating-point ss">
<p class="pro-title">service specialzation</p>
<p class="pro-head-1"><?php echo $expertise?></p>
</div>
<div class="rating-point creden">
<p class="pro-title">Credentials</p>
<p class="pro-head-1"><?php echo $credentials ?></p>
</div>
<div class="rating-point yoe">
<p class="pro-title">Years OF Experience</p>
<p class="pro-head-1"><?php echo $year_exp ?></p>
</div>
<div class="rating-point mail">
<p class="pro-title">Email</p>
<p class="pro-head-1"><?php echo $user_email; ?></p>
</div>
<div class="view-more">
<input type="button" class="btn btn-primary serch-select view-more" value="ENQUIRE" name="ENQUIRE">
<div class="enquiry">
<?php if (Yii::$app->session->hasFlash('contactFormSubmitted')): ?>
<div class="alert alert-success">
Thank you for contacting us. We will respond to you as soon as possible.
</div>
<?php else: ?>
<form id="contact-form" action="" method="post" role="form">
<div class="form-group">
<div class="col-lg-12 no-padding">
<div class="name-1"><input type="text" name="name" class="form-control transparent" value="" placeholder="Name" required> </div>
<div class="contact-1"><input type="text" name="contact" class="form-control transparent" value="" placeholder="Contact No." required> </div>
</div>
</div>
<div class="form-group">
<div class="col-lg-12 no-padding">
<div class="email-1"><input type="email" name="email" class="form-control transparent" value="" placeholder="Email" required> </div>
<div class="subject-1"><input type="text" name="subject" class="form-control transparent" value="" placeholder="Subject" required></div>
</div>
</div>
<div class="form-group"><textarea name="message" class="form-control" rows="6" placeholder="Message"></textarea></div>
<input id="form-token" type="hidden" name="<?=Yii::$app->request->csrfParam?>"
value="<?=Yii::$app->request->csrfToken?>"/>
<div class="form-group submit-button">
<input type="hidden" name="user_id" value="<?php echo $rows['user_id']; ?>" />
<input type="hidden" name="user_name" value="<?php echo $rows['first_name'].' '.$rows['last_name']; ?>" />
<input type="hidden" name="user_email" value="<?php echo $rows['user_email']; ?>" />
<input type="submit" class="btn btn-primary" name="contact-button">
</div>
</form>
<?php endif; ?>
</div>
</div>
</div>
</div>
<div class="clear"></div>
<?php endforeach; ?>
Here is my form
<div class="serch-select-premium">
<?php $form = ActiveForm::begin(['action' =>['site/premiumsearch'], 'id' => '', 'method' => 'get',]); ?>
<?= $form->field($model, 'type_a_keyword')->textInput(['maxlength' => true, 'placeholder' => "Type a keyword"])->label(false); ?>
<?= Html::submitButton('Personal Insurance', ['class' => '','id' => 'personalinsurance', 'name' => 'login-button1']) ?>
<?= Html::submitButton('Corporate Insurance', ['class' => '','id' => 'corporateinsurance', 'name' => 'login-button2']) ?>
<?= Html::submitButton('Solution Based Planning', ['class' => '', 'id' => 'sbasedplanning','name' => 'login-button3']) ?>
<?= Html::submitButton('Tax Planning', ['class' => '','id' => 'taxplanning', 'name' => 'login-button4']) ?>
<?php ActiveForm::end(); ?>
</div>

What exact code is needed for Wordpress/Woocommerce login/sign up pages [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I am creating a small e-commerce website using wordpress & woocommerce but I'm not really understanding the login/signup abilities for users. I just want users who visit the site to be able to click a link on the home page where they can sign up and login (with the option to reset their passwords) and in return those customer details are saved within the user data for the wordpress admin to be able to see. What is the coding for this? Because I can't seem to get into a lot of these plugins.
<?php
global $wpdb, $user_ID;
$firstname='';
$lastname='';
$username='';
$email='';
//if looged in rediret to home page
if ( is_user_logged_in() ) {
wp_redirect( get_option('home') );// redirect to home page
exit;
}
if(sanitize_text_field( $_POST['com_submit']) != ''){
$firstname=sanitize_text_field( $_REQUEST['com_firstname'] );
$lastname=sanitize_text_field( $_REQUEST['com_lastname']);
$username = sanitize_text_field( $_REQUEST['com_username'] );
$email = sanitize_text_field( $_REQUEST['com_email'] );
$password = $wpdb->escape( sanitize_text_field( $_REQUEST['com_password']));
$status = wp_create_user($username,$password,$email);
if (is_wp_error($status)) {
$error_msg = __('Username or Email already registered. Please try another one.','twentyten');
}
else{
$user_id=$status;
update_user_meta( $user_id,'first_name', $firstname);
update_user_meta( $user_id,'last_name', $lastname);
//code to auto login start
$alar_enable_auto_login= get_option('alar_enable_auto_login');
if($alar_enable_auto_login==''){
$alar_enable_auto_login= 'true';
}
if($alar_enable_auto_login == 'true'){
if(!is_user_logged_in()){
$secure_cookie = is_ssl();
$secure_cookie = apply_filters('secure_signon_cookie', $secure_cookie, array());
global $auth_secure_cookie;
$auth_secure_cookie = $secure_cookie;
wp_set_auth_cookie($user_id, true, $secure_cookie);
$user_info = get_userdata($user_id);
do_action('wp_login', $user_info->user_login, $user_info);
}
}
//code to auto login end
wp_redirect( get_option('home') );// redirect to home page
exit;
}
}
?>
<div class="alar-registration-form">
<div class="alar-registration-heading">
<?php _e("Registration Form",'');?>
</div>
<?php if($error_msg!='') { ?><div class="error"><?php echo $error_msg; ?></div><?php } ?>
<form name="form" id="registration" method="post">
<div class="ftxt">
<label><?php _e("First Name :",'');?></label>
<input id="com_firstname" name="com_firstname" type="text" class="input" required value=<?php echo $firstname; ?> >
</div>
<div class="ftxt">
<label><?php _e("Last name :",'');?></label>
<input id="com_lastname" name="com_lastname" type="text" class="input" required value=<?php echo $lastname; ?> >
</div>
<div class="ftxt">
<label><?php _e("Username :",'');?></label>
<input id="com_username" name="com_username" type="text" class="input" required value=<?php echo $username; ?> >
</div>
<div class="ftxt">
<label><?php _e("E-mail :",'');?> </label>
<input id="com_email" name="com_email" type="email" class="input" required value=<?php echo $email; ?> >
</div>
<div class="ftxt">
<label><?php _e("Password :",'');?></label>
<input id="password1" name="com_password" type="password" required class="input" />
</div>
<div class="ftxt">
<label><?php _e("Confirm Password : ",'');?></label>
<input id="password2" name="c_password" type="password" class="input" />
</div>
<div class="fbtn"><input type="submit" name='com_submit' class="button" value="Register"/> </div>
</form>
</div>
<?php
}
//add registration shortcoode
add_shortcode( 'registration-form', 'alar_registration_shortcode' );
// function to login Shortcode
function alar_login_shortcode( $atts ) {
//if looged in rediret to home page
if ( is_user_logged_in() ) {
wp_redirect( get_option('home') );// redirect to home page
exit;
}
global $wpdb;
if(sanitize_text_field( $_GET['login'] ) != ''){
$login_fail_msg=sanitize_text_field( $_GET['login'] );
}
?>
<div class="alar-login-form">
<?php if($login_fail_msg=='failed'){?>
<div class="error" align="center"><?php _e('Username or password is incorrect','');?></div>
<?php }?>
<div class="alar-login-heading">
<?php _e("Login Form",'');?>
</div>
<form method="post" action="<?php echo get_option('home');?>/wp-login.php" id="loginform" name="loginform" >
<div class="ftxt">
<label><?php _e('Login ID :','');?> </label>
<input type="text" tabindex="10" size="20" value="" class="input" id="user_login" required name="log" />
</div>
<div class="ftxt">
<label><?php _e('Password :','');?> </label>
<input type="password" tabindex="20" size="20" value="" class="input" id="user_pass" required name="pwd" />
</div>
<div class="fbtn">
<input type="submit" tabindex="100" value="Log In" class="button" id="wp-submit" name="wp-submit" />
<input type="hidden" value="<?php echo get_option('home');?>" name="redirect_to">
</div>
</form>
</div>
just copy and past This code where do you want to add register login form

Notice: Undefined index: province in D:\wamp\www\PDO\sampleCRUD\update.php on line 13?

I have here the page for update.php my problem was I keep getting this error
Notice: Undefined index: province in D:\wamp\www\PDO\sampleCRUD\update.php on line 13
every time I select this value "---" in my dropdown list it keeps showing this error but if select the rest of the list in the dropdown there's no error I tried to set the province but I still getting this error.
here my code for update.php
<?php
include_once 'dbconfig.php';
$username = isset($_GET['username']) ? $_GET['username'] : '';
$password = isset($_GET['password']) ? $_GET['password'] : '';
$province = isset($_GET['province']) ? $_GET['province'] : '';
if(isset($_POST['btn-update']))
{
$user_id = $_GET['user_id'];
$username = $_POST['username'];
$password = $_POST['password'];
$province = $_POST['province'];
if($crud->update($user_id,$username,$password,$province))
{
echo "<script type='text/javascript'>alert('Record was updated Successfully!');</script>";
}
else
{
echo "<script type='text/javascript'>alert('Updating Failed!'); </script>";
}
}
if(isset($_GET['user_id']))
{
$user_id = $_GET['user_id'];
extract($crud->getID($user_id));
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-type" content="text/html; charset=UTF-8">
<title>Survey Update Landholdings</title>
<link rel="shortcut icon" href="image/icon.ico"/>
<link rel="stylesheet" type="text/css" href="css/bootstrap.css">
<div class="container">
<p><strong>Survey Update</strong></p>
<br />
<div id="Survey-Update">
<form method='post'>
<table class='table table-bordered'>
<tr>
<td>First Name</td>
<td><input type='text' name='username' class='form-control' value="<?php echo $username; ?>" required></td>
</tr>
<tr>
<td>Last Name</td>
<td><input type='text' name='password' class='form-control' value="<?php echo $password; ?>" required></td>
</tr>
<tr>
<td>Province</td>
<?php
include_once 'dbconfig.php';
$sql = "SELECT username FROM sample";
$stmt = $DB_con->prepare($sql);
$stmt->execute();
$results = $stmt->fetchAll(PDO::FETCH_ASSOC);
if ($stmt->rowCount() > 0)
{
?>
<td><select class='form-control' name='province'>
<option selected="selected" disabled>---</option>
<?php foreach ($results as $row)
{
?>
<option value="<?php echo $row['username']; ?>"><?php echo $row['username']; ?></option>
<?php
}
?>
</select>
<?php
}
?>
</td>
</tr>
<tr>
<td colspan="2">
<button type="submit" class="btn btn-primary" name="btn-update">
<span class="edit"></span>Update</button>
CANCEL
</td>
</tr>
</table>
</form>
</div>
the error is in this line
$province = $_POST['province'];
Change this line
<option selected="selected" disabled>---</option>
to
<option selected="selected" value="" disabled>---</option>
to send an empty value for province instead of none.
Edit: the above code does not work.
The issue here is the disabled and selected="selected". It seems, disabled options don't get submitted.
If you want to stick with disabled and selected I suggest using
$province = isset($_POST['province']) ? $_POST['province'] : '';

OpenCart text at login page doesnt get changed if I change lines in language files

I run an opencart shop 1.5.6.4 with vqmod installed.
I installed xml from opencart in order to force a login before reaching my shop. So it's a closed shop. I customized my login page inside css to hide all menu bars and I "copied" the language selector from the shop into the login page.
It's working, but since then the language texts from the connected language files don't get recognized anymore and the login page texts are like "entry_password". But in the language folders/files I connected them correctly.
Do you have any hints how to fix this?
Yes, I could write them directly into my login.tpl but then I would only have one language available.
I tried to uninstall all vqmod xmls via vqmod manager and got the same result.
It looks like the language isn't loaded correctly, but I really don't know why.
This is my login.tpl in catalog/view/theme/default/template/account:
<?php echo $header; ?>
<style>
INLINE CSS
</style>
<div id="banner">
<center><img src="BANNER URL" alt="header" /></center><br/>
</div>
<?php if ($success) { ?>
<div class="success">Login erfolgreich</div>
<?php } ?>
<?php if ($error_warning) { ?>
<div class="warning">Login fehlgeschlagen</div>
<?php } ?>
<div id="content">
<div class="login-content">
<div class="left">
<h2><?php echo $text_new_customer; ?></h2>
<div class="content">
<p><b><?php echo $text_register; ?></b></p>
<p><?php echo $text_register_account; ?></p>
<?php echo $button_continue; ?></div>
</div>
<div class="right">
<form action="<?php echo $action; ?>" method="post" enctype="multipart/form-data">
<div id="language_selector">Sprache | Language<br>
<img src="image/flags/de.png" alt="Deutsch" title="Deutsch" onclick="$('input[name=\'language_code\']').attr('value', 'de'); $(this).parent().parent().submit();">
<img src="image/flags/gb.png" alt="English" title="English" onclick="$('input[name=\'language_code\']').attr('value', 'en'); $(this).parent().parent().submit();">
<img src="image/flags/nl.png" alt="Nederlands" title="Nederlands" onclick="$('input[name=\'language_code\']').attr('value', 'nl'); $(this).parent().parent().submit();">
<input type="hidden" name="language_code" value="">
<input type="hidden" name="redirect" value="http://MYDOMAIN/opencart/index.php?route=account/login">
</div>
<div class="content">
<h2>Login</h2>
<b>E-Mail:</b><br />
<input type="text" name="email" value="<?php echo $email; ?>" />
<br />
<br />
<b>Password</b><br />
<input type="password" name="password" value="<?php echo $password; ?>" />
<br />
<?php echo $text_forgotten; ?><br />
<br />
<input type="submit" value="<?php echo $button_login; ?>" class="button" />
<?php if ($redirect) { ?>
<input type="hidden" name="redirect" value="<?php echo $redirect; ?>" />
<?php } ?>
</div>
</form>
</div>
</div>
<?php echo $content_bottom; ?></div>
<script type="text/javascript"><!--
$('#login input').keydown(function(e) {
if (e.keyCode == 13) {
$('#login').submit();
}
});
//--></script>
<?php echo $footer; ?>
I want to change the div class content in order to make the h2 and b fields in multilanguage by reading it out from the language-php files:
<div class="content">
<h2><?php echo $text_login; ?></h2>
<b><?php echo $entry_email; ?></b><br />
<input type="text" name="email" value="<?php echo $email; ?>" />
<br />
<br />
<b><?php echo $entry_password; ?></b><br />
<input type="password" name="password" value="<?php echo $password; ?>" />
<br />
<?php echo $text_forgotten; ?><br />
<br />
<input type="submit" value="<?php echo $button_login; ?>" class="button" />
<?php if ($redirect) { ?>
<input type="hidden" name="redirect" value="<?php echo $redirect; ?>" />
<?php } ?>
</div>
this is a language-file login.php example: (located in /catalog/language/english/account/)
<?php
// Heading
$_['heading_title'] = 'Account Login';
// Text
$_['text_account'] = 'Account';
$_['text_login'] = 'Login';
$_['text_new_customer'] = 'New Customer';
$_['text_register'] = 'Register Account';
$_['text_register_account'] = 'By creating an account you will be able to shop faster, be up to date on an order\'s status, and keep track of the orders you have previously made.';
$_['text_returning_customer'] = 'Returning Customer';
$_['text_i_am_returning_customer'] = 'I am a returning customer';
$_['text_forgotten'] = 'Forgotten Password';
// Entry
$_['entry_email'] = 'E-Mail Address:';
$_['entry_password'] = 'Password:';
// Error
$_['error_login'] = 'Warning: No match for E-Mail Address and/or Password.';
$_['error_approved'] = 'Warning: Your account requires approval before you can login.';
?>
this is my controller-file login.php example which should connect $entry_email, $entry_password and $text_login into the active language file (english language file see above).
It is located in /catalog/controller/account
<?php
class ControllerAccountLogin extends Controller {
private $error = array();
public function index() {
$this->load->model('account/customer');
// Login override for admin users
if (!empty($this->request->get['token'])) {
$this->customer->logout();
$this->cart->clear();
unset($this->session->data['wishlist']);
unset($this->session->data['shipping_address_id']);
unset($this->session->data['shipping_country_id']);
unset($this->session->data['shipping_zone_id']);
unset($this->session->data['shipping_postcode']);
unset($this->session->data['shipping_method']);
unset($this->session->data['shipping_methods']);
unset($this->session->data['payment_address_id']);
unset($this->session->data['payment_country_id']);
unset($this->session->data['payment_zone_id']);
unset($this->session->data['payment_method']);
unset($this->session->data['payment_methods']);
unset($this->session->data['comment']);
unset($this->session->data['order_id']);
unset($this->session->data['coupon']);
unset($this->session->data['reward']);
unset($this->session->data['voucher']);
unset($this->session->data['vouchers']);
$customer_info = $this->model_account_customer->getCustomerByToken($this->request->get['token']);
if ($customer_info && $this->customer->login($customer_info['email'], '', true)) {
// Default Addresses
$this->load->model('account/address');
$address_info = $this->model_account_address->getAddress($this->customer->getAddressId());
if ($address_info) {
if ($this->config->get('config_tax_customer') == 'shipping') {
$this->session->data['shipping_country_id'] = $address_info['country_id'];
$this->session->data['shipping_zone_id'] = $address_info['zone_id'];
$this->session->data['shipping_postcode'] = $address_info['postcode'];
}
if ($this->config->get('config_tax_customer') == 'payment') {
$this->session->data['payment_country_id'] = $address_info['country_id'];
$this->session->data['payment_zone_id'] = $address_info['zone_id'];
}
} else {
unset($this->session->data['shipping_country_id']);
unset($this->session->data['shipping_zone_id']);
unset($this->session->data['shipping_postcode']);
unset($this->session->data['payment_country_id']);
unset($this->session->data['payment_zone_id']);
}
$this->redirect($this->url->link('common/home'));
}
}
if ($this->customer->isLogged()) {
$this->redirect($this->url->link('common/home'));
}
$this->language->load('account/account');
$this->document->setTitle($this->language->get('heading_title'));
if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) {
unset($this->session->data['guest']);
// Default Shipping Address
$this->load->model('account/address');
$address_info = $this->model_account_address->getAddress($this->customer->getAddressId());
if ($address_info) {
if ($this->config->get('config_tax_customer') == 'shipping') {
$this->session->data['shipping_country_id'] = $address_info['country_id'];
$this->session->data['shipping_zone_id'] = $address_info['zone_id'];
$this->session->data['shipping_postcode'] = $address_info['postcode'];
}
if ($this->config->get('config_tax_customer') == 'payment') {
$this->session->data['payment_country_id'] = $address_info['country_id'];
$this->session->data['payment_zone_id'] = $address_info['zone_id'];
}
} else {
unset($this->session->data['shipping_country_id']);
unset($this->session->data['shipping_zone_id']);
unset($this->session->data['shipping_postcode']);
unset($this->session->data['payment_country_id']);
unset($this->session->data['payment_zone_id']);
}
// Added strpos check to pass McAfee PCI compliance test (http://forum.opencart.com/viewtopic.php?f=10&t=12043&p=151494#p151295)
if (isset($this->request->post['redirect']) && (strpos($this->request->post['redirect'], $this->config->get('config_url')) !== false || strpos($this->request->post['redirect'], $this->config->get('config_ssl')) !== false)) {
$this->redirect(str_replace('&', '&', $this->request->post['redirect']));
} else {
$this->redirect($this->url->link('common/home'));
}
}
$this->data['breadcrumbs'] = array();
$this->data['breadcrumbs'][] = array(
'text' => $this->language->get('text_home'),
'href' => $this->url->link('common/home'),
'separator' => false
);
$this->data['breadcrumbs'][] = array(
'text' => $this->language->get('text_account'),
'href' => $this->url->link('account/account', '', 'SSL'),
'separator' => $this->language->get('text_separator')
);
$this->data['breadcrumbs'][] = array(
'text' => $this->language->get('text_login'),
'href' => $this->url->link('account/login', '', 'SSL'),
'separator' => $this->language->get('text_separator')
);
$this->data['heading_title'] = $this->language->get('heading_title');
$this->data['text_new_customer'] = $this->language->get('text_new_customer');
$this->data['text_register'] = $this->language->get('text_register');
$this->data['text_register_account'] = $this->language->get('text_register_account');
$this->data['text_returning_customer'] = $this->language->get('text_returning_customer');
$this->data['text_i_am_returning_customer'] = $this->language->get('text_i_am_returning_customer');
$this->data['text_forgotten'] = $this->language->get('text_forgotten');
$this->data['entry_email'] = $this->language->get('entry_email');
$this->data['entry_password'] = $this->language->get('entry_password');
$this->data['button_continue'] = $this->language->get('button_continue');
$this->data['button_login'] = $this->language->get('button_login');
if (isset($this->error['warning'])) {
$this->data['error_warning'] = $this->error['warning'];
} else {
$this->data['error_warning'] = '';
}
$this->data['action'] = $this->url->link('account/login', '', 'SSL');
$this->data['register'] = $this->url->link('account/register', '', 'SSL');
$this->data['forgotten'] = $this->url->link('account/forgotten', '', 'SSL');
// Added strpos check to pass McAfee PCI compliance test (http://forum.opencart.com/viewtopic.php?f=10&t=12043&p=151494#p151295)
if (isset($this->request->post['redirect']) && (strpos($this->request->post['redirect'], $this->config->get('config_url')) !== false || strpos($this->request->post['redirect'], $this->config->get('config_ssl')) !== false)) {
$this->data['redirect'] = $this->request->post['redirect'];
} elseif (isset($this->session->data['redirect'])) {
$this->data['redirect'] = $this->session->data['redirect'];
unset($this->session->data['redirect']);
} else {
$this->data['redirect'] = '';
}
if (isset($this->session->data['success'])) {
$this->data['success'] = $this->session->data['success'];
unset($this->session->data['success']);
} else {
$this->data['success'] = '';
}
if (isset($this->request->post['email'])) {
$this->data['email'] = $this->request->post['email'];
} else {
$this->data['email'] = '';
}
if (isset($this->request->post['password'])) {
$this->data['password'] = $this->request->post['password'];
} else {
$this->data['password'] = '';
}
if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/account/login.tpl')) {
$this->template = $this->config->get('config_template') . '/template/account/login.tpl';
} else {
$this->template = 'default/template/account/login.tpl';
}
$this->children = array(
'common/column_left',
'common/column_right',
'common/content_top',
'common/content_bottom',
'common/footer',
'common/header'
);
$this->response->setOutput($this->render());
}
protected function validate() {
if (!$this->customer->login($this->request->post['email'], $this->request->post['password'])) {
$this->error['warning'] = $this->language->get('error_login');
}
$customer_info = $this->model_account_customer->getCustomerByEmail($this->request->post['email']);
if ($customer_info && !$customer_info['approved']) {
$this->error['warning'] = $this->language->get('error_approved');
}
if (!$this->error) {
return true;
} else {
return false;
}
}
}
?>
What I already tried:
- Replace login.tpl with original default login.tpl (in catalog/view/theme/default/template/account)
- Remove all vqmod xml's from vqmod manager.
Thanks in advance for your help.
language-file login.php
$_['text_email1'] = 'Email Address';
$_['text_pass1'] = 'Password';
controller-file login.php
$this->data['email1'] = $this->language->get('text_email1');
$this->data['pass1'] = $this->language->get('text_pass1');
Login.tpl
<div class="content">
<h2><?php echo $text_login ?></h2>
<b><?php echo $email1 ?></b><br />
<input type="text" name="email" value="<?php echo $email; ?>" />
<br />
<br />
<b> <?php echo $pass1 ?> </b><br />
<input type="password" name="password" value="<?php echo $password; ?>" />
<br />
<?php echo $text_forgotten; ?><br />
<br />
<input type="submit" value="<?php echo $button_login; ?>" class="button" />
<?php if ($redirect) { ?>
<input type="hidden" name="redirect" value="<?php echo $redirect; ?>" />
<?php } ?>
</div>
Add the code in language and controller file,and change div class content with this.