I have been hunting around for a solution to this problem I am trying to resolve.
Here is the scenario:
I want to issue a single use voucher code for every purchase made between two specified dates. The voucher is to be redeemed between another two specified dates. The voucher must be single use only, but could potentially be given away if the original purchaser doesn't want/need it.
Each customer can be assigned any number of individual voucher codes - one to be issued per purchase.
The voucher code should be automatically generated and emailed to them with their order confirmation, so there is no manual work required.
Can someone help either with usable code for Magento 1.6.2, or point me towards a plugin that might do the job?
I have contacted MageStore about their offering to ask if it fits my needs, but thought I would ask the question here in case I can get an answer/solution faster, as they are not available at this time.
=== Final working solution ===
I found code in various places that each had bits that helped, but not one overall working solution for me. Eventually, I managed to hack this together into a module - here is the observer.php part of that module (the crux of the beast). I hope it helps someone!
Note - this code worked for ME in MY scenario. I cannot offer any support on this, and take no responsibility for it's use in your application - please make use of it as you see fit.
<?php
/**
* Our class name should follow the directory structure of
* our Observer.php model, starting from the namespace,
* replacing directory separators with underscores.
* i.e. app/code/local/SmashingMagazine/
* LogProductUpdate/Model/Observer.php
*/
class Robgt_AutoVoucher_Model_Observer
{
/**
* Magento passes a Varien_Event_Observer object as
* the first parameter of dispatched events.
*/
public function autoVoucher(Varien_Event_Observer $observer)
{
// Should we run this code at all?
// Between 17th at midnight and 24th at midday December 2012 ONLY
$from = strtotime('2012-12-17 00:00:01');
$to = strtotime('2012-12-24 11:59:59');
$now = time();
if($from <= $now && $to >= $now) {
//Get the Order ID
$order = $observer->getEvent()->getOrder();
$orderEntityId = $order->getId();
$orderid = $order->getIncrementId();
//$orderid = Mage::getSingleton('checkout/session')->getLastRealOrderId();
if(empty($orderid))
{
$orderid = '999999999';
}
// Grab the last 3 digits of the Order number for use in the voucher code
$last_orderNumberDigits = substr($orderid, -3, 3);;
// Create coupon code random part
$codeLength = 7;
$chars = "ABCDEFGHIJKLMNPQRSTUVWXYZ1234567890";
srand((double)microtime()*1000000);
$i = 0;
$code = '' ;
while ($i <= $codeLength)
{
$num = rand() % 33;
$tmp = substr($chars, $num, 1);
$code = $code . $tmp;
$i++;
}
$couponRandomCode = $code;
// Build coupon code
// Format is: MH[Last 3 Digits of Order number]-[5 Random digits]
$couponCode = 'MH'.$last_orderNumberDigits.'-'.$couponRandomCode;
$couponName = 'Xmas2012 - '.$couponCode;
// Build the coupon rule
$rule = Mage::getModel('salesrule/rule');
$rule->setName($couponName);
$rule->setDescription('Xmas 2012 Discount coupon');
$rule->setFromDate('2013-01-01'); // Jan 1st
$rule->setToDate('2013-01-31'); // Jan 31st
$rule->setCouponType(2);
$rule->setCouponCode($couponCode);
$rule->setUsesPerCoupon(1);
$rule->setUsesPerCustomer(1);
$rule->setCustomerGroupIds('0,1,3,4');
$rule->setIsActive(1);
$conditions = array(
"1" => array(
'type' => 'salesrule/rule_condition_combine',
'aggregator' => 'all',
'value' => 1,
'new_child' => false
),
"1--1" => array(
'type' => 'salesrule/rule_condition_product_found',
'value' => 1,
'aggregator' => 'all',
'new_child' => false
),
"1--1--1" => array(
'type' => 'salesrule/rule_condition_product',
'attribute' => 'category_ids',
'operator' => '!()',
'value' => '932,341,800,1116'
)
);
$actions = array(
"1" => array(
"type" => "salesrule/rule_condition_product",
"aggregator" => "all",
"value" => "1",
"new_child" => false
),
"1--1" => array(
"type" => "salesrule/rule_condition_product",
"attribute" => "category_ids",
'operator' => '!()',
'value' => '932,341,800,1116'
)
);
$rule->setData('conditions',$conditions);
$rule->setData("actions",$actions);
$rule->setStopRulesProcessing(1);
$rule->setIsAdvanced(1);
$rule->setProductIds('');
$rule->setSortOrder(0);
$rule->setSimpleAction('by_percent');
$rule->setDiscountAmount(10);
$rule->setDiscountStep(0);
$rule->setSimpleFreeShipping(0);
$rule->setTimesUsed(0);
$rule->setIsRss(0);
$rule->setWebsiteIds('1');
$rule->loadPost($rule->getData());
$rule->save();
// Email the details to Trev
$to = 'trevor.wallinger#gmail.com';
//$to = 'robgt.com#gmail.com';
$subject = 'New Xmas 2012 Voucher Code';
$message = '<body style="background:#F6F6F6; font-family:Verdana, Arial, Helvetica, sans-serif; font-size:12px; margin:0; padding:0;">
<div style="background:#F6F6F6; font-family:Verdana, Arial, Helvetica, sans-serif; font-size:12px; margin:0; padding:0;">
<table cellspacing="0" cellpadding="0" border="0" height="100%" width="100%">
<tr>
<td align="center" valign="top" style="padding:20px 0 20px 0">
<!-- [ header starts here] -->
<table bgcolor="FFFFFF" cellspacing="0" cellpadding="10" border="0" width="650" style="border:1px solid #E0E0E0;">
<tr>
<td valign="top">
<h1 style="font-size:22px; font-weight:normal; line-height:22px; margin:0 0 11px 0;">A new coupon code was generated, as follows:</h1>
<p style="font-size:12px; line-height:16px; margin:0 0 8px 0;"><strong>Order Number:</strong> '.$orderid.'</p>
<p style="font-size:12px; line-height:16px; margin:0 0 8px 0;"><strong>Coupon Code:</strong> '.$couponCode.'</p>
</td>
</tr>
</table>
</td>
</tr>
</table>
</div>
</body>
';
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
try {
mail($to, $subject, $message, $headers);
$mailReport = 'Mail sent!';
}
catch(Exception $ex) {
$mailReport = "Mail failed to send!";
}
// Log the voucher code generated
// Saved to /var/log/coupons.log
Mage::log(
"Coupon created: {$couponCode} | Order ID: {$orderid} | Mail Report: {$mailReport}\n\r",
null,
'coupons.log'
);
} // End If Date check.
}
}
Related
currently i am working on order report i am fetching all order records but except status i have last_status column id which is defined by id with every order but i want to show status with order please help me how can i do that ? Does anyone have an idea please help me thanks.
status codes
'0' = 'Pending',
'1' = 'Info Received',
'2' = 'In Transit',
'3' = 'Out for Delivery',
'4' = 'Failed Attempt',
'5' = 'Delivered',
'6' = 'Exception',
'7' = 'Expired',
'8' = 'Canceled',
'9' = 'Void',
reportController
public function report(Request $request)
{
$data = [];
// sets the start date at index 0 and ending date at index 1
$date = explode(' - ', $request->date);
$Order = Order::with('users');
$order = $Order->whereBetween('created_at', $date)
->orderBy('created_at', 'desc')
->get();
$data = [
'orders' => $order,
];
// return $data['orders'];
return view('cms.reports.report-list', $data);
}
html view
<table class="table table-bordered table-striped" cellspacing="0" cellpadding="0">
<thead>
<tr>
<th>Order Id</th>
<th>Customer Name</th>
<th>Status</th>
<th>Order Received Date</th>
</tr>
</thead>
<tbody>
#foreach($orders as $order)
<tr>
<td>{{$order->id}}</td>
<td>{{$order->users->fname ?? null}} {{$order->users->lname ?? null}}</td>
<td>{{$order->last_status}}</td>
<td>{{$order->created_at}}</td>
</tr>
#endforeach
</tbody>
<tfoot>
</tfoot>
</table>
Rather than having to add a CASE statement every time you query, you could add the status to a config file and reference from there.
config/orders.php
<?php
return [
'status' => [
0 => [
'label' => 'Pending',
'color' => 'grey',
],
1 => [
'label' => 'Info Received',
'color' => 'teal',
],
2 => [
'label' => 'In Transit',
'color' => 'blue',
],
...
],
];
create a blade component:
resources/views/components/status-label.blade.php
<span
class="text-sm font-medium bg-{{ config('orders.status.'.$status.'color') }}-100 py-1 px-2 rounded text-{{ config('orders.status.'.$status.'color') }}-500 align-middle">
{{ config('orders.status.'.$status.'label') }}
</span>
Then in your blade file, you can do:
<x-status-label :status="$order->last_status" />
you can do this way...
in order model class
public function orderStatus()
{
switch($this->order_status){
case '1':
return 'Info Received';
break ;
case '2':
return 'In Transit';
break ;
default:
return 'Pending';
}
}
in view
{{ $order->orderStatus() }}
solution with html markup
in order model class
public function orderStatus()
{
switch($this->order_status){
case '1':
return '<span class="label label-warning">Info Received</span>';
break ;
case '2':
return '<span class="label label-info">In Transit</span>';
break ;
default:
return '<span class="label label-danger">Pending</span>';
}
in view
{!! $order->orderStatus() !!}
and css class
.label {
color:white;
display:inline-bolck;
paddign:3px;
text-align: center;
line-height:25px;
min-width: 50px;
}
.label-info{
background:blue;
}
.label-danger{
background:red;
}
quantity not update only If I add an item with the exact same options more than once to my cart, it replaces instead of increasing the qty of the existing item
This is cart view code
`<table class="table table-bordered table-hover">
<thead ><!-- Table head -->
<tr>
<th class="active">Sl</th>
<th class="active col-sm-4">Product</th>
<th class="active col-sm-2">Real Price</th>
<th class="active ">Qty</th>
<th class="active ">Disc Price</th>
<th class="active">Total</th>
<th class="active">Action</th>
</tr>
</thead><!-- / Table head -->
<tbody><!-- / Table body -->
<?php $cart = $this->cart->contents() ;
?>
<?php $counter =1 ; ?>
<?php if (!empty($cart)): foreach ($cart as $item) : ?>
<tr class="custom-tr">
<td class="vertical-td">
<?php echo $counter ?>
</td>
<td class="vertical-td"><?php echo $item['name'] ?></td>
<td class="vertical-td"><?php echo $item['pkprice'] ?></td>
<td class="vertical-td">
<input type="text" name="qty" style="width: 50px" value="<?php echo $item['qty'] ?>" onblur ="order(this);" id="<?php echo 'qty'.$item['rowid'] ?>" class="form-control">
</td>
<td>
<div class="input-group">
<span class="input-group-addon">
<input type="checkbox" id="<?php echo 'opt'.$item['rowid'] ?>" onclick="return price_checkbox(this)" name="custom_price"
<?php echo $item['price_option'] == 'custom_price' ? 'checked':'' ?>
data-placement="top" data-toggle="tooltip" data-original-title="Custom Price">
</span>
<input type="text" name="price" value="<?php echo $item['price'] ?>" onblur ="order(this);" id="<?php echo 'pri'.$item['rowid'] ?>" class="form-control"
<?php echo $item['price_option'] == 'custom_price' ? '':'disabled' ?> >
</div>
<input type="hidden" name="product_code" value="<?php echo $item['id'] ?>" id="<?php echo 'code'.$item['rowid'] ?>">
</td>
<td class="vertical-td"><?php echo number_format($item['subtotal'], 2, '.', ',') ?></td>
<td class="vertical-td">
<?php echo btn_delete('admin/order/delete_cart_item/' . $item['rowid']); ?>
</td>
</tr>
<?php
$counter++;
endforeach;
?><!--get all sub category if not this empty-->
<?php else : ?> <!--get error message if this empty-->
<td colspan="6">
<strong>There is no record for display</strong>
</td><!--/ get error message if this empty-->
<?php endif; ?>
</tbody><!-- / Table body -->
`
This is Controller Code
public function add_cart_item_by_barcode(){
$product_code = $this->input->post('barcode', true);
$result = $this->order_model->validate_add_cart_item($product_code);
if($result){
$price = $this->check_product_rate($result->product_id, $qty=1);
//product tax check
$tax = $this->product_tax_calculate($result->tax_id, $qty=1, $price);
$data = array(
'id' => $result->product_code,
'qty' => 1,
'price' => $price,
'buying_price' => $result->buying_price,
'name' => $result->product_name,
'pkprice' => $result->p_price,
'tax' => $tax,
'price_option' => 'general'
);
$this->cart->update($data);
$this->session->set_flashdata('cart_msg', 'add');
}
redirect('admin/order/new_order/'.$flag ='add');
}
public function check_product_rate($product_id=null, $qty=null)
{
//tier Price check
$tire_price = $this->order_model->get_tire_price($product_id, $qty);
if($tire_price)
{
return $price = $tire_price->tier_price ;
}
//special offer check
$this->tbl_special_offer('special_offer_id');
$offer_price = $this->global_model->get_by(array("product_id"=>$product_id), true);
if(!empty($offer_price)) {
$today = strtotime(date('Y-m-d'));
$start_date = strtotime($offer_price->start_date);
$end_date = strtotime($offer_price->end_date);
if (($today >= $start_date) && ($today <= $end_date)) {
return $price = $offer_price->offer_price;
}
}
//return regular rate
$this->tbl_product_price('product_price_id');
$general_price = $this->global_model->get_by(array("product_id"=>$product_id), true);
return $product_price = $general_price->selling_price;
}
/*** Product tax calculation ***/
public function product_tax_calculate($tax_id, $qty ,$price)
{
$this->tbl_tax('tax_id');
$tax = $this->global_model->get_by(array('tax_id'=>$tax_id), true);
//1 = tax in %
//2 = Fixed tax Rate
if($tax){
if($tax->tax_type == 1)
{
$subtotal = $price * $qty;
$product_tax = $tax->tax_rate * ($subtotal / 100);
//return $result = round($product_tax, 2);
return $result = $product_tax;
}else
{
//$product_tax = $tax->tax_rate * $qty;
$product_tax = $tax->tax_rate * $qty;
return $result = $product_tax;
}
}
}
/*** Update Product Cart ***/
public function update_cart_item()
{
$rowid = $this->input->post('rowid');
$qty = $this->input->post('qty');
$product_price = $this->input->post('price');
$product_code = $this->input->post('product_code');
$custom_price = $this->input->post('custom_price');
if($qty !=0 )
{
//tbl product
$this->tbl_product('product_id');
$result = $this->global_model->get_by(array('product_code'=> $product_code ), true);
//product Inventory Check
$this->tbl_inventory('inventory_id');
$product_inventory = $this->global_model->get_by(array('product_id'=> $result->product_id ), true);
if($qty > $product_inventory->product_quantity)
{
$type = 'error';
$message = 'Sorry! This product has not enough stock.';
set_message($type, $message);
echo 'false';
return;
}
if($custom_price == "on")
{
$price = $product_price;
$price_option = 'custom_price';
}
else
{
//product price check
$price = $this->check_product_rate($result->product_id, $qty);
$price_option = 'general';
}
//product tax check
$tax = $this->product_tax_calculate($result->tax_id, $qty, $price);
$data = array(
'rowid' => $rowid,
'qty' => $qty,
'price' => $price,
'tax' => $tax,
'price_option' => $price_option
);
}else
{
$data = array(
'rowid' => $rowid,
'qty' => $qty,
);
}
$this->cart->update($data);
if($this->input->post('ajax') != '1'){
redirect('admin/order/new_order'); // If javascript is not enabled, reload the page with new data
}else{
echo 'true'; // If javascript is enabled, return true, so the cart gets updated
}
}
/*** Show cart ***/
function show_cart(){
$this->load->view('admin/order/cart/cart');
}
/*** cart Summery ***/
function show_cart_summary(){
$this->load->view('admin/order/cart/cart_summary');
}
/*** Delete Cart Item ***/
public function delete_cart_item($id)
{
$data = array(
'rowid' => $id,
'qty' => 0,
);
$this->cart->update($data);
$this->session->set_flashdata('cart_msg', 'delete');
redirect('admin/order/new_order/'.$flag ='delete');
}
This is working fine when add product or change its quantity all perfect working but If I add an item with the exact same options more than once to my cart, it replaces instead of increasing the qty of the existing item
Have you tried this?
<?php foreach ($this->cart->contents() as $items): ?>
<?php echo form_hidden($counter.'[rowid]', $items['rowid']); ?> // write this
and then this
<td><?php echo form_input(array('name' => $counter.'[qty]', 'value' => $items['qty'], 'maxlength' => '3', 'size' => '5')); ?></td>
instead of-
<?php echo form_input(array('name' =>'rowid1[]', 'type'=>'text', 'value' => $items['rowid'], 'maxlength' => '3', 'size' => '5')); ?>
I hope this works
Check what query is generated when update query is fire, i think any signal quote is added in your query.
for check the last database query use this function:-
print_r($this->db->last_query());
After a lot of struggled i get my code correctly here is the correct code of insert and update
function add_cart_item_by_barcode(){
$product_code = $this->input->post('barcode', true);
$result = $this->order_model->validate_add_cart_item($product_code);
$rowid = $this->input->post('rowid');
$cart = $this->cart->contents();
foreach ($cart as $cart) {
if($product_code == $cart['id']){
$rowid=$cart['rowid'];
$qty=$cart['qty'];
$data=array(
'rowid'=>$rowid,
'qty'=>$qty+1
);
$data=$this->cart->update($data);
$this->session->set_flashdata('cart_msg', 'add');
redirect('admin/order/new_order/'.$flag ='add');
}
}
if ($result) {
// update rate
$price = $this->check_product_rate($result->product_id, $qty=1);
//product tax check
$tax = $this->product_tax_calculate($result->tax_id, $qty=1, $price);
$data = array(
'id' => $result->product_code,
'qty' => $qty,
'price' => $price,
'buying_price' => $result->buying_price,
'name' => $result->product_name,
'pkprice' => $result->p_price,
'tax' => $tax,
'price_option' => 'general'
);
$this->cart->insert($data);
$this->session->set_flashdata('cart_msg', 'add');
}
redirect('admin/order/new_order/'.$flag ='add');
}
In yii2 I am displaying images from the daabase and for the same images I have comments in the database table. I want the image description to be below the image, which i am not able to achieve.
My code.
<div class="margin-top-20">
<h5> <p class="details-edit"> <i class="fa fa-picture-o"></i> GHS Pictograms </p> </h5>
<div class="panel panel-default panel-edit">
<div class="panel-body">
<?php
$images = '';
$a = '';
// append all images
// var_dump($data->getPictogramPath()); exit();
foreach($model->getPictogramPath() as $name)
$images =$images.' '.Html::img(\Yii::$app->request->BaseUrl.'/web'.$name->pictogram_filepath,['alt'=>'','width'=>'100','height'=>'100', 'data-toggle'=>'tooltip','data-placement'=>'left','title' => $name->pictogram_comment ,'style'=>'cursor:default;']).Html::label($name->pictogram_comment,['class' => 'pictogram-label']);
$a = $a.Html::label($name->pictogram_comment);
echo ($images);
?>
</div>
</div>
</div>
My output is :
I am not able to get the label below the image.. Can anyone sugggest me what is the issue here?
Thank you..
You need to have a little change on your html structure. First of all need wrap each image and label in block, also need make a couple changes in your css files.
You code will look like this:
$images = '';
$a = '';
// Append all images
foreach($model->getPictogramPath() as $name) {
$images .= Html::beginTag('div', ['class' => 'img-and-label-wrapper']);
$images .= Html::img(\Yii::$app->request->BaseUrl. '/web' . $name->pictogram_filepath, ['alt' => '', 'width' => '100', 'height' => '100', 'data-toggle' => 'tooltip', 'data-placement' => 'left', 'title' => $name->pictogram_comment ,'style'=>'cursor:default;']);
$images .= Html::label($name->pictogram_comment,['class' => 'pictogram-label']);
$images .= Html::endTag('div');
}
echo $images;
Here styles that you need to add:
.img-and-label-wrapper {
display : inline-block;
}
.img-and-label-wrapper label{
display: block;
text-align: center;
}
Guess this will helpful for you
What i want is, i have a uniq id call num i want insert mutiple description for that unique num. i have a form to add fileds dynamically so i can add fields as much i want. when i try to insert one row data its works perfectly when i try to insert more than one row data it doesn't work.
My View page :
<form name="codexworld_frm" action="" method="post">
<div class="field_wrapper">
<input type="text" name="num" value=""/><br />
<input type="text" name="description[]" value=""/><input type="text" name="voucher_no[]" value=""/><input type="text" name="price[]" value=""/>
<img src="<?php echo base_url('images/add-icon.png'); ?>"/>
</div>
<input type="submit" name="submit" value="SUBMIT"/>
</form>
My Controller :
$data = array(
'no' => $this->input->post('num'),
'descriptions' => $this->input->post('description'),
'voucher' => $this->input->post('voucher_no'),
'des_price' => $this->input->post('price'),
);
$this->multi_model->form_insert($data);
$data['message'] = 'Data Inserted Successfully';
//Loading View
$this->load->view('multi_view', $data);
My Model:
function form_insert($data){
$this->db->insert('tbl_description', $data);
}
if i use foreache loop into my model i think it will work but i how do i use ?
When i use print_r() function this is out put
1001
Array
(
[0] => description1
[1] => description2
[2] => description3
)
Array
(
[0] => voucher 1
[1] => voucher 2
[2] => voucher 3
)
Array
(
[0] => 100
[1] => 200
[2] => 300
)
see this link it is use multiple insert without loop or you can use your foreach loop in controller count description post and go through it.
$data = array();
$count = count($this->input->post['description']);
for($i=0; $i < $count; $i++) {
$data[] = array(
'no'=>$this->input->post('num'),
'descriptions' => $this->input->post['descriptions'][$i],
'voucher' => $this->input->post['voucher'][$i],
'des_price' => $this->input->post['des_price'][$i],
);
}
$this->db->insert_batch('tbl_description', $data);
Hope this will helps you..
Controller
//if voucher_no is required..
$voucher_no = $this->input->post('voucher_no');
$count = count($voucher_no);
if ($count > 0) {
for ($i = 0; $i < $count; $i++) {
if (!empty($voucher_no[$i])) {
$data = array(
'no' => $this->input->post('num'),
'descriptions' => $this->input->post('description')[$i],
'voucher' => $this->input->post('voucher_no')[$i],
'des_price' => $this->input->post('price')[$i],
);
$this->multi_model->form_insert($data);
}
}
}
$data['message'] = 'Data Inserted Successfully';
//Loading View
$this->load->view('multi_view', $data);
Let us know the results..
change model as following.
function form_insert($data){
foreach($data['description'] as $key=>$des)
{
$savedata = array(
'no' => $data('no'),
'descriptions' => $des,
'voucher' => $data['voucher'][$key],
'des_price' => $data['dec_price'][$key],
);
$this->db->insert('tbl_description', $savedata);
}
}
you can insert object wise.
in your controller:-
$value=$this->input->post('num');
$count=count($val);
for($i=0; $i<$count; $i++){
$data['no']=$this->input->post('num')[$i];
$data['description']=$this->input->post('description')[$i];
$data['voucher']=$this->input->post('voucher')[$i];
$data['prize']=$this->input->post('prize')[$i];
$this->multi_model->form_insert($data);
}
I am new to CakePHP. I have two problem with the view.
There is line break between text field name and text field area. I have tried to pass 'div' => false but that didn't work. How can I remove line break and display both on same line?
I have added validation rule to this textfield but when I click save Error message doesn't show up. Do I need to do something else beside adding validates in my model?
Here is my view input.ctp
echo $this->Form->input('fileId', array(
'type'=>'text',
'style' => 'width: 200px; height: 15px'
));
echo $this->Form->end('Save Post');
Here is my model:
var $validate = array(
'fileId' => 'notEmpty',
'message' => 'Should not be empty'
);
Controller:
if ($this->request->is('post')) {
$data = $this->request->data;
if ($data) {
// saving the data
}
}
If you are not using save then you need to manually validate the data using validates. In such case you also need to set the data. For e.g. in your controller
$this->ModelName->set($data);
$this->Modelname->validates();
For validate your data, you should have something like this:
public $validate = array(
'fileId' => array(
'rule' => 'notEmpty',
'message' => 'Should not be empty'
)
);
And your Controller:
if ($this->request->is('post')) {
if ($this->Model->save($this->request->data)) {
// saved
}
}
If you can not save, the error will be shown near the corresponding field. Or you can customize your error using $this->Model->validationErrors array.
For the line break question, make sure that 200px does the automatic line break because of where these elements are positioned.
validation errors appear when validates() or save() was called.
setup your action completely.
If you're not using FormHelper::input, which outputs the field, label and error, you need to manually output the error as well using $this->Form->error('fileId').
And for the form try this:
add this to your css
label { float: left;
width: 150px;
display: block;
clear: none;
text-align: left;
vertical-align: middle;
padding-right: 0px;}
.xg {
display: block;
float:left;
}
echo $this->Form->input('fileId', array('div'=>'xg','type'=>'text', 'style' => 'width: 200px; height: 15px'));
echo $this->Form->end('Save Post');
you can customize your output by following method:
<tr>
<td><label>Username</label></td>
<td>
<?php echo $this->Form->input('username',array('label'=>false,'div'=>false,'error'=>false)); ?>
</td>
<td><?php echo $this->Form->error('username'); ?></td>
</tr>
This method will give you output in same line.