Input type submit won't trigger when it's clicked - codeigniter

I have trouble with my code, I want to create an upload button to upload my .xlsx file, but it won't trigger even when I try to click it.
My view.php :
<form action="<?php echo base_url("index.php/fin/cost_control/workingcanvas/import"); ?>" method="post" id="import_form" enctype="multipart/form-data">
<p><label>Pilih File Excel</label>
<input type="file" name="file" id="file" required accept=".xls, .xlsx" /></p>
<br />
<input type="submit" id="import" name="import" value="Import" class="btn btn-info" />
</form>
My controller:
public function import(){
include APPPATH.'third_party/PHPExcel/PHPExcel.php';
$excelreader = new PHPExcel_Reader_Excel2007();
$loadexcel = $excelreader->load('excel/'.$this->filename.'.xlsx');
$sheet = $loadexcel->getActiveSheet()->toArray(null, true, true ,true);
$numrow = 1;
foreach($sheet as $row){
if($numrow > 1){
array_push($data, array(
'nis'=>$row['A'],
'nama'=>$row['B'],
'jenis_kelamin'=>$row['C'],
'alamat'=>$row['D'],
));
}
$numrow++;
}
$this->SiswaModel->insert_multiple($data);
redirect("Siswa");
}
and my model:
public function insert_multiple($data){
$this->db->insert_batch('siswa', $data);
}
I've tried with adding some part on autoload such as
$autoload['helper'] = array('url','form','file');
Any suggestions or advice? Thanks.

first load form helper in autoload file of codeigniter or load manually
$autoload['helper'] = array('url'); // autoload
$this->load->helper->('form'); // manually loading form helper
you better use this
$attributes = array('enctype' => 'multipart/form-data');
echo form_open('index.php/fin/cost_control/workingcanvas/import', $attributes);
<your upload form code>
<?php echo form_close(); ?>
instead of tags
more info: https://codeigniter.com/user_guide/helpers/form_helper.html

Related

File does not exist (ncjoes/office-converter, laravel)

i was using ncjoes/office-converter, trying to upload .docx and convert it to .pdf, but it occurred error when it converts to .pdf
the error shows NcJoes\OfficeConverter\OfficeConverterException
File does not exist --test.docx
view
<form action="/notes" method="POST" role="form" enctype="multipart/form-data">
#csrf
#method('POST')
<div>
<label for="title">title:</label>
<input id="title" name="title">
</div>
<div>
<label for="topdf">upload:</label>
<input type="file" id="topdf" name="topdf">
</div>
<button type="submit" class="btn-sm btn-primary">add</button>
</form>
controller
public function store(Request $request)
{
$validatedData = $request->validate([
'topdf' => 'required|mimes:docx',
'title'=>'required'
]);
$Name = str_replace(" ","",$request->input('title'));
$FileName = $Name . '.' . $request->topdf->extension();
$request->topdf->move(public_path('pdf'), $FileName);
$converter = new OfficeConverter($FileName);
//$fin=$converter->convertTo('output-file.pdf');
//$fin->move(public_path('pdf'), $FileName);
}
i think $converter = new OfficeConverter($FileName); was wrong, but idk how to fix ;;
First upload the file this way:
$file = $request->file('topdf')->store('pdf');
$path = Storage::path($file);
And then, try to access the file and convert via the $path variable:
$converter = new OfficeConverter($path);

Codeigniter Radio button form validation?

I want to validate three radio button inputs using codeigniter form validation rule:
HTML Page
<form action="<?php echo base_url('register')" ?> method="POST">
<input type="radio" name="cars" value="BMW">
<input type="radio" name="cars" value="Ferrari">
<input type="radio" name="cars" value="Jaguar">
<input type="submit" name="submitter">
</form>
Controller
public function register()
{
$this->form_validation->set_rules('cars', 'Cars', 'required');
if($this->form_validation->run() == TRUE)
{
i know what to do here
}
else
{
i know what to do here
}
}
How to do form validation in codeigniter for radio button in my case ?
Load library for form validation and other helpers in application/config/autoload.php
$autoload['libraries'] = array('form_validation');
$autoload['helper'] = array('form', 'url');
In your controller
public function register()
{
$this->form_validation->set_rules('cars', 'Cars', 'required');
if($this->form_validation->run() == TRUE)
{
echo "success";
}
else
{
$this->load->view('welcome_message');
}
}
In your view file use below code for printing validation errors
<?php echo validation_errors(); ?>
To show form error use form_error() function and to show all error use <?php echo validation_errors(); ?>
HTML PAGE
<form action="<?php echo base_url('register'); ?>" method="POST">
<?php echo form_error('cars'); ?>
<input type="radio" name="cars" value="BMW">
<input type="radio" name="cars" value="Ferrari">
<input type="radio" name="cars" value="Jaguar">
<input type="submit" name="submitter">
</form>
Controller
public function register(){
$this->load->helper(array('form', 'url'));
$this->load->library('form_validation');
$this->form_validation->set_rules('cars', 'Cars', 'required');
if($this->form_validation->run() == TRUE)
{
echo "i know what to do here"; //die;
}
else
{
echo "i know what to do here"; //die;
}
$this->load->view('welcome_message'); // your html view page
}
I think you are looking for in_list validation as an addition to required that has been mentioned by the others.
$this->form_validation->set_rules('cars', 'Cars', 'required|in_list[BMW,Ferrari,Jaguar]');
Also, as a self-reminder, since it took me 1 year to know about this.

CLI stopped working error

I get "CLI stopped working" error when i press the upload button.I used the sample code from one of the website to upload file into the database column. I use Laravel 5.2.39. command used: php artisan serve
Code:(Only test version)
Form.blade.php
<form method="post" enctype="multipart/form-data" action="/upload_file">
{{ csrf_field() }}
<input type="file" name="file" />
<input type="submit" name="submit" value="upload" />
</form>
Routes.php
(Not an ideal place to code this but it is only for file upload test purpose)
Route::get('/upload_form', function()
{
$data['files'] = Attachment::get();
return View::make('form', $data);
});
Route::post('/upload_file', function()
{
$rules = array(
'file' => 'required|mimes:doc,docx,pdf',
);
$validator = Validator::make(Request::all(), $rules);
if(Request::hasFile('file'))
{
$f = Request::file('file');
$att = new Attachment;
$att->name = $f->getClientOriginalName();
$att->file = base64_encode(file_get_contents($f->getRealPath()));
$att->mime = $f->getMimeType();
$att->size = $f->getSize();
$att->save();
return Redirect::to('/upload_form');
}
});
Has anyone encountered this issue? Need help.

Checkout Observer Modification 1.7+

this is about me tinkering again to see if this modification works:
I modified the Mage/Checkout/Model/Observer.php:
public function salesQuoteSaveAfter($observer)
{
$quote = $observer->getEvent()->getQuote();
Start of added code --- > $post = Mage::app()->getRequest()->getPost();//Mage::app()->getRequest()->getPost();
if(isset($post['shipping']['email'])){
if(isset($_SESSION['emailadd'])){
unset($_SESSION['emailadd']);
$_SESSION['emailadd'] = 'test2#mail.com';//$post['shipping']['email'];
}else{
$_SESSION['emailadd'] = 'test#mail.com';//$post['shipping']['email'];
}
}else{
if(isset($_SESSION['emailadd'])){
unset($_SESSION['emailadd']);
$_SESSION['emailadd'] = 'test3#mail.com';//$post['shipping']['email'];
}else{
$_SESSION['emailadd'] = 'test4#mail.com';//$post['shipping']['email'];
}
} <--End of added code;
/* #var $quote Mage_Sales_Model_Quote */
if ($quote->getIsCheckoutCart()) {
Mage::getSingleton('checkout/session')->getQuoteId($quote->getId());
}
}
the problem is this code: is returning nothing which sets the session['emailadd'] = test4#mail.com
$post = Mage::app()->getRequest()->getPost();
if my code is in the wrong method, how do I add a salesQuoteSaveBefore() method that is called before sending the data in the database? is there an XML to configure before doing so?
because first what I'm aiming at is just to get the input data or post data from the onepage/checkout inputs specially the shipping[email] input, don't tell me that there is none because there is:
<li>
<div class="input-box">
<label for="shipping:emailadd"><?php echo $this->__('Email Address') ?> <span class="required">*</span></label><br />
<input type="text" name="shipping['email']" id="shipping:emailadd" value="<?php echo $this->htmlEscape($this->getAddress()->getEmail()) ?>" title="<?php echo $this->__('Email Address') ?>" class="validate-email required-entry input-text" />
</div>
<div class="input-box">
<label for="shipping:emailadd"><?php echo $this->__('Confirm Email') ?> <span class="required">*</span></label><br />
<input type="text" name="shipping[emailconfirm]" id="shipping:emailconfirm" value="<?php echo $this->htmlEscape($this->getAddress()->getEmail()) ?>" title="<?php echo $this->__('Email Address') ?>" class="validate-email required-entry input-text" />
</div>
</li>
all I want to get is this one single shipping[email] input, it's kinda buggy because I'm stuck with for so long already. but I can't find a way to get it's value after onepage/checkout is submitted.
Any help would be appreciated.
First thing is you were editing core files. This is not appreciated.
You can get shipping email easily from controllers. Using Event Absorber is good method than over writing files. But that is hard to compare over writing .
Just overwrite the OnepageController.php at core->Mage->checkout->controllers.
Here is the code,
include_once("Mage/Checkout/controllers/OnepageController.php");
class Pakagename_Modulename_OnepageController extends Mage_Checkout_OnepageController
{
public function saveBillingAction()
{
if ($this->_expireAjax()) {
return;
}
if ($this->getRequest()->isPost()) {
// $postData = $this->getRequest()->getPost('billing', array());
// $data = $this->_filterPostData($postData);
$data = $this->getRequest()->getPost('billing', array());
$customerAddressId = $this->getRequest()->getPost('billing_address_id', false);
if (isset($data['email'])) {
$data['email'] = trim($data['email']);
}
Here the problem is customer may use different email for shipping and billing. So you need to checkout both shipping and billing save actions.
add to session
$email = $data['email'];
Mage::getSingleton('core/session')->setMyValue($email);
Then here I assume that you were trying to edit order e-mail template.
1) Edit sendNewOrderEmail() function located in
app/code/core/Mage/Sales/Model/Order.php
$my_email = Mage::getSingleton('core/session')->getMyValue();
$mailer->setTemplateParams(array(
'order' => $this,
'billing' => $this->getBillingAddress(),
'payment_html' => $paymentBlockHtml,
'my_email' => "$my_email" //New custom value
));
Then hereafter you can fetch that email like this
{{ var my_email }}
If you want edit invoice template then you should find out corresponding function to define custom email variable. That's all..!

Joomla Component not saving data

I have a component that used to work (Without setting HTML tags to the description) and now after trying to get the HTML formatting to work it won't save.
com_lot\views\lot\tmpl\form.php:
<?php defined('_JEXEC') or die('Restricted access');
$document =& JFactory::getDocument();
$document->addScript('includes/js/joomla.javascript.js');
require_once(JPATH_ADMINISTRATOR .DS. 'components' .DS. 'com_jce' .DS. 'helpers' .DS. 'browser.php');
?>
<form action="index.php" method="post" name="adminForm" id="adminForm">
<script language="javascript" type="text/javascript">
function submitbutton(pressbutton) {
var form = document.adminForm;
if (pressbutton == 'cancel') {
submitform( pressbutton );
return;
}
<?php
$editor =& JFactory::getEditor();
echo $editor->save( 'description' );
?>
submitform(pressbutton);
}
</script>
...
<tr>
<td width="100" align="right" class="key">
<label for="description">
<?php echo JText::_( 'Description' ); ?>:
</label>
</td>
<td>
<?php
$editor =& JFactory::getEditor();
echo $editor->display('description', $this->lotdata->description, '550', '400', '60', '20', false);
?>
</td>
</tr>
...
<input type="hidden" name="option" value="com_lot" />
<input type="hidden" name="lotid" value="<?php echo $this->lotdata->lotid; ?>" />
<input type="hidden" name="task" value="" />
<input type="hidden" name="controller" value="lot" />
<?php echo JHTML::_( 'form.token' ); ?>
<button type="button" onclick="submitbutton('save')"><?php echo JText::_('Save') ?></button>
<button type="button" onclick="submitbutton('cancel')"><?php echo JText::_('Cancel') ?></button>
</form>
com_lot\models\lot.php:
function store($data)
{
// get the table
$row =& $this->getTable();
// Bind the form fields to the hello table
if (!$row->bind($data)) {
$this->setError($this->_db->getErrorMsg());
return false;
}
// Make sure the hello record is valid
if (!$row->check()) {
$this->setError($this->_db->getErrorMsg());
return false;
}
// Store the web link table to the database
if (!$row->store()) {
$this->setError( $row->getErrorMsg() );
return false;
}
return true;
}
function save()
{
// Check for request forgeries
JRequest::checkToken() or jexit( 'Invalid Token' );
// get the model
$model =& $this->getModel();
//get data from request
$post = JRequest::get('post');
$post['description'] = JRequest::getVar('description', '', 'post', 'string', JREQUEST_ALLOWRAW);
// let the model save it
if ($model->store($post)) {
$message = JText::_('Success');
} else {
$message = JText::_('Error while saving');
$message .= ' ['.$model->getError().'] ';
}
$this->setRedirect('index.php?option=com_lot', $message);
}
Any help appreciated.
Edit: I have seen stuff about JForms and having XML files... is this applicable? I haven't found anywhere that says what they're used for, just what types there are...
I found the problem (once I'd cleaned up the code a bit) was that in the article I was following (http://docs.joomla.org/How_to_use_the_editor_in_a_component) missed changing store() to store($data).
Because the pages redirect etc it doesn't die and error out. Thanks to for Jan for your help.

Resources