How change html View of ZF1 captcha - php

i am not using captcha in zend form i am directly writting zend captch code on controller. My code is:
IndexController.php
public function loginAction(){
$this->view->assign('action',"/sabkuch/index/auth");
$this->view->assign('user','username');
$this->view->assign('passwd','Password');
//$a=$this->_helper->Comman->textEmail("hi........","htm body.......","pkr","from#gm.com","xyz","xyz#gm.com");
//echo $a; die;
// Our form object...
// And here's our captcha object...
$captcha = new Zend_Form_Element_Captcha('captcha',
array('label' => 'Write the chars to the field',
'captcha' => array( // Here comes the magic...
// First the type...
'captcha' => 'Image',
'useNumbers' => true,
'fontSize' => '22',
'wordLen' => '4',
'height' => '57',
'width' => '235',
// Captcha timeout, 5 mins
'timeout' => 300,
// What font to use...
'font' => APPLICATION_PATH . '/../public/font/6.ttf',
// Where to put the image
'imgDir' => APPLICATION_PATH . '/../public/captcha/',
// URL to the images
// This was bogus, here's how it should be... Sorry again :S
'imgUrl' => 'http://localhost/sabkuch/public/captcha/',
)));
$this->view->captcha = $captcha;
}
Login.phml
<table width="100%" border="0" cellspacing="0" cellpadding="1">
<form class="form_align" name="login" method="post" action="<?php echo $this->escape($this->action);?>">
<tbody>
<tr>
<td align="left"><strong><?php echo $this->escape($this->user);?></strong></td>
</tr>
<tr>
<td align="left"><?php echo $this->formText('username', '', array(
'class' => 'textfield',
'alt' => 'NOBLANK~loginEmail~DM~',
'size' => '30',
)
); ?>
</td>
</tr>
<tr>
<td align="left"><strong><?php echo $this->escape($this->passwd);?></strong></td>
</tr>
<tr>
<td align="left"><?php echo $this->formPassword('passwd', '', array(
'class' => 'textfield',
'alt' => 'NOBLANK~loginEmail~DM~',
'size' => '30',
)
); ?>
</td>
</tr>
<tr>
<td align="left"><strong>Set Captcha</strong></td>
</tr>
<tr>
<td align="left"><?php
echo $this->captcha->render($this, null) ;
?>
</td></tr>
<tr>
<td align="left" style="padding-top:5px">
<?php echo $this->formHidden('id', 'login'); ?>
<input type="submit" name="submit" value="Submit"> </td>
</tr>
</tbody>
</form>
</table>
captch code output is
<dd id="captcha-element">
<img width="235" height="57" alt="" src="http://localhost/sabkuch/public/captcha/770eec95f4b247754b4b6c30cd74a4a4.png" />
<input type="hidden" name="captcha[id]" value="770eec95f4b247754b4b6c30cd74a4a4" id="captcha-id" />
<input type="text" name="captcha[input]" id="captcha-input" value="" /></dd>
i need captcha html output as per my requirement like
<tr><td> <dd id="captcha-element">
<img width="235" height="57" alt="" src="http://localhost/sabkuch/public/captcha/770eec95f4b247754b4b6c30cd74a4a4.png" />
<input type="hidden" name="captcha[id]" value="770eec95f4b247754b4b6c30cd74a4a4" id="captcha-id" />
</tr></td>
<tr><td>
<input type="text" name="captcha[input]" id="captcha-input" value="" /></dd>
</tr></td>
in zend form we cn add decoratro but i am directly using this captcha on controller How i change this ouput of html

Related

How to update image with form hidden?

Hi all I am a new codeigniter .I have create code update image with form hidden but I have problam the from hidden not passing value to form image userfile :( Iam very need help now ?or could anyone give the source code about update image in to database on codigniter.
<form action="<?php echo base_url()."./site_admin/update_menu/".$this->uri->segment(3); ?>" method="post" enctype="multipart/form-data">
<?php
$id = $this->uri->segment(3);
$sql = $this->db->get_where('menu',array('id_menu' => $id));
$row = $sql->row(); ?>
<?php $idcat = $row->cate_id ?>
<table class="tab" style="width:100%">
<tr>
<td>Categories Name:</td>
<td>
<select style="padding:6px;background:#C2C2C2;font-weight: bold;" name="cate">
<?php
$query = $this->db->get('categories_menu');
foreach($query->result() as $lazy){
$select = "";
if($lazy->id == $idcat){
$select = "selected";
}
echo "<option $select value='".$lazy->id."'>".$lazy->cate_name_menu."</option>";
}
?>
</select>
</td>
</tr>
<tr>
<td>Upload image:</td>
<td><input type="file" name="userfile" style="width:190px;height:35px;font-weight: bold;background:#C2C2C2;" ></td>
<td><input type="hidden" name="mono" value="<?php echo $row->image; ?>"></td>
</td>
</tr>
<tr>
<td>Title:</td>
<td><textarea class="title" name="title" cols="100" rows="4"><?php echo $row->title; ?></textarea></td>
</tr>
<tr>
<td>Description:</td>
<td><textarea rows="15" name="description" class="dess" ><?php echo $row->description; ?></textarea><td>
</tr>
<tr>
<td>Prices</td>
<td><textarea class="price" name="price" cols="40" rows="4"><?php echo $row->prices; ?></textarea></td>
</tr>
<tr>
<td></td>
<td>
<input style="width:100px; padding:10px;font-weight: bold;background:#1F1F1F;color:white;" type="submit" value="Submit" name="submit">
</td>
</tr>
</table>
</form>
Controller:
function update_menu(){
$id = $this->uri->segment(3);
$img1 = $this->input->post('userfile');
$img2 = $this->input->post('mono');
if($img1 == ""){
$img1 = $img2;
$datas = array(
'cate_id' => $this->input->post('cate'),
'title' => $this->input->post('title'),
'description' => $this->input->post('description'),
'prices' => $this->input->post('price'),
'image' => $img1
);
$this->db->where('id_menu', $id);
$this->db->update('menu',$datas);
redirect('./site_admin/edit_menu/'.$id);
}else{
$id = $this->uri->segment(3);
$updata = array(
'upload_path' => './images/',
'allowed_types' => 'gif|jpg|png',
'max_size' => '5000',
'max_width' => '4000',
'max_height' => '2800'
);
$this->load->library('upload',$updata);
$this->upload->do_upload('userfile');
$nampic = $this->upload->data();
$data = array(
'cate_id' => $this->input->post('cate'),
'title' => $this->input->post('title'),
'description' => $this->input->post('description'),
'prices' => $this->input->post('price'),
'image' => $nampic['file_name']
);
$this->db->where('id_menu', $id);
$this->db->update('menu',$data);
redirect('./site_admin/edit_menu/'.$id);
}
}

Copy database contents from one table to another table in codeigniter

I need to copy table contents from table: user_openletter to table: country on clicking archive button. How to write a query to copy from,to,title,openletter,open_id from user_openletter to another table country. This a codeigniter app.
my controller code is :
public function store_user_data_archieve()
{
$match = $this->input->post('submit');
echo $match;
if($match == "Archieve")
{
$data = array(
'open_id' => $this->input->post('open_id'),
'featured' => '1',
'from' => $this->input->post('from'),
'to' => $this->input->post('to'),
'title' => $this->input->post('title'),
'archieve' => '1',
'latest' => '0',
'sponsor' => 'images/sponsor.png'
);
$this->load->database();
//load the model
$this->load->model('select');
//load the method of model
$data['r']=$this->select->store_user_data_archieve($data);
echo "success";
}
else if(!$match == "new")
{
$data = array(
'open_id' => $this->input->post('open_id'),
'featured' => '1',
'from' => $this->input->post('from'),
'to' => $this->input->post('to'),
'title' => $this->input->post('title'),
'openletter' => $this->input->post('openletter'),
'archieve' => '0',
'latest' => '1',
'sponsor' => 'images/sponsor.png'
);
$this->load->database();
//load the model
$this->load->model('select');
//load the method of model
$data['r']=$this->select->store_user_data_archieve($data);
echo "success";
}
else if(!$match == "Discard")
{
echo "failure";
}
}
My view code is:
<?php
foreach ($r->result() as $row)
{
?>
<table border="1" cellpadding="4" cellspacing="0">
<tr>
<td>from</td>
<td>to</td>
<td>title</td>
<td>openletter</td>
<td>Date & Time</td>
<td>open_id</td>
</tr>
<tr>
<form action="/index.php/welcome/store_user_data_archieve" method="post">
<td><input type="text" name="from" value="<?php echo $row->from;?>" /></td>
<td><input type="text" name="to" value="<?php echo $row->to;?>" /></td>
<td><input type="text" name="title" value="<?php echo $row->title;?>" /></td>
<td><input type="text" name="openletter" value="<?php echo $row->openletter;?>" /></td>
<td><input type="text" name="datetime" value="<?php echo $row->datetime;?>" /></td>
<td><input type="text" name="open_id" value="<?php echo $row->open_id;?>" /></td>
<td><div><input type="submit" name="submit" value="Archieve" /></div></td>
<td><div><input type="submit" name="new" value="new" /></div></td>
</form>
</tr>
</table>
<?php } ?>
My model code is:
public function store_user_data_archieve($data)
{
//data is retrieved from this query
$this->db->insert('country', $data);
$this->db->set('openletter');
$this->db->select('openletter');
$this->db->where('open_id', $data[open_id]);
$this->db->from('user_openletter');
// Produces: INSERT INTO mytable (title, name, date) VALUES ('{$title}', '{$name}', '{$date}')
}
As per our discussion you need to copy from,to,title,openletter,open_id from table user_openletter to country table
$this->db->select('from,to,title,openletter,open_id');// select your filed
$q = $this->db->get('user_openletter')->result(); // get result from table
foreach ($q as $r) { // loop over results
$this->db->insert('country', $r); // insert each row to country table
}
$this->db->select('from, to, title,openletter, open_id');
$result_set = $this->db->get('user_openletter')->result();
if(count($result_set) > 0) {
$this->db->insert_batch('country', $result_set);
}

uploading image and data in mysql table in codeigniter

I'm trying to upload an image with a car make, year, lease and payment data
along with the image upload. My image path is also inserted to the DB but i still cant figure how to combine both.
Im getting an error Array to string conversion and its not inputting my data and image upload.
cars table:
car_make | car_model | car_year | car_lease | car_payment | imgpath
acura | G37 Sedan | 2009 | 48 | 350 | assets/images/acura_1.jpg
controller:
public function car_validation_do_upload() {
$this->load->library('form_validation');
$this->form_validation->set_rules('car_make', 'Car Make', 'required');
$this->form_validation->set_rules('car_model', 'Car Model', 'required');
$this->form_validation->set_rules('car_year', 'Car Year', 'required');
$this->form_validation->set_rules('car_lease', 'Car Lease', 'required');
$this->form_validation->set_rules('car_payment', 'Car Payment', 'required');
if($this->form_validation->run() == TRUE) {
$config['upload_path'] = './assets/images/';
$config['allowed_types'] = 'gif|jpeg|jpg|png';
$this->load->library('upload', $config);
$newRow = array("car_make" => $this->input->post('car_make'),
"car_model" => $this->input->post('car_model'),
"car_year" => $this->input->post('car_year'),
"car_lease" => $this->input->post('car_lease'),
"car_payment" => $this->input->post('car_payment'));
$data = array('upload' => $this->upload->data());
$result = array_merge($newRow, $data);
$this->load->model("model_users");
$this->model_users->insert1($result);
$this->session->set_flashdata('message', 'car inserted into database!');
redirect('main/insertCar');
}
else {
$this->load->view('insert_car');
}
}
Model:
public function insert1($data) {
$this->db->insert("cars", $data);
}
View
<?php
//echo form_open('main/car_validation_insert');
echo form_open_multipart('main/car_validation_do_upload');
echo validation_errors();
if($this->session->flashdata('message')){
echo $this->session->flashdata('message');
}
?>
<table width="504" style="margin-left:15px;">
<tr>
<td colspan="2"><p class="table-title">Insert Car</p></td>
<td></td>
</tr>
<tr>
<td>Car Make: </td>
<td><input type="text" name="car_make" class="textbox" tabindex="1"/></td>
<td> </td>
</tr>
<tr>
<td>Car Model:</td>
<td><input type="text" name="car_model" class="textbox" tabindex="2"/></td>
<td> </td>
</tr>
<tr>
<td>Car Year:</td>
<td><input type="text" name="car_year" class="textbox" tabindex="3"/></td>
<td> </td>
</tr>
<tr>
<td>Car Lease:</td>
<td><input type="text" name="car_lease" class="textbox" tabindex="4"/></td>
<td> </td>
</tr>
<tr>
<td>Car Payment:</td>
<td><input type="text" name="car_payment" class="textbox" tabindex="5"/></td>
<td> </td>
</tr>
<tr>
<td>Car Image:</td>
<td><input type="file" name="userfile" size="20" /></td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
</table>
<input type="submit" name="submit" value="submit" id="button" class="button" style="margin-left:140px;" />
<?php
echo form_close();
?>
Change this:
$data = array('upload' => $this->upload->data());
$result = array_merge($newRow, $data);
To this:
if ($this->upload->do_upload()){
$image_data = $this->upload->data();
//this will create a new key with the name upload in your newRow
//so theres no need to use the function array_merge
$newRow['imgpath'] ='assets/images/'.$image_data['file_name'];
}
else{
//do something here
echo 'error uploading image'
}
The $image_data variable will have this information about your uploaded image
Array
(
[file_name] => mypic.jpg
[file_type] => image/jpeg
[file_path] => /path/to/your/upload/
[full_path] => /path/to/your/upload/jpg.jpg
[raw_name] => mypic
[orig_name] => mypic.jpg
[client_name] => mypic.jpg
[file_ext] => .jpg
[file_size] => 22.2
[is_image] => 1
[image_width] => 800
[image_height] => 600
[image_type] => jpeg
[image_size_str] => width="800" height="200"
)
You can find all the information about the file upload class on the user guide of codeingiter:
http://ellislab.com/codeigniter/user-guide/libraries/file_uploading.html

input multiple value to one row in codeigniter

I have 3 pieces of the column, which I will inserting in one table in my database. The name of each form like this:
<h3><?= $title; ?></h3><?php echo form_open("admin/artikel/buat/");?>
<table width="95%">
<tr>
<td><b>Pilih Referensi Jurnal</b></td>
<td>
<input type="hidden" name="IDJurnal" id="IDJurnal" value="<?php echo $IDJurnal; ?>" />
<input type="text" name="volume" id="volume" value="<?php echo $volume; ?>" readonly="readonly" class="sedang" />
<?php echo anchor_popup('admin/artikel/popup', 'Referensi Jurnal', array('class' => 'button')); ?>
</td>
</tr>
<tr>
<td><b>Kategori</b></td>
<td>
<?php
echo form_dropdown('IDKategori', $kategori) . "";
?>
</td>
</tr>
<tr>
<td width="125"><strong>Judul</strong></td>
<td><input type="text" name="judul" class="panjang"></td>
</tr>
<tr>
<td width="125"><strong>Pengarang</strong></td>
<td>
<input type="text" name="pengarang" class="panjang">
<input type="text" name="pengarang" class="panjang">
<input type="text" name="pengarang" class="panjang">
</td>
</tr>
<tr>
<td><b>Abstract</b></td>
<td>
<?php
$data = array('name' => 'abstract');
echo $this->ckeditor->editor($data['name']);
?>
</td>
</tr>
<tr>
<td></td>
<td>
<input type="submit" class="button" value="Simpan">
<input type="button" class="button" value="Batal" onClick="javascript: history.go(-1)" />
</td>
</tr>
<?php
echo form_close();
?>
i want inserting the value from each form name to my sql table, like this:
CREATE TABLE `pengarang`(
`IDPengarang` INT(11)NOT NULL AUTO_INCREMENT,
`IDArtikel` INT(11)NOT NULL,
`nama_pengarang` VARCHAR(255)NOT NULL,
PRIMARY KEY(`IDPengarang`))ENGINE = INNODB DEFAULT CHARSET = utf8;
in my model like this:
function addArtikel() {
$now = date("Y-m-d H:i:s");
$data = array(
'IDJurnal' => $this->input->post('IDJurnal'),
'IDKategori' => $this->input->post('IDKategori'),
'judul' => $this->input->post('judul'),
'abstract' => $this->input->post('abstract'),
'created_time' => $now,
'created_by' => $_SESSION['username']
);
// $data1 = array(
// 'IDJurnal' => $this->input->post('IDJurnal'),
// 'IDKategori' => $this->input->post('IDKategori'),
// 'judul' => $this->input->post('judul'),
// 'abstract' => $this->input->post('abstract'),
// 'created_time' => $now,
// 'created_by' => $_SESSION['username']
// );
// $data2 = array(
// 'IDArtikel' => $this->input->post('IDArtikel'),
// 'nama_pengarang' => $this->input->post('pengarang')
// );
$this->db->insert('artikel', $data);
// $this->db->insert_batch('artikel', $data1);
// $this->db->insert_batch('pengarang', $data1);
}
in my controller
function buat() {
if ($this->input->post('judul')) {
$this->MArtikel->addArtikel();
$this->session->set_flashdata('message', 'Artikel telah di buat !');
redirect('admin/artikel/index', 'refresh');
} else {
// konfigurasi ckfinder dengan ckeditor
$this->load->library('ckeditor');
$this->load->library('ckfinder');
$this->ckeditor->basePath = base_url() . 'asset/ckeditor/';
$this->ckeditor->config['toolbar'] = 'Full';
$this->ckeditor->config['language'] = 'en';
$this->ckfinder->SetupCKEditor($this->ckeditor, '../../../asset/ckfinder/');
$data['title'] = "Tambah Artikel";
$data['main'] = 'admin/artikel/artikel_buat';
$data['jurnal'] = $this->MJurnal->getJurnalDropDown();
$data['kategori'] = $this->MKategori->getKategoriDropDown();
$this->load->vars($data);
$this->load->view('dashboard/template');
}
}
What should I add to my controller and my model, that would make the results in my table looks like this
IDPengarang IDArtikel nama_pengarang
1 1 testing 1
2 1 testing 2
3 1 testing 3
thank's before

Error in code with Joomla API 1.5: to use a variable that receives a post request with JRequest:: getVar

I am using the joomla framework to return values from a POST request, and the print screen shows me data, but when using the array in sending me to a method and print or send me data.
Here I put the code that I've got gray hair,thanks in advance.
This is the controller:
/**
* Construct (registers additional tasks to methods).
*/
function __construct(){
parent::__construct();
//Registro de tareas extra
$this->registerTask('add','ingresarPlanilla');
}//function
function ingresarPlanilla(){
// Comprueba del request la clave de falsificación
//JRequest::checkToken('post') or die( 'Objeto invalido' );
$task = JRequest::getVar('task');
$model = &$this->getModel('planilla');
if ($returnid = $model->ingresar()) {
switch ($task) {
case 'add' :
$link = '?option=com_mercurio&view=planilla&controller=planilla&task=add';
break;
default :
$link = 'index.php?option=com_mercurio&view=planilla';
break;
}
$msg = JText::_( 'PLANILLA INGRESADA' );
$cache = &JFactory::getCache('com_mercurio');
$cache->clean();
} else {
$msg = 'PLANILLA NO INGRESADA';
$link = 'index.php?option=com_mercurio&view=planilla';
}
//$model->checkin();
$this->setRedirect($link, $msg);
}
}
This is the model:
$cliente = new SoapClient(URLMERCURIOWS.URLWSPLANILLA, array('login'=>LOGINWS,'password'=>PASSWORDWS));
if (is_soap_fault($cliente)) {
trigger_error("SOAP Fault: (faultcode: {$arr->faultcode}, faultstring: {$arr->faultstring})", E_USER_ERROR);
return false;
}
$postost = JRequest::get( 'post', JREQUEST_ALLOWHTML );
$postost['cdPoblacionOrigen'] = JRequest::getVar('cdPoblacionOrigen', '', 'post', 'cdPoblacionOrigen');
$postost['nmSecDniCliente'] = JRequest::getVar('nmSecDniCliente', '', 'post', 'nmSecDniCliente');
$postost['cdAgenciaCliente'] = JRequest::getVar('cdAgenciaCliente', '', 'post', 'cdAgenciaCliente');
$postost['nmPesoTransportado'] = JRequest::getVar('nmPesoTransportado', '', 'post', 'nmPesoTransportado');
$postost['nmVolumenTransportado'] = JRequest::getVar('nmVolumenTransportado', '', 'post', 'nmVolumenTransportado');
$postost['nmUndsTransportadas'] = JRequest::getVar('nmUndsTransportadas', '', 'post', 'nmUndsTransportadas');
$planilla = array();
$planilla = $postost;
echo $postost['cdPoblacionOrigen']."</br>";
echo $postost['nmSecDniCliente']."</br>";
echo $postost['cdAgenciaCliente']."</br>";
echo $postost['nmPesoTransportado']."</br>";
echo $postost['nmVolumenTransportado']."</br>";
echo $postost['nmUndsTransportadas']."</br>";
$cliente->ingresarPlanilla( AGENCIAXDEFECTO, null, null, null, $postost['cdPoblacionOrigen'], $post['nmSecDniCliente'], $post['cdAgenciaCliente'], null, $post['nmPesoTransportado'], $post['nmVolumenTransportado'], $post['nmUndsTransportadas'], null, null, null, null, null, null, null, null, null);
return true;
}
This is the view:
<form id="ingresarPlanilla" name="ingresarPlanilla" method="post" action="?option=com_mercurio&view=planilla&controller=planilla&task=add">
<table width="98%" border="1" bordercolor="#ECE9D8">
<tr>
<td width="21%" class="titulo" align="center">Ingresar Planilla</td>
<td width="29%"> </td>
<td width="21%"> </td>
<td width="29%"> </td>
</tr>
<tr>
<td colspan="2">Agencia Origen</td>
<td colspan="2"><input name="cdAgenciaOrigen" type="text" class="campo_noeditable" id="cdAgenciaOrigen" value="<?php echo AGENCIAXDEFECTO;?>"readonly="readonly"/></td>
</tr>
<tr>
<td colspan="2">Poblacion Origen</td>
<td colsp man="2"><input name="cdPoblacionOrigen" type="text" class="campo" id="cdPoblacionOrigen" /></td>
</tr>
<tr>
<td colspan="2">DNI Cliente</td>
<td colspan="2"><input name="nmSecDniCliente" value="<?php echo $aux[5];?>" type="text" class="campo" id="nmSecDniCliente"/></td>
</tr>
<tr>
<td colspan="2">Peso Transportado</td>
<td colspan="2"><input name="nmPesoTransportado" type="text" class="campo" id="nmPesoTransportado "/></td>
</tr>
<tr>
<td colspan="2">Volumnen Transportado</td>
<td colspan="2"><input name="nmVolumenTransportado" type="text" class="campo" id="nmVolumenTransportado"/></td>
</tr>
<tr>
<td colspan="2">Unidades Transportados</td>
<td colspan="2"><input name="nmUndsTransportadas" type="text" class="campo" id="nmUndsTransportadas"/></td>
</tr>
<tr>
<td colspan="3">Observaciones</td>
</tr>
<tr>
<td colspan="3"><textarea name="observaciones" cols="60" rows="3" class="campo" id="observaciones"></textarea></td>
</tr>
<tr>
<td class="label"><input type="submit" name="Enviar" id="Enviar" value="Enviar" /></td>
</tr>
<input type="hidden" name="option" value="com_mercurio" />
<input type="hidden" name="cdAgenciaCliente" value="<?php echo $aux[6];?>" />
<input type="hidden" name="view" value="<?php echo JRequest::getVar('view'); ?>" />
<input type="hidden" name="task" value="" />
<?php echo JHTML::_( 'form.token' ); ?>
You can use this line below to read all POST data into an array with key value pairs.
$post = JRequest::get('post');
This will load all values into an array. So you would use the above like so:
$post = JRequest::get('post');
echo $post['cdPoblacionOrigen']; // prints value of post for input with name 'cdPoblacionOrigen'

Categories