What is the pattern for creating a multilingual input in opencart for admin side.
For example I want to have two List Description Limit inputs, one for each language.
Like in this image. So I can control from admin side the list limit for every language.
Currently I use this pattern to create a custom input, but this is not language dependent:
File: admin/view/template/extension/theme/theme_default.tpl
<fieldset>
<div class="form-group required">
<label class="col-sm-2 control-label" for="inputId"><span data-toggle="tooltip" title="<?php echo $help_inputName; ?>"><?php echo $label_inputName; ?></span></label>
<div class="col-sm-10">
<input type="text" name="theme_default_inputName" value="<?php echo $theme_default_inputName; ?>" placeholder="<?php echo $label_inputName; ?>" id="inputId" class="form-control" />
<?php if ($error_inputName) { ?>
<div class="text-danger"><?php echo $error_inputName; ?></div>
<?php } ?>
</div>
</div>
</fieldset>
File: admin/language/en-gb/extension/theme/theme_default.php
//Language strings
$_['help_inputName'] = 'helpTxt';
$_['label_inputName'] = 'labelForInput';
$_['error_inputName'] = 'errorForInput';
File: admin/controller/extension/theme/theme_default.php
//Language strings
$text_strings = array(
'help_inputName',
'label_inputName',
'error_inputName'
);
foreach ($text_strings as $text) {
$data[$text] = $this->language->get($text);
}
//Error handling
if (isset($this->error['inputName'])) {
$data['error_inputName'] = $this->error['inputName'];
} else {
$data['error_inputName'] = '';
}
//Custom field
if (isset($this->request->post['theme_default_inputName'])) {
$data['theme_default_inputName'] = $this->request->post['theme_default_inputName'];
} elseif (isset($setting_info['theme_default_inputName'])) {
$data['theme_default_inputName'] = $setting_info['theme_default_inputName'];
} else {
$data['theme_default_inputName'] = "customText";
}
//Validation
if (!$this->request->post['theme_default_inputName']) {
$this->error['inputName'] = $this->language->get('error_inputName');
}
Related
I've tried everything to code upload the image file but I still stuck and it keeps an error. It can't detect the data of the image file so it can't store to the database when I submitted the form. I saw every tutorial I've been searched and look into my code seems everything right but why it still keeps an error.
Controller
public function create()
{
if (!$this->session->userdata('user_logged')) {
redirect('Auth');
}
$data["title"] = "Form Create Blog";
$data["landingpage"] = false;
$data['content'] = 'component/admin/blog/blog_create';
$this->form_validation->set_rules('blogTitle', 'Title tidak boleh kosong', 'required|max_length[50]');
$this->form_validation->set_rules('blogHeaderImg', 'Header Image tidak boleh kosong', 'required');
$this->form_validation->set_rules('blogKeyword', 'Keyword tidak boleh kosong', 'required|max_length[50]');
$this->form_validation->set_rules('blogContent', 'Content tidak boleh kosong', 'required');
if ($this->form_validation->run() == FALSE) {
$this->load->view('index', $data);
} else {
$config['upload_path'] = realpath(APPPATH . '../assets/img/upload/blog/header_image');
$config['allowed_types'] = 'jpg|png|PNG';
$nmfile = time() . "_" . $_FILES['blogHeaderImg']['name'];
$config['file_name'] = $nmfile;
$this->load->library('upload', $config);
if (!$this->upload->do_upload("blogHeaderImg")) {
$error = array('error' => $this->upload->display_errors());
echo '<div class="alert alert-danger">' . $error['error'] . '</div>';
} else {
$data = array('upload_data' => $this->upload->data());
$header_image = $data['upload_data']['file_name'];
$this->M_Blog->storeBlogData($header_image);
print_r($_FILES['blogHeaderImg']);
$this->session->set_flashdata('flashAddBlog', 'Data berhasil <strong>ditambahkan</strong>');
redirect('blog');
}
}
}
Model
public function storeBlogData($header_image)
{
$data = [
'title' => $this->input->post('blogTitle', TRUE),
'header_image' => $header_image,
'content' => $this->input->post('blogContent', TRUE),
'blog_keyword' => $this->input->post('blogKeyword', TRUE),
'created_by' => $this->session->userdata('user_logged')->id,
'last_modified_by' => $this->session->userdata('user_logged')->id,
'is_deleted' => 'n'
];
$this->db->insert('blog', $data);
}
View
<form method="POST" action="create" enctype="multipart/form-data">
<div class="form-group">
<label for="blogTitle">Title</label>
<input class="form-control" type="text" name="blogTitle" id="blogTitle" placeholder="Title">
<small class="form-text text-danger"><?= form_error('blogTitle') ?></small>
</div>
<div class="form-group">
<label for="blogHeaderImg">Header Image</label>
<input class="form-control-file" type="file" id="blogHeaderImg" name="blogHeaderImg">
<small class="form-text text-danger"><?= form_error('blogHeaderImg') ?></small>
</div>
<div class="form-group">
<label for="blogKeyword">Keyword</label>
<input class="form-control" type="text" id="blogKeyword" name="blogKeyword" placeholder="Keyword">
<small class="form-text text-danger"><?= form_error('blogKeyword') ?></small>
</div>
<div class="form-group">
<label for="blogContent">Content</label>
<textarea class="form-control" type="text" id="blogContent" name="blogContent" placeholder="Content" rows="10"></textarea>
<small class="form-text text-danger"><?= form_error('blogContent') ?></small>
</div>
<button class="btn btn-primary" type="submit">Submit</button>
</form>
already solved. I just have to add this code to blog controller
if (empty($_FILES['blogHeaderImg']['name'])) {
$this->form_validation->set_rules('blogHeaderImg', 'Document', 'required');
}
instead of using this code
$this->form_validation->set_rules('blogHeaderImg', 'Header Image tidak boleh kosong', 'required');
thank you
I am trying to create a simple drag and drop page using php. When I click the "submit" button, I get an error: Notice: Undefined index: file in C:\xampp\htdocs\phpfiles\DragAndDrop\includes\gallery-upload.inc.php on line 13. Why is it not reading the "file" index from the htmlphp?
Here is the HTML and PHP code:
enter code here
<!--continuted from HTML page-->
</section>
<?php
$_SESSION['username'] = "Admin";
if (isset($_SESSION['username'])) {
echo '<div class="gallery-upload">
<form action="includes/gallery-upload.inc.php" method="post" enctype="mutipart/form-data">
<input type="text" name="filename" placeholder="File Name...">
<input type="text" name="filetitle" placeholder="Image Title...">
<input type="text" name="filedesc" placeholder="Image description...">
<input type="file" name="file">
<button type="submit" name="submit">Upload</button>
</form>
</div>';
}
?>
</main>
</body>
</html>
<!--and the php page-->
<?php
if (isset($_POST['submit'])) {//checks submit form and posts the info
$newFileName = $_POST['filename'];
if (empty($_POST['filename'])) { //if filename is emptly
$newFileName = "gallery"; //if filename is empty, generates name
} else {
$newFileName = strtolower(str_replace(" ", "-", $newFileName)); //if spaces are in the name, creates stringholder
}
$imageTitle = $_POST['filetitle'];
$imageDesc = $_POST['filedesc'];
$file = $_FILES['file'];
}
?>
You have a typo:
mutipart/form-data
Should be
multipart/form-data
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
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.
Help please... I can send tweets, but when try to upload with media says "missing or invalid url parameter"
I tryed with many ways of define "media", only url, getfilecontent("url"), "#"."url", and more...
I use Abrahams library (twitteroauth)
This is my code:
<?php
session_start();
require_once('twitteroauth/twitteroauth.php');
require_once('config.php');
if (empty($_SESSION['access_token']) || empty($_SESSION['access_token']['oauth_token']) || empty($_SESSION['access_token']['oauth_token_secret'])) {
header('Location: ./clearsessions.php');
}
$access_token = $_SESSION['access_token'];
$connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, $rowTwitter["twitter_token"], $rowTwitter["twitter_token_secret"]);
$msg = $_POST["texto2"];
$image = $_POST["URL"];
$parameters = array(
'media[]' => "{$image}",
'status' => "{$msg}"
);
$code = $connection->post('statuses/update_with_media', $parameters);
var_dump($code);
?>
And this is the result:
object(stdClass)#5 (1) { ["errors"]=> array(1) { [0]=> object(stdClass)#6 (2) { ["code"]=> int(195) ["message"]=> string(33) "Missing or invalid url parameter." } } }
EDITED: Hi again! I added this code:
$filename = $image;
$handle = fopen($filename, "rb");
$image = fread($handle, filesize($filename));
fclose($handle);
And now this is the problem:
object(stdClass)#5 (1) { ["errors"]=> array(1) { [0]=> object(stdClass)#6 (2) { ["code"]=> int(189) ["message"]=> string(22) "Error creating status." } } }
i did it using modified library
---html---
<form action="" method="POST" enctype="multipart/form-data">
<div>
<label for="status">Tweet Text</label>
<textarea type="text" name="status" rows="5" cols="60"></textarea>
<br />
<label for="image">Photo</label>
<input type="file" name="image" />
<br />
<input type="submit" value="Submit" />
</div>
</form>
---php---
if (!empty($_FILES)) {
// we set the type and filename are set here as well
$params = array(
'media[]' => "#{$_FILES['image']['tmp_name']};type={$_FILES['image']['type']};filename={$_FILES['image']['name']}",
'status' => $_POST['status']
);
$dd = $twitteroauth->post('statuses/update_with_media',$params,true);
var_dump($dd);
}
download modified library here
https://github.com/tomi-heiskanen/twitteroauth/blob/77795ff40e4ec914bab4604e7063fa70a27077d4/twitteroauth/twitteroauth.php