cakephp-upload won´t validate - php

I´am using the plugin
https://github.com/josegonzalez/cakephp-upload
for image upload.
I won´t to disable adding post without uploaded image.
How to write validation to it?
class BlogContent extends AppModel
{
public $validate = array(
'title' => array(
'rule' => 'notEmpty',
'message' => 'Titulok musí byť zadaný'
),
'text' => array(
'rule' => 'notEmpty',
'required' => true,
'message' => 'Text musí byť zadaný'
),
'photo' => array(
'isUpload' => array(
'rule' => 'isFileUpload',
'required' => true,
'message' => 'Článok musí obsahovať obrázok',
'last' => false
),
'isCompletedUpload' => array(
'rule' => 'isCompletedUpload',
'message' => 'Obrázok nebol úspešne nahratý',
'last' => false
),
'tempDirExists' => array(
'rule' => 'tempDirExists',
'message' => 'Priečinok TEMP nie je dostupný',
'last' => false
),
...
If I use required=> true for isUpload, it will never validates. However if I not type it, it will validates without uploading image.
View code: admin_add.ctp
<div class="blogContents form">
<?php echo $this->Form->create('BlogContent', array('type' => 'file'));
echo $this->Form->input('title', array('label' => 'Titulok'));
echo $this->Form->input('text', array('class' => 'ckeditor', 'label' => ''));
echo $this->Form->input('image', array('label' => '', 'type' => 'file', 'accept' => 'image/*'));
echo $this->Html->link(__('Vybrať obrázok'), '#', array('class' => 'btn btn-default', 'id' => 'upload'));
echo _('<p>Zvolený obrázok:</p>');
echo $this->Html->div('filelist', '<p>Žiaden obrázok nebol zvolený</p>');
echo $this->Form->input('image_dir', array('type' => 'hidden'));
echo $this->Form->input('active', array('label' => 'Publikované'));
echo $this->Form->submit(__('Uložiť článok'), array('class' => 'btn btn-success')) ?>
</div>

Related

CakePHP input stopped working

I'm completely new with cake, so I have no clue what happened.
this code works :
echo $this->Form->input('phone',
array(
'required' => false,
'div' => 'form-group',
'class' => 'form-control',
'label' => array(
'class' => 'control-label',
'text' => __d('admin', 'Tel. numeris')
),
'placeholder' => __d('admin', 'Tel. numeris'),
'error' => array(
'attributes' => array(
'class' => 'alert alert-danger'
)
)
)
);
this one doesn't :
echo $this->Form->input('email',
array(
'required' => false,
'div' => 'form-group',
'class' => 'form-control',
'label' => array(
'class' => 'control-label',
'text' => __d('admin', 'El.paštas')
),
'placeholder' => __d('admin', 'El.paštas'),
'error' => array(
'attributes' => array(
'class' => 'alert alert-danger'
)
)
)
);
and for example if I change email to, lets say, emailas, it works too(but then it doesnt do anything) :
echo $this->Form->input('emailas',
array(
'required' => false,
'div' => 'form-group',
'class' => 'form-control',
'label' => array(
'class' => 'control-label',
'text' => __d('admin', 'El.paštas')
),
'placeholder' => __d('admin', 'El.paštas'),
'error' => array(
'attributes' => array(
'class' => 'alert alert-danger'
)
)
)
);
could someone please help me or at least tell me where to look? The input stopped working out of the blue, so maybe theres a possibility to somehow restart whole plugin? THANK YOU IN ADVANCE
P.S.
This is how the input field looks atm vs how it should look like : http://imgur.com/bBrkgxM
Try this:
echo $this->Form->input('email',
array(
'required' => false,
'div' => 'form-group',
'class' => 'form-control',
'type' => 'email',
'label' => array(
'class' => 'control-label',
'text' => __d('admin', 'El.paštas')
),
'placeholder' => __d('admin', 'El.paštas'),
'error' => array(
'attributes' => array(
'class' => 'alert alert-danger'
)
)
)
);
And make sure you have email field in database and nowhere is overriding email field (in controller / model)

Cakephp trying to validate non existing input

I have never seen this before. I have a form with multiple models connected to one. When I submit the form, Cake is trying to validate fields with no vaildation and it even is trying to validate a field that I changed the name on. I have cleared the model cache in the tmp folder. I am stumped. Here is my code.
View:
echo $this->Form->create('Lead', array('class' => 'form form-vertical'));
echo $this->Form->input('Lead.project_name', array('class' => 'form-control', 'div'=>array('class'=>'col-md-12'), 'value' => 'Project'.$userId));
echo $this->Form->input('Lead.sales_owner', array('class' => 'form-control', 'value' => $fullName, 'div'=>array('class'=>'col-md-4')));
$leadSourceOptions = array('Door to Door' => 'Door to Door','Referral' => 'Referral','Inbound Call' => 'Inbound Call','Self Generated by Closer' => 'Self Generated by Closer','Tradeshows' => 'Tradeshows','Telemarketing' => 'Telemarketing',);
echo $this->Form->input('Lead.lead_source', array('class' => 'form-control', 'type' => 'select', 'options' => $leadSourceOptions, 'div'=>array('class'=>'col-md-4')));
$typeOptions = array('Individual' => 'Individual', 'Business' => 'Business', 'Government' => 'Government');
echo $this->Form->input('Lead.type', array('class' => 'form-control', 'type' => 'select', 'options' => $typeOptions, 'div'=>array('class'=>'col-md-6')));
$taxOptions = array('Individual' => 'Individual', 'Corporation' => 'Corporation', 'LLC (Corporation)' => 'LLC (Corporation)', 'LLC (Non-Corporation)' => 'LLC (Non-Corporation)', 'Partnership' => 'Partnership', 'Sole Proprietor' => 'Sole Proprietor', 'Tax Exempt' => 'Tax Exempt');
echo $this->Form->input('Lead.tax_entity', array('class' => 'form-control', 'type' => 'select', 'options' => $taxOptions, 'div'=>array('class'=>'col-md-6')));
echo $this->Form->input('Customer.first_name', array('class' => 'form-control', 'div'=>array('class'=>'col-md-5')));
echo $this->Form->input('Customer.last_name', array('class' => 'form-control', 'div'=>array('class'=>'col-md-5')));
$titleOptions = array('Mr' => 'Mr', 'Mrs' => 'Mrs', 'Ms' => 'Ms');
echo $this->Form->input('Customer.title', array('class' => 'form-control', 'type' => 'select', 'options' => $titleOptions, 'div'=>array('class'=>'col-md-2')));
echo $this->Form->input('Customer.email', array('class' => 'form-control', 'div'=>array('class'=>'col-md-5')));
echo $this->Form->input('Customer.phone', array('class' => 'form-control', 'placeholder' => '123-456-7890', 'div'=>array('class'=>'col-md-5')));
echo $this->Form->input('Customer.phone_extension', array('required' => false, 'class' => 'form-control', 'label' => 'Ext', 'div'=>array('class'=>'col-md-2')));
$phoneOptions = array('Home' => 'Home', 'Mobile' => 'Mobile', 'Business' => 'Business', 'Business Fax' => 'Business Fax', 'Home Fax' => 'Home Fax', 'Pager' => 'Pager', 'Skype' => 'Skype');
echo $this->Form->input('Customer.phone_type', array('class' => 'form-control', 'type' => 'select', 'options' => $phoneOptions, 'div'=>array('class'=>'col-md-6')));
echo $this->Form->input('Customer.best_time_of_day_to_reach', array('class' => 'form-control', 'div'=>array('class'=>'col-md-6')));
echo $this->Form->input('Customer.address', array('class' => 'form-control', 'div'=>array('class'=>'col-md-6')));
echo $this->Form->input('Customer.address_line_2', array('class' => 'form-control', 'div'=>array('class'=>'col-md-6')));
echo $this->Form->input('Customer.city', array('class' => 'form-control', 'div'=>array('class'=>'col-md-5')));
echo $this->Form->input('Customer.state', array('class' => 'form-control', 'type' => 'select', 'options' => $states, 'selected' => 'UT', 'div'=>array('class'=>'col-md-5')));
echo $this->Form->input('Customer.zip', array('class' => 'form-control', 'div'=>array('class'=>'col-md-2')));
echo '<div class="clear"></div>';
echo $this->Form->input('mailing', array('type' => 'checkbox', 'label' => 'Mailing address the is different from the home address?', 'hiddenField' => false, 'div'=>array('class'=>'col-md-12')));
echo $this->Form->input('Customer.mailing_street', array('class' => 'form-control', 'div'=>array('class'=>'col-md-6')));
echo $this->Form->input('Customer.mailing_address_line_2', array('class' => 'form-control', 'div'=>array('class'=>'col-md-6')));
echo $this->Form->input('Customer.mailing_city', array('class' => 'form-control', 'div'=>array('class'=>'col-md-5')));
echo $this->Form->input('Customer.mailing_state', array('class' => 'form-control', 'type' => 'select', 'options' => $states, 'selected' => '', 'div'=>array('class'=>'col-md-5')));
echo $this->Form->input('Customer.mailing_zip', array('class' => 'form-control', 'div'=>array('class'=>'col-md-2')));
$serviceTypeOptions = array('Residential' => 'Residential', 'Commercial' => 'Commercial');
echo $this->Form->input('EnergyUsage.service_type', array('class' => 'form-control', 'type' => 'select', 'options' => $serviceTypeOptions, 'div'=>array('class'=>'col-md-4')));
echo $this->Form->input('EnergyUsage.utility', array('class' => 'form-control', 'type' => 'select', 'options' => $utilities, 'selected' => 'Rocky Mountain Power (Utah Power)', 'div'=>array('class'=>'col-md-4')));
$voltageOptions = array('240 V : 120 V Split Phase' => '240 V : 120 V Split Phase', 'V Delta: 277 V Wye 3 Phase' => 'V Delta: 277 V Wye 3 Phase', '208 V Delta 3 Phase' => '240 V Split Phase Delta 3 Phase (Aka Stinger, Or High Leg Delta)', '240 V Split Phase Delta 3 Phase (Aka Stinger, Or High Leg Delta)' => '208 V Delta : 120 V Wye 3 Phase', '208 V Delta : 120 V Wye 3 Phase' => '240 V Delta 3 Phase', '240 V Delta 3 Phase');
echo $this->Form->input('EnergyUsage.service_config_voltage', array('class' => 'form-control', 'type' => 'select', 'options' => $voltageOptions, 'div'=>array('class'=>'col-md-4')));
echo $this->Form->input('EnergyUsage.utility_account_number', array('class' => 'form-control', 'div'=>array('class'=>'col-md-6')));
echo $this->Form->input('EnergyUsage.billing_period_one_start_date', array('class' => 'form-control datepicker', 'div'=>array('class'=>'col-md-6')));
echo $this->Form->input('EnergyUsage.notes', array('class' => 'form-control', 'div'=>array('class'=>'col-md-12')));
function daysInMonth($month){
$today = date('Y-m-d');
$date = explode('-',$today);
if($month > $date[1]){ $year = $date[0]-1;}else{$year = date('Y');}
return cal_days_in_month(CAL_GREGORIAN, $month, $year);
}
echo $this->Form->input('MonthyUsage.jan_billing_days', array('class' => 'form-control', 'value' => daysInMonth(1), 'div'=>array('class'=>'col-md-6 col-sm-6')));
echo $this->Form->input('MonthyUsage.jan_consumption', array('class' => 'form-control', 'div'=>array('class'=>'col-md-6 col-sm-6')));
echo $this->Form->input('MonthyUsage.feb_billing_days', array('class' => 'form-control', 'value' => daysInMonth(2), 'div'=>array('class'=>'col-md-6 col-sm-6')));
echo $this->Form->input('MonthyUsage.feb_consumption', array('class' => 'form-control', 'div'=>array('class'=>'col-md-6 col-sm-6')));
echo $this->Form->input('MonthyUsage.mar_billing_days', array('class' => 'form-control', 'value' => daysInMonth(3), 'div'=>array('class'=>'col-md-6 col-sm-6')));
echo $this->Form->input('MonthyUsage.mar_consumption', array('class' => 'form-control', 'div'=>array('class'=>'col-md-6 col-sm-6')));
echo $this->Form->input('MonthyUsage.apr_billing_days', array('class' => 'form-control', 'value' => daysInMonth(4), 'div'=>array('class'=>'col-md-6 col-sm-6')));
echo $this->Form->input('MonthyUsage.apr_consumption', array('class' => 'form-control', 'div'=>array('class'=>'col-md-6 col-sm-6')));
echo $this->Form->input('MonthyUsage.may_billing_days', array('class' => 'form-control', 'value' => daysInMonth(5), 'div'=>array('class'=>'col-md-6 col-sm-6')));
echo $this->Form->input('MonthyUsage.may_consumption', array('class' => 'form-control', 'div'=>array('class'=>'col-md-6 col-sm-6')));
echo $this->Form->input('MonthyUsage.jun_billing_days', array('class' => 'form-control', 'value' => daysInMonth(6), 'div'=>array('class'=>'col-md-6 col-sm-6')));
echo $this->Form->input('MonthyUsage.jun_consumption', array('class' => 'form-control', 'div'=>array('class'=>'col-md-6 col-sm-6')));
echo $this->Form->input('MonthyUsage.jul_billing_days', array('class' => 'form-control', 'value' => daysInMonth(7), 'div'=>array('class'=>'col-md-6 col-sm-6')));
echo $this->Form->input('MonthyUsage.jul_consumption', array('class' => 'form-control', 'div'=>array('class'=>'col-md-6 col-sm-6')));
echo $this->Form->input('MonthyUsage.aug_billing_days', array('class' => 'form-control', 'value' => daysInMonth(8), 'div'=>array('class'=>'col-md-6 col-sm-6')));
echo $this->Form->input('MonthyUsage.aug_consumption', array('class' => 'form-control', 'div'=>array('class'=>'col-md-6 col-sm-6')));
echo $this->Form->input('MonthyUsage.sep_billing_days', array('class' => 'form-control', 'value' => daysInMonth(9), 'div'=>array('class'=>'col-md-6 col-sm-6')));
echo $this->Form->input('MonthyUsage.sep_consumption', array('class' => 'form-control', 'div'=>array('class'=>'col-md-6 col-sm-6')));
echo $this->Form->input('MonthyUsage.oct_billing_days', array('class' => 'form-control', 'value' => daysInMonth(10), 'div'=>array('class'=>'col-md-6 col-sm-6')));
echo $this->Form->input('MonthyUsage.oct_consumption', array('class' => 'form-control', 'div'=>array('class'=>'col-md-6 col-sm-6')));
echo $this->Form->input('MonthyUsage.nov_billing_days', array('class' => 'form-control', 'value' => daysInMonth(11), 'div'=>array('class'=>'col-md-6 col-sm-6')));
echo $this->Form->input('MonthyUsage.nov_consumption', array('class' => 'form-control', 'div'=>array('class'=>'col-md-6 col-sm-6')));
echo $this->Form->input('MonthyUsage.dec_billing_days', array('class' => 'form-control', 'value' => daysInMonth(12), 'div'=>array('class'=>'col-md-6 col-sm-6')));
echo $this->Form->input('MonthyUsage.dec_consumption', array('class' => 'form-control', 'div'=>array('class'=>'col-md-6 col-sm-6')));
echo '<div class="col-md-6 margin-top3"></div>';
echo $this->Form->input('EnergyUsage.average_billing_amount', array('class' => 'form-control', 'div'=>array('class'=>'col-md-6')));
//echo $this->Form->input('image_upload', array('class' => 'form-control', 'div'=>array('class'=>'col-md-6'), 'type' => 'file', 'accept' => 'image/*', 'catpture' => 'camera'));
echo $this->Form->end(__('Submit')); ?>
Model:
App::uses('AppModel', 'Model');
class Lead extends AppModel {
public $validate = array('project_name' => array( 'notEmpty' => array('rule' => array('notEmpty'),//'message' => 'Your custom message here',),),);
public $belongsTo = array('User' => array('className' => 'User','foreignKey' => 'user_id','conditions' => '','fields' => '', 'order' => ''));
public $hasMany = array(
'Customer' => array('className' => 'Customer','foreignKey' => 'lead_id','dependent' => false,),
'EngeryUsage' => array('className' => 'EngeryUsage','foreignKey' => 'lead_id','dependent' => false, ),
'MonthlyUsage' => array('className' => 'MonthlyUsage', 'foreignKey' => 'lead_id','dependent' => false,),);
}
App::uses('AppModel', 'Model');
class Customer extends AppModel {
public $validate = array(
'lead_id' => array('numeric' => array('rule' => array('numeric'),//'message' => 'Your custom message here', ),),
'first_name' => array('notEmpty' => array('rule' => array('notEmpty'),//'message' => 'Your custom message here', ),),
'last_name' => array('notEmpty' => array('rule' => array('notEmpty'), //'message' => 'Your custom message here',), ),
'phone' => array('notEmpty' => array('rule' => array('notEmpty'),//'message' => 'Your custom message here',),),
'phone_extension' => array('numeric' => array('rule' => array('numeric'), 'message' => 'Your custom message here','allowEmpty' => true,'required' => false,),),
'address' => array('notEmpty' => array('rule' => array('notEmpty'),//'message' => 'Your custom message here',),),
'city' => array('notEmpty' => array('rule' => array('notEmpty'),//'message' => 'Your custom message here',),),
'state' => array('notEmpty' => array('rule' => array('notEmpty'),//'message' => 'Your custom message here',),),
'zip' => array('numeric' => array('rule' => array('numeric'),//'message' => 'Your custom message here',),),
);
public $belongsTo = array('Lead' => array('className' => 'Lead','foreignKey' => 'lead_id',));
}
App::uses('AppModel', 'Model');
class EnergyUsage extends AppModel {
public $validate = array('lead_id' => array('numeric' => array('rule' => array('numeric'),//'message' => 'Your custom message here',),),);
public $belongsTo = array('Lead' => array('className' => 'Lead','foreignKey' => 'lead_id'));
}
App::uses('AppModel', 'Model');
class MonthyUsage extends AppModel {
public $belongsTo = array( 'Lead' => array('className' => 'Lead','foreignKey' => 'lead_id'));
}
in the controller when I debug validationErrors I get:
array(
'phone_extension' => array(),
'best_time_of_day_to_reach' => array(),
'address_line_2' => array(),
'mailing_street' => array(),
'mailing_address_line_2' => array(),
'mailing_city' => array(),
'mailing_zip' => array(),
'ext' => array()
)
This is the debug statement with the customer input fields removed:
array(
'Lead' => array(
'project_name' => 'Project1',
'sales_owner' => 'Nate Branning',
'lead_source' => 'Door to Door',
'type' => 'Individual',
'tax_entity' => 'Individual'
),
'Customer' => array(
'first_name' => '',
'last_name' => '',
'title' => 'Mr',
'email' => '',
'phone' => '',
'phone_extension' => '',
'phone_type' => 'Home',
'best_time_of_day_to_reach' => '',
'address' => '',
'address_line_2' => '',
'city' => '',
'state' => 'UT',
'zip' => '',
'mailing_street' => '',
'mailing_address_line_2' => '',
'mailing_city' => '',
'mailing_state' => 'AL',
'mailing_zip' => ''
),
'EnergyUsage' => array(
'service_type' => 'Residential',
'utility' => 'Rocky Mountain Power (Utah Power)',
'service_config_voltage' => '240 V : 120 V Split Phase',
'utility_account_number' => '',
'billing_period_one_start_date' => '',
'notes' => '',
'average_billing_amount' => ''
),
'MonthyUsage' => array(
'jan_billing_days' => '31',
'jan_consumption' => '',
'feb_billing_days' => '28',
'feb_consumption' => '',
'mar_billing_days' => '31',
'mar_consumption' => '',
'apr_billing_days' => '30',
'apr_consumption' => '',
'may_billing_days' => '31',
'may_consumption' => '',
'jun_billing_days' => '30',
'jun_consumption' => '',
'jul_billing_days' => '31',
'jul_consumption' => '',
'aug_billing_days' => '31',
'aug_consumption' => '',
'sep_billing_days' => '30',
'sep_consumption' => '',
'oct_billing_days' => '31',
'oct_consumption' => '',
'nov_billing_days' => '30',
'nov_consumption' => '',
'dec_billing_days' => '31',
'dec_consumption' => ''
)
)
Thanks in advance.
I solved my problem. I had the associations wrong. Customer, EnergyUsage and MonthyUsage belong to Lead. Where the error was in the leads controller I had the association as hasMany. Whe I changed it to hasOne it fixed the issue. I think cake was trying to validate Customer more than once.

Yiibooster editable widget inside popover widget

I'm building website using yii 1.1 framework and Clevertech YiiBooster extension.
Is there an easy way to render few "editable field" widgets inside the popover widget ?
Please see the code below. Any suggestions are welcome.
Main view:
....
$this->widget(
'booster.widgets.TbButton', array(
'label' => 'Right popover',
'context' => 'warning',
'buttonType' => 'button',
'size' => 'extra_small',
'htmlOptions' => array(
'id' => uniqid(),
'data-html' => true,
'data-title' => 'A Title',
'data-placement' => 'right',
'data-content' => $this->renderPartial('VIEW', array('data'=>$data), true, true),
'data-toggle' => 'popover'
),
)
);
....
partial view:
$this->widget('booster.widgets.TbEditableField', array(
'type' => 'text',
'model' => $survey,
'attribute' => 'text',
'pk' => 'pk',
'name' => 'name',
'text' => '',
'url' => $this->createUrl('controller/method/'), //url for submit data
'title' => 'text',
'placement' => 'right',
'id' => uniqid()),true);
$this->widget('booster.widgets.TbEditableField', array(
'type' => 'text',
'model' => $survey,
'attribute' => 'text',
'pk' => 'pk',
'name' => 'name',
'text' => '',
'url' => $this->createUrl('controller/method/'), //url for submit data
'title' => 'text',
'placement' => 'right',
'id' => uniqid()),true);
$this->widget('booster.widgets.TbEditableField', array(
'type' => 'text',
'model' => $survey,
'attribute' => 'text',
'pk' => 'pk',
'name' => 'name',
'text' => '',
'url' => $this->createUrl('controller/method/'), //url for submit data
'title' => 'text',
'placement' => 'right',
'id' => uniqid()),true);

Zend captcha problems

I'm a beginner and I followed the tutorial on zend framework website to create a simple web application from a skeleton one. I'm trying to add further elements to the form proposed by the tutorial, expecially an 'image' capctha, but, when I try to render it in the appropriate view, I get this fatal error:
Fatal error: Call to undefined method Zend\Form\Element::getCaptcha() in C:\xampp\htdocs\new\vendor\zendframework\zendframework\library\Zend\Form\View\Helper\FormCaptcha.php on line 45.
This is the code related to the albumform class:
<?php
namespace Album\Form;
use Zend\Form\Element;
use Zend\Form\Form;
use Zend\Captcha\Image;
use Zend\Captcha\AdapterInterface;
class AlbumForm extends Form
{
protected $captcha;
public function __construct($name = null)
{
// we want to ignore the name passed
parent::__construct('album');
$this->captcha = new Image(array(
'expiration' => '300',
'wordlen' => '7',
'font' => 'public/fonts/glyphicons-halflings-regular.tff',
'fontSize' => '20',
'imgDir' => 'public/captcha',
'imgUrl' => '/captcha'
));
$this->add(array(
'name' => 'id',
'type' => 'Hidden',
));
$this->add(array(
'name' => 'title',
'type' => 'Text',
'options' => array(
'label' => 'Title',
),
'attributes' => array(
'value' => 'Scrivi il titolo',
'class' => 'prova',
),
));
$this->add(array(
'name' => 'artist',
'type' => 'Text',
'options' => array(
'label' => 'Artist',
),
));
$this->add(array(
'name' => 'captcha',
'attributes' => array(
'type' => 'Captcha'
),
'options' => array(
'label' => 'Please verify you are human.',
'captcha' => $this->captcha
)
));
$this->add(array(
'name' => 'submit',
'type' => 'Submit',
'attributes' => array(
'value' => 'Go',
'id' => 'submitbutton',
),
));
}
}
This is the code within the view:
<?php
$form->setAttribute('action', $this->url('album', array('action' => 'add')));
$form->prepare();
echo $this->form()->openTag($form) . "\n";
echo $this->formHidden($form->get('id')) . "\n";
echo $this->formLabel($form->get('title')) . "\n";
?>
<br/>
<?php
echo $this->formInput($form->get('title')) . "\n";
?>
<br/><br/>
<?php
echo $this->formLabel($form->get('artist')) . "\n";
?>
<br/>
<?php
echo $this->formInput($form->get('artist')) . "\n";
?>
<br/><br/>
<?php
echo $this->formCaptcha($form->get('captcha')) . "\n";
echo $this->formSubmit($form->get('submit')) . "\n";
echo $this->form()->closeTag() . "\n";
?>
Can you please help me? What is missing?
Thanks!
The problem is in your element definition. You have:
$this->add(array(
'name' => 'captcha',
'attributes' => array(
'type' => 'Captcha'
),
'options' => array(
'label' => 'Please verify you are human.',
'captcha' => $this->captcha
)
));
but the 'type' is in the wrong place. It should be:
$this->add(array(
'name' => 'captcha',
'type' => 'Captcha'
'options' => array(
'label' => 'Please verify you are human.',
'captcha' => $this->captcha
)
));

PHP attachment in write form

I need to edit the following form so it will have attach file function:
function _getWriteForm()
{
$aForm = array(
'form_attrs' => array(
'name' => 'WallPostText',
'action' => BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'post/',
'method' => 'post',
'enctype' => 'multipart/form-data',
'target' => 'WallPostIframe',
'onsubmit' => 'javascript:return ' . $this->_sJsPostObject . '.postSubmit(this);'
),
'inputs' => array(
'content' => array(
'type' => 'textarea',
'name' => 'content',
'caption' => '',
'colspan' => true
),
'submit' => array(
'type' => 'submit',
'name' => 'submit',
'value' => _t('_wall_post'),
'colspan' => true
)
),
);
I wanted to edit HTML file first, but the only HTML code for this is:
<!-- Post Text -->
<div class="wall-ptype-cnt wall_text">__post_wall_text__</div>
Can someone please help me with editing array to allow file attachment?
Thank you.
You should try something like this:
function _getWriteForm()
{
$aForm = array(
'form_attrs' => array(
'name' => 'WallPostText',
'action' => BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'post/',
'method' => 'post',
'enctype' => 'multipart/form-data',
'target' => 'WallPostIframe',
'onsubmit' => 'javascript:return ' . $this->_sJsPostObject . '.postSubmit(this);'
),
'inputs' => array(
'content' => array(
'type' => 'textarea',
'name' => 'content',
'caption' => '',
'colspan' => true
),
'file' => array(
'type' => 'file',
'name' => 'upload_file',
'caption' => 'Upload',
'colspan' => true
),
'file_two' => array( //I added a second input file
'type' => 'file',
'name' => 'upload_file_two',
'caption' => 'Upload',
'colspan' => true
),
'submit' => array(
'type' => 'submit',
'name' => 'submit',
'value' => _t('_wall_post'),
'colspan' => true
)
),
);
I hope it helps.
Saludos ;)

Categories