Cakephp trying to validate non existing input - php
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.
Related
cakephp-upload won´t validate
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>
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)
How to merge two arrays into one in CodeIgniter?
This is my config file which contains form attributes in CodeIgniter. $config['reg_attribute'] = array( 'form' => array( 'id' => 'reg-form', 'class' => 'form-horizontal', 'role' => 'form' ), 'name' => array( 'id'=>'reg-name', 'class' => 'form-control', 'name'=>'name', 'placeholder' => 'Enter name', 'value'=>set_value('name') ), 'gender' => array( 'id'=>'reg-reg', 'class' => 'form-control', 'name'=>'gender', 'value'=>set_value('gender') ), 'contact_no' => array( 'id'=>'reg-reg', 'class' => 'form-control', 'name'=>'contact_no', 'placeholder' => 'Enter Phone number', 'value'=>set_value('contact_no') ), 'email'=> array( 'id'=>'reg-email', 'class' => 'form-control', 'name'=>'email', 'placeholder' => 'Enter Email', 'value'=>set_value('email') ), 'password' =>array( 'id'=>'reg-password', 'class' => 'form-control', 'name'=>'password', 'placeholder'=>'Enter Password', 'value'=>set_value('password') ), 'confirm_password' =>array( 'id'=>'reg-password', 'class' => 'form-control', 'name'=>'confirm_password', 'placeholder'=>'Enter Confirm Password', 'value'=>set_value('confirm_password') ), 'submit' =>array( 'id' => 'btn-login', 'class' => 'btn btn-success', 'name' => 'submit', 'value' => 'Register' ) ); Here I'm loading the form attributes from config and storing it into an array $data["reg_attrib"] $this->config->load('reg_rules'); $data["reg_attrib"] = $this->config->item("reg_attribute"); I have an another array which is $add_form $add_form = array( 'action' => base_url('admin/user/insert'), 'title' => 'Add User', ); Now I want to merge both the array's into a single array and send it to view i.e to $add_attributes. $this->admin_layout->view('admin/add_user',$add_attributes);
Simply merge them with array_merge(). Try this - $add_attributes = array_merge($data["reg_attrib"], $add_form);
use array_merge() function like $merged_arr = array_merge($arr1,$arr2); in your case it will be same as #BOSE suggested: $add_attributes = array_merge($data["reg_attrib"], $add_form);
Cakephp Google RE Captcha not posting data
I am getting a undefined variable error when trying to use googles reCaptcha with 'g-recaptcha-response' according to their user docs https://developers.google.com/recaptcha/docs/verify However when i submit my user form - no data is posted from the recaptcha - this makes me believe it is a view error. Controller funtion if ($this->request->is('post')) { //if ($this->Recaptcha->verify()) { //verify captcha debug($this->request->data); $recaptcha_secret = "xxxxxxxxxxxxxxxxxxxxxxx"; $response = file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=".$recaptcha_secret."&response=".$this->request->data['g-recaptcha-response']); $response = json_decode($response, true); if($response["success"] == true){ } else{ } } } View.ctp <script src='https://www.google.com/recaptcha/api.js'></script> <?php $this->set('title_for_layout', 'Sign Up '); ?> <!-- -- TESTACL1 USERS ADD -- --> <div class="container-fluid"> <div class="row"> <!-- div class="col-md-3"> </div --> <div class="col-md-1"> </br></br> </div> <div class="col-md-5"> <div class="usersfor"> <?php echo $this->Form->create(array( 'novalidate' => true, 'User' )); ?> <fieldset> <legend><?php echo __('Sign Up for an Account'); ?></legend> <?php if ($this->Session->read('Auth.User')) { echo 'It looks like you already have a Junto Account! We\'re pleased to hear it!'; echo '<br/>'; echo '<br/>*'; echo '<br/>**'; echo '<br/>***'; echo '<br/>****'; echo '<br/>*****'; echo '<br/>******'; echo '<br/>*******'; echo '<br/>******'; echo '<br/>****'; echo '<br/>***'; echo '<br/>**'; echo '<br/>*'; } else { // echo $this->Form->input('group_id', array ('class'=>'form-control','label' => 'Type Of Account:', 'type'=>'text','value'=>'Registered', 'maxLength' => '20')); echo $this->Form->input('username', array( 'class' => 'form-control', 'label' => 'Email Address:', 'type' => 'text', 'maxLength' => '50', 'placeholder' => 'EG. johndoe#example.com', 'style' => 'width:75%;' )); echo $this->Form->hidden('PassFrom', array( 'value' => '' )); echo $this->Form->input('password', array( 'placeholder' => '(8 - 20 characters)', 'div' => 'chckbx', 'class' => 'form-control', 'label' => 'Create Password:', 'type' => 'password', 'maxLength' => '20', 'style' => 'width:55%;', 'min' => 8 )); echo $this->Form->input('first_name', array( 'placeholder' => 'EG. John', 'class' => 'form-control', 'label' => 'First Name:', 'type' => 'text', 'maxLength' => '45', 'style' => 'width:75%;' )); echo $this->Form->input('last_name', array( 'placeholder' => 'EG. Doe', 'div' => 'chckbx', 'class' => 'form-control', 'label' => 'Last Name:', 'type' => 'text', 'maxLength' => '45', 'style' => 'width:75%;' )); echo $this->Form->input('addressLineOne', array( 'placeholder' => 'EG. 99 Example Street', 'class' => 'form-control', 'label' => 'Address:', 'type' => 'text', 'maxLength' => '40', 'style' => 'width:75%;' )); echo $this->Form->input('addressLineTwo', array( 'placeholder' => '(optional)', 'class' => 'form-control', 'label' => false, 'type' => 'text', 'maxLength' => '40', 'style' => 'width:75%;' )); ?> </div> </div> <div class="col-md-6"> <p></br></p> <p></br></p> <p></br></p> <?php echo $this->Form->input('city', array( 'placeholder' => 'EG. Melbourne', 'class' => 'form-control', 'label' => 'Suburb:', 'type' => 'text', 'maxLength' => '60', 'style' => 'width:35%;' )); ?> <div class="row"> <div class="col-md-6"> <?php echo $this->Form->input('state', array( 'class' => 'form-control', 'label' => 'State:', 'options' => array( 'VIC' => 'VIC', 'ACT' => 'ACT', 'NSW' => 'NSW', 'NT' => 'NT', 'QLD' => 'QLD', 'SA' => 'SA', 'TAS' => 'TAS', 'WA' => 'WA' ) )); ?> </div> <div class="col-md-6"> <?php echo $this->Form->input('postcode', array( 'placeholder' => '', 'class' => 'form-control', 'label' => 'Postcode:', 'type' => 'text', 'maxLength' => '4', 'style' => 'width:40%;' )); ?> </div> </div> <br/> <?php echo $this->Form->input('telephoneNumber', array( 'placeholder' => 'EG. 0401555777', 'class' => 'form-control', 'label' => 'Telephone Number (Include area code e.g. 0423232112):', 'maxLength' => '10', 'style' => 'width:37%;' )); ?> <b><?php echo "Date of Birth:"; ?></b> <?php echo $this->Form->input('dob', array( 'div' => 'chckbx', 'label' => '', 'dateFormat' => 'DMY', 'maxYear' => date('Y') , 'minYear' => date('Y') - 70 )); // echo $this->Form->input('gender', array ('class'=>'form-control','label' => 'Gender:', 'options' => array('M'=>'Male','F'=>'Female'))); // echo $this->Form->input('newsletterSubscription', array ('class'=>'form-control','label' => 'Subscribe to Newsletter?:', 'options' => array('Y'=>'Yes','N'=>'No'))); ?> <br/> <?php $options = array( 'm' => ' Male ', 'f' => ' Female' ); $attributes = array( 'legend' => false ); echo $this->Form->radio('gender', $options, $attributes); echo $this->Form->input('newsletterSubscription', array( 'div' => 'chckbx', 'value' => 'y', 'type' => 'checkbox', 'hiddenField' => 'n', 'label' => ' Subscribe To Junto Club Newsletter?' )); } ?> <div class="g-recaptcha" data-sitekey="6LfGCQETAAAAAOEMaiCsSVxyypunTvGBSsFWr5XW"></div> </fieldset> </br> </br> <div class="submit" align="center"> <?php echo $this->Form->end(__('Submit')); ?> <p></br></p> <p></br></p> </div> <!-- End --> <div class="col-md-2"> </div> </div> </div> <div class="actions"> <!-- <h3><?php /* echo __('Actions'); ?></h3> <ul> <li><?php echo $this->Html->link(__('List Users'), array('action' => 'index')); ?></li> <li><?php echo $this->Html->link(__('List Groups'), array('controller' => 'groups', 'action' => 'index')); ?> </li> <li><?php echo $this->Html->link(__('New Group'), array('controller' => 'groups', 'action' => 'add')); */ ?> </li> </ul> --> </div> </div> update:: The issue appears to be caused by div tags. I was able to resolve the issue by placing the recaptcha widget inside a particular div. <script src='https://www.google.com/recaptcha/api.js'></script> <?php $this->set('title_for_layout', 'Sign Up '); ?> <!-- -- TESTACL1 USERS ADD -- --> <div class="container-fluid"> <div class="row"> <!-- div class="col-md-3"> </div --> <div class="col-md-1"> </br></br> </div> <div class="col-md-5"> <div class="usersfor"> <?php echo $this->Form->create(array( 'novalidate' => true, 'User' )); ?> <fieldset> <legend><?php echo __('Sign Up for an Account'); ?></legend> <?php if ($this->Session->read('Auth.User')) { echo 'It looks like you already have a Junto Account! We\'re pleased to hear it!'; echo '<br/>'; echo '<br/>*'; echo '<br/>**'; echo '<br/>***'; echo '<br/>****'; echo '<br/>*****'; echo '<br/>******'; echo '<br/>*******'; echo '<br/>******'; echo '<br/>****'; echo '<br/>***'; echo '<br/>**'; echo '<br/>*'; } else { // echo $this->Form->input('group_id', array ('class'=>'form-control','label' => 'Type Of Account:', 'type'=>'text','value'=>'Registered', 'maxLength' => '20')); echo $this->Form->input('username', array( 'class' => 'form-control', 'label' => 'Email Address:', 'type' => 'text', 'maxLength' => '50', 'placeholder' => 'EG. johndoe#example.com', 'style' => 'width:75%;' )); echo $this->Form->hidden('PassFrom', array( 'value' => '' )); echo $this->Form->input('password', array( 'placeholder' => '(8 - 20 characters)', 'div' => 'chckbx', 'class' => 'form-control', 'label' => 'Create Password:', 'type' => 'password', 'maxLength' => '20', 'style' => 'width:55%;', 'min' => 8 )); echo $this->Form->input('first_name', array( 'placeholder' => 'EG. John', 'class' => 'form-control', 'label' => 'First Name:', 'type' => 'text', 'maxLength' => '45', 'style' => 'width:75%;' )); echo $this->Form->input('last_name', array( 'placeholder' => 'EG. Doe', 'div' => 'chckbx', 'class' => 'form-control', 'label' => 'Last Name:', 'type' => 'text', 'maxLength' => '45', 'style' => 'width:75%;' )); echo $this->Form->input('addressLineOne', array( 'placeholder' => 'EG. 99 Example Street', 'class' => 'form-control', 'label' => 'Address:', 'type' => 'text', 'maxLength' => '40', 'style' => 'width:75%;' )); echo $this->Form->input('addressLineTwo', array( 'placeholder' => '(optional)', 'class' => 'form-control', 'label' => false, 'type' => 'text', 'maxLength' => '40', 'style' => 'width:75%;' )); ?> </div> **<div class="g-recaptcha" data-sitekey="6LfGCQETAAAAAOEMaiCsSVxyypunTvGBSsFWr5XW"></div>** </div> <div class="col-md-6"> <p></br></p> <p></br></p> <p></br></p> <?php echo $this->Form->input('city', array( 'placeholder' => 'EG. Melbourne', 'class' => 'form-control', 'label' => 'Suburb:', 'type' => 'text', 'maxLength' => '60', 'style' => 'width:35%;' )); ?> <div class="row"> <div class="col-md-6"> <?php echo $this->Form->input('state', array( 'class' => 'form-control', 'label' => 'State:', 'options' => array( 'VIC' => 'VIC', 'ACT' => 'ACT', 'NSW' => 'NSW', 'NT' => 'NT', 'QLD' => 'QLD', 'SA' => 'SA', 'TAS' => 'TAS', 'WA' => 'WA' ) )); ?> </div> <div class="col-md-6"> <?php echo $this->Form->input('postcode', array( 'placeholder' => '', 'class' => 'form-control', 'label' => 'Postcode:', 'type' => 'text', 'maxLength' => '4', 'style' => 'width:40%;' )); ?> </div> </div> <br/> <?php echo $this->Form->input('telephoneNumber', array( 'placeholder' => 'EG. 0401555777', 'class' => 'form-control', 'label' => 'Telephone Number (Include area code e.g. 0423232112):', 'maxLength' => '10', 'style' => 'width:37%;' )); ?> <b><?php echo "Date of Birth:"; ?></b> <?php echo $this->Form->input('dob', array( 'div' => 'chckbx', 'label' => '', 'dateFormat' => 'DMY', 'maxYear' => date('Y') , 'minYear' => date('Y') - 70 )); // echo $this->Form->input('gender', array ('class'=>'form-control','label' => 'Gender:', 'options' => array('M'=>'Male','F'=>'Female'))); // echo $this->Form->input('newsletterSubscription', array ('class'=>'form-control','label' => 'Subscribe to Newsletter?:', 'options' => array('Y'=>'Yes','N'=>'No'))); ?> <br/> <?php $options = array( 'm' => ' Male ', 'f' => ' Female' ); $attributes = array( 'legend' => false ); echo $this->Form->radio('gender', $options, $attributes); echo $this->Form->input('newsletterSubscription', array( 'div' => 'chckbx', 'value' => 'y', 'type' => 'checkbox', 'hiddenField' => 'n', 'label' => ' Subscribe To Junto Club Newsletter?' )); } ?> <div class="submit" align="center"> <?php echo $this->Form->end(__('Submit')); ?> </div> </fieldset> </br> </br> <!-- End --> <div class="col-md-2"> </div> </div> </div> <div class="actions"> <!-- <h3><?php /* echo __('Actions'); ?></h3> <ul> <li><?php echo $this->Html->link(__('List Users'), array('action' => 'index')); ?></li> <li><?php echo $this->Html->link(__('List Groups'), array('controller' => 'groups', 'action' => 'index')); ?> </li> <li><?php echo $this->Html->link(__('New Group'), array('controller' => 'groups', 'action' => 'add')); */ ?> </li> </ul> --> </div> </div> But why would this be affecting me in this way? Error thrown Notice (8): Undefined index: g-recaptcha-response [APP\Controller\UsersController.php, line 73] Code Context UsersController::add() - APP\Controller\UsersController.php, line 73 ReflectionMethod::invokeArgs() - [internal], line ?? Controller::invokeAction() - CORE\Cake\Controller\Controller.php, line 490 Dispatcher::_invoke() - CORE\Cake\Routing\Dispatcher.php, line 191 Dispatcher::dispatch() - CORE\Cake\Routing\Dispatcher.php, line 165 [main] - APP\webroot\index.php, line 108 Debug array( 'User' => array( 'password' => '*****', 'username' => '', 'PassFrom' => '', 'first_name' => '', 'last_name' => '', 'addressLineOne' => '', 'addressLineTwo' => '', 'city' => '', 'state' => 'VIC', 'postcode' => '', 'telephoneNumber' => '', 'dob' => array( 'day' => '27', 'month' => '01', 'year' => '2015' ), 'gender' => '', 'newsletterSubscription' => 'n' ) )
I'm having the same problem. g-recaptcha-response is in the POST array, but it's not in $this->data. See: Array ( [_method] => POST [data] => Array ( [BlogPostComment] => Array ( [name] => shannon [email] => shannon#home.com [text] => asdf [blog_post_id] => 11 [remote_ip] => 184.00.00.001 ) ) [g-recaptcha-response] => 03AHJ_VutSTvzfJze9pkzpcwQE3Xdf [ ... truncated...] ) That's because the other form elements have ids like BlogPostCommentName or BlogPostCommentEmail, which get into $this->data array as: [BlogPostComment] => Array ( [name] => shannon [email] => shannon#home.com ) ...and so on. But the recaptcha input's id is g-recaptcha-response, so it's not considered part of that set. This makes it difficult to validate the response. I don't know how to solve that yet, but anyway, that's where your posted data is probably ending up.
Automatically line break in Yii
If not including PHP, there is no error. If include Yii CMenu, automatically added white space before CMenu Example: <div id="umenu"> <?php $this->widget('zii.widgets.CMenu', array( 'encodeLabel' => false, 'items' => array( array('label' => ' ', 'url' => '/', 'itemOptions' => array('class' => 'umenu1')), array('label' => 'RÓLUNK', 'url' => StaticpageModule::getUrl(1), 'itemOptions' => array('class' => 'umenu2')), array('label' => 'TERMELÉS', 'url' => StaticpageModule::getUrl(2), 'itemOptions' => array('class' => 'umenu3')), array('label' => 'A KÁVÉ', 'url' => StaticpageModule::getUrl(3), 'itemOptions' => array('class' => 'umenu4')), array('label' => 'EGYÜTTMŰKÖDÉS', 'url' => StaticpageModule::getUrl(5), 'itemOptions' => array('class' => 'umenu5')), array('label' => 'KAPCSOLAT', 'url' => StaticpageModule::getUrl(4), 'itemOptions' => array('class' => 'umenu6')), ), )); ?> </div> Output:
Well, as PeterM said in its comment, you have whitespaces after opening div#menu... And about double quotes you see in chrome dev tool : when a string literal is not on the same line with its surrounding tag then the string literal is displayed on a new line with quotes around the string literal to make it visible where the string starts and ends. What is the purpose of the quotes around some dollar values on certain retail sites?
Change <div id="umenu"> <?php $this->widget('zii.widgets.CMenu', array( To <div id="umenu"><?php $this->widget('zii.widgets.CMenu', array(
From the reference documentation for the widget constructor, it looks like you might need to pass false as the $captureOutput flag to tell it not to push any output to the page. Try: <?php $this->widget('zii.widgets.CMenu', array( 'encodeLabel' => false, 'items' => array( array('label' => ' ', 'url' => '/', 'itemOptions' => array('class' => 'umenu1')), array('label' => 'RÓLUNK', 'url' => StaticpageModule::getUrl(1), 'itemOptions' => array('class' => 'umenu2')), array('label' => 'TERMELÉS', 'url' => StaticpageModule::getUrl(2), 'itemOptions' => array('class' => 'umenu3')), array('label' => 'A KÁVÉ', 'url' => StaticpageModule::getUrl(3), 'itemOptions' => array('class' => 'umenu4')), array('label' => 'EGYÜTTMŰKÖDÉS', 'url' => StaticpageModule::getUrl(5), 'itemOptions' => array('class' => 'umenu5')), array('label' => 'KAPCSOLAT', 'url' => StaticpageModule::getUrl(4), 'itemOptions' => array('class' => 'umenu6')), ), false ));