I am trying to save a description field that has varchar(500) in the database. When I look at the Net Panel in firebug the entire description is being posted (200+ words). However, in cakephp only 75 words are being saved. I set a breakpoint in my controller and looked at this->request->data and it has about 150 characters. Below is my code:
<fieldset>
<legend>Create Log</legend>
<?php echo $this->Form->Create('Log', array('inputDefaults' => array('div' => false, 'label' => false))); ?>
<div class="control-group">
<div class="input-prepend">
<span class="add-on"><i class="icon-folder-open"></i></span>
<?php echo $this->Form->input('project_id'); ?>
</div>
</div>
<div class="control-group">
<div class="input-prepend">
<span class="add-on"><i class="icon-user"></i></span>
<input type="text" id="txtName" placeholder="Customer" />
<?php echo $this->Form->Hidden('customer_id'); ?>
<a><span class="add-on"><i class="icon-plus" style="color: green;" onclick="window.open('<?php echo $this->Html->Url(array('controller' => 'customers', 'action' => 'add?popup')); ?>', 'Add Customer', 'height=630, width=430')"></i></span></a>
</div>
</div>
<div class="control-group">
<div class="input-prepend">
<span class="add-on"><i class="icon-time"></i></span>
<?php echo $this->Form->input('time_spent', array('placeholder' => 'Time spent (hrs)')); ?>
</div>
</div>
<div class="control-group">
<div class="input-prepend">
<span class="add-on"><i class="icon-book"></i></span>
<?php echo $this->Form->textarea('description', array('placeholder' => 'Description', 'class' => 'logTextArea', 'rows' => '7')); ?>
</div>
</div>
<?php echo $this->Form->end(array(
'label' => 'Save Record',
'class' => 'btn btn-primary',
'div' => false
)); ?>
<?php echo $this->Html->script('jquery.autocomplete', array('inline' => false)); ?>
<?php $this->start('script'); ?>
<script type="text/javascript">
$(document).ready(function () {
var options, a;
jQuery(function() {
options = {
serviceUrl: "<?php echo $this->Html->Url(array('controller' => 'logs', 'action' => 'autoComplete.json')); ?>",
minChars: 2,
onSelect: function(suggestion){ $('#LogCustomerId').val(suggestion.data); }
};
a = $('#txtName').autocomplete(options);
});
});
</script>
<?php $this->end(); ?>
Controller:
public function add() {
$this->set('title_for_layout', 'Add log');
// Populate projects DDL
$this->set('projects', $this->Log->Project->find('list', array(
'order' => array('Project.project_name')
)));
if ($this->request->is('post'))
{
$this->Log->create();
if ($this->Log->save($this->request->data))
{
$this->Session->setFlash('Log has succesfully been created', 'default', array('class' => 'alert alert-success'));
$this->redirect(array('action' => 'index'));
} else {
$this->Session->setFlash('Unable to save log', 'default', array('class' => 'alert alert-error'));
}
}
}
This problem may be caused by a bug in some versions of PHP that truncates $_POST values.
Without re-posting the information, this question contains some additional
information.
PHP $_POST array variables are truncated
Some (possibly) related bugs;
Bug #42824 Post Data truncated
Related
I have two activeform in my view and one of them use pjax. And both of them requires second click to submit. I don't know what I am doing wrong. I search this problem in internet, but meet other cases of second click
<?php Pjax::begin(['id' => 'workers', "timeout" => 50000], ["options" => ["timeout" => 5000]]);?>
<?php
echo $this->render('_show', [
"model" => $searchModel,
"filials" => $filials,
"workers" => $workers,
"posts" => $posts,
]);
echo $this->render('_handle_form');
?>
<div class="row js-loader">
<div class="col-lg-12 col-md-12">
<div class="table-responsive">
<?=GridView::widget([
'dataProvider' => $dataProvider,
'emptyText' => 'Нет результатов',
'tableOptions' => ['class' => 'table table-hover table-claim table-claimadm', 'style' => 'font-weight:600;'],
'rowOptions' => ['class'=>'row-without-border row-open'],
'layout' => "{items}{pager}",
'columns' => [
[
...
]
]);?>
</div>
</div>
</div>
<?php Pjax::end();?>
<script>
window.onload = function () {
$(document).on('pjax:send', function (event) {
tbody = $('#' + event.target.id).find(".js-loader");
if (tbody.length != 0) {
tbody_height = tbody.height();
tbody.html('<div class="block-loader" style="width:100%"></div>');
}
});
$('#submit_with_answer').click(function() {
if ($.trim($('#text-claim').val()).length > 0)
{
$('#complaint_feedback').submit();
}
else
{
$('#textarea-group').addClass('has-error');
$('#answer_error').html('Заполните поле «Добавить текст ответа»');
}
});
};
</script>
The "_show" view is:
<?php $form = ActiveForm::begin([
'id' => 'complaints',
'action' => Url::to(['complaints/show']),
'method' => 'GET',
'options' =>
[
'class' => 'form-respons form-claimadm',
'data-pjax' => 1,
],
]);
active fields....
<div class="form-btns col-md-2 col-sm-6 col-xs-12">
<?= Html::submitButton('Применить', ['class' => 'btn btn-primary','style'=>"float:right;"]) ?>
</div>
</div>
<?php ActiveForm::end(); ?>
and _handle_form is:
<?php
use yii\widgets\ActiveForm;
use yii\helpers\Url;
?>
<?php
$form = ActiveForm::begin([
'id' => 'complaint_feedback',
'action' => Url::to(['complaints/handle-complaint']),
'method' => 'POST',
'options' => ['class' => 'form-respons form-claim-feedback','style'=>'display:none;'],
]);
?>
<div id="textarea-group" class="form-group">
<label for="text-claim" class="hidden-xs">Добавить текст ответа</label>
<textarea class="form-control" id="text-claim" rows="3" name="complaint_answer" placeholder="Добавить текст ответа"></textarea>
<div id="answer_error" class="help-block"></div>
<input id="complaint_id" name="complaint_id" type="hidden" value="">
</div>
<div class="clearfix form-btns">
<button type="button" onclick="$('#complaint_feedback').submit();" class="btn btn-link">Обработать без ответа</button>
<button id="submit_with_answer" type="button" class="btn btn-primary">Отправить</button>
</div>
<?php ActiveForm::end(); ?>
<a id="hide_handle_form" style="display: none;" onclick="$('#complaint_feedback').hide(); $('.handle_button').removeClass('disabled'); $(this).hide();$('tr[data-key='+$('#complaint_id').val()+']').removeClass('row-open');" class="btn btn-link btn-show-hide">Свернуть
</a>
if I comment lines with pjax, everything works correctly. How can I fix this trouble?
When I submit this form all things are well n good but I want the controller function not shows in url. I want all things are done in same page. Still the url show
localhost/Naveen/CodeIgniter/welcome/insertform
but I don't want the form_open('') show's in url so how it is possible?
controller welcome.php
public function insertform()
{
if (isset($_POST['mysmt']))
{
$this->form_validation->set_rules('fname', 'Name', 'required');
$this->form_validation->set_rules('femail', 'Email', 'trim|required|valid_email');
$this->form_validation->set_rules('fmobile', 'Mobile', 'required');
if ($this->form_validation->run() == FALSE)
{
$this->load->view('welcome_view');
}
else
{
$_POST['fname'];
$_POST['femail'];
$_POST['fmobile'];
if($this->test_model->insert('user_accounts',array('',$_POST['fname'],$_POST['femail'],$_POST['fmobile'])))
{
$success['success']="Thanks For Join Us";
$this->load->view('welcome_view',$success);
}
}
}
else
{
$this->load->view('welcome_view');
}
}
view welcome_view.php
<?php echo form_open('welcome/insertform'); // ?>
<div class="form-group">
<?php
if(isset($success))
{?>
<input type="button" class="form-control btn-success" value="<?php echo $success; ?>">
<?php }
else
{
echo "";
}?>
</div>
<div class="form-group">
<label class="control-label" for="focusedInput">Name <?php echo form_error('fname'); ?></label>
<?php
$entername = array(
'name' => 'fname',
'value' => '',
'maxlength' => '100',
'placeholder' => 'Enter Name',
'class' => 'form-control',
);
echo form_input($entername); ?>
</div>
<div class="form-group">
<label class="control-label" for="focusedInput">Email <?php echo form_error('femail'); ?></label>
<?php
$enteremail = array(
'name' => 'femail',
'value' => '',
'maxlength' => '100',
'placeholder' => 'Enter Email',
'class' => 'form-control',
);
echo form_input($enteremail); ?>
</div>
<div class="form-group">
<label class="control-label" for="focusedInput">Mobile <?php echo form_error('fmobile'); ?></label>
<?php
$entermobile = array(
'name' => 'fmobile',
'value' => '',
'maxlength' => '100',
'placeholder' => 'Enter Mobile',
'class' => 'form-control',
);
echo form_input($entermobile); ?>
</div>
<div class="form-group">
<?php
$f_formsmt = array(
'name' => 'mysmt',
'value' => 'Submit Form',
'class' => 'form-control btn btn-success',
);
echo form_submit($f_formsmt); ?>
</div>
<?php echo form_close(); ?>
You handle it through applications/config/routes.php
consider you url: localhost/Naveen/CodeIgniter/welcome/insertform
$route['add'] = 'welcome/insertform';
now you can use localhost/Naveen/CodeIgniter/add
You can change whatever the string you want for any controller/function using routes.
Hope you understood :)
You need to add the url in route and add link to your link href
In route.php add:
$route['custom_url'] = 'controller/method';
I used Header("location:../{whatever-filename}")
Then gave that "whatever-filename" the proper routing in the config/routes.php.
Routing without using the redirect function would load the appropriate page but the url would still show the controller and method you're using.
Hope it helps
user data has been lost if there is a validation error and error validation messages are also not showing on front end.
Here is my controller
public function add() {
$this->theme = 'Front';
if (!empty($this->logged_in)) {
return $this->redirect(Router::url('/', true) . $this->logged_in['Role']['alias']);
}
$this->set('title_for_layout', __('Create An Account'));
// hanlde post data
if ($this->request->is("post")) {
if (!empty($this->request->data)) {
$this->User->set($this->request->data);
if (!$this->User->validates()) {
$this->User->validationErrors;
$this->Session->setFlash(__('The Information could not be saved. Please, try again.'), 'message', array('class' => 'danger'));
$this->redirect(Router::url('/', true) . 'sign-up/');
}
}
// die('sdsddsaf');
// if (!empty($this->request->data['User']['role_id']) && $this->request->data['User']['role_id'] == 2) {
unset($this->request->data['User']['specialization_id']);
$randomSt = $this->Custom->randomString(28);
$this->request->data['User']['activation_key'] = $randomSt;
// }
if ($this->User->save($this->request->data)) {
$user = $this->request->data;
if (!empty($this->request->data['User']['role_id']) && $this->request->data['User']['role_id'] == 3) {
$this->Session->setFlash(__('Thank you for registering with us. Please check your email inbox/junk.'), 'message', array('class' => 'successs'));
// set mail variable
$to = $this->request->data['User']['email'];
$fname = $this->request->data['User']['first_name'];
$lname = $this->request->data['User']['last_name'];
//$activelink = SITEURL . 'activate?code=' . $randomSt;
$siteurl = Configure::read('Site.title');
$replace = array($fname, $lname, $siteurl);
// Send mail on Registration
$this->sendMail($to, 'RegisterDoctor', $replace);
} else {
$this->Session->setFlash(__('Thank you for registering with us. Please check your e-mail inbox/junk as your e-mail confirmation has just been sent.'), 'message', array('class' => 'successs'));
$activelink = Router::url('/', true) . 'activate/' . $this->User->id . '/' . $randomSt;
// set mail variable
$to = $this->request->data['User']['email'];
$fname = $this->request->data['User']['first_name'];
$lname = $this->request->data['User']['last_name'];
//$activelink = SITEURL . 'activate?code=' . $randomSt;
$siteurl = Configure::read('Site.title');
$replace = array($fname, $lname, $activelink, $siteurl);
// Send mail on Registration
$this->sendMail($to, 'Register', $replace);
}
$this->redirect(array('controller' => 'users', 'action' => 'login'));
}
}
$reponse = array();
$roles = $this->User->rolesSignup();
$genders = $this->User->genders();
$specializations = $this->User->specializations();
$this->set(compact('roles', 'genders', 'specializations'));
}
And below is my view
<?php
echo $this->Form->create('User', array(
'inputDefaults' => array('div' => false, 'label' => false, 'fieldset' => false),
'class' => 'ac p10',
// 'data-togglesd' => "validator",
'role' => 'form',
'type' => 'file',
'onSubmit' => 'return checksubmitPass()'
)
);
?>
<div class="ph10">
<div class="btn-group radio_group w100" data-toggle="buttons">
<label class="btn btn-primary col-md-6 <?php echo (empty($this->request->data['User']['role_id']) || #$this->request->data['User']['role_id'] == 2 ) ? 'active' : ""; ?> btn_roles">
<input type="radio" name="data[User][role_id]" value="2" class="role_id" <?php echo (empty($this->request->data['User']['role_id']) || #$this->request->data['User']['role_id'] == 2 ) ? 'checked="checked"' : ""; ?>> User
</label>
<label class="btn btn-primary col-md-6 <?php echo (!empty($this->request->data['User']['role_id']) && $this->request->data['User']['role_id'] == 3 ) ? 'active' : ""; ?> btn_roles">
<input type="radio" name="data[User][role_id]" value="3" class="role_id" <?php echo (!empty($this->request->data['User']['role_id']) && $this->request->data['User']['role_id'] == 3 ) ? 'checked="checked"' : ""; ?>> Doctor
</label>
</div>
</div>
<div class="form-group p10 cr">
<div class="cm upload_img round"><img src="<?php echo $this->webroot; ?>img/user_avtar(upload).png" class="user_pic_upload">
<?php echo $this->Form->file('image', array('class' => 'user_img', 'data-fv-file' => 'true', 'data-fv-notempty-message' => __('notEmpty'), 'data-fv-field' => 'data[User][image]')); ?>
</div>
<small style="display: none;" class="help-block" data-fv-validator="notEmpty" data-fv-for="data[User][image]" data-fv-result="VALID">This field cannot be left blank.</small>
</div>
<div class="form-group mt10 cr">
<div class="clearfix">
<div class="col-lg-6 first_name"><?php echo $this->Form->input('first_name', array('class' => 'form-control', 'placeholder' => 'First Name', 'data-stripe' => "alphabet", 'data-fv-notempty-message' => __('notEmpty'), 'data-fv-regexp' => 'true', 'data-fv-regexp-regexp' => "^[a-zA-Z\s]+$", 'data-fv-regexp-message' => "The first name can consist of alphabetical characters and spaces only")); ?></div>
<div class="col-lg-6 last_name"><?php echo $this->Form->input('last_name', array('class' => 'form-control', 'placeholder' => 'Last Name', 'data-fv-notempty-message' => __('notEmpty'), 'data-fv-regexp' => 'true', 'data-fv-regexp-regexp' => "^[a-zA-Z\s]+$", 'data-fv-regexp-message' => "The last name can consist of alphabetical characters and spaces only", 'required')); ?></div>
</div>
</div>
<div class="form-group ph10 mt10">
<?php echo $this->Form->input('email', array('class' => "form-control", 'placeholder' => 'Email Address', 'data-fv-notempty-message' => __('notEmpty'), 'data-fv-emailaddress-message' => __('validemail'))); ?>
</div>
<div class="form-group mt10 ph10 row_org">
<div id="dropdown-menu">
<?php echo $this->Form->input('specialization_id', array('empty' => 'Select Speciallization', 'class' => 'selectpicker form-control', 'data-fv-notempty-message' => __('notEmpty'), 'required')); ?>
</div>
</div>
<div class="form-group ph10 mt10">
<?php echo $this->Form->input('password', array('class' => "form-control", 'placeholder' => 'Password', 'type' => 'password', 'data-fv-notempty-message' => __('notEmpty'))); ?>
</div>
<span id="result"></span>
<div class="form-group ph10 mt10">
<?php
echo $this->Form->input('verify_password', array(
'class' => "form-control",
'type' => 'password',
'placeholder' => 'Confirm Password',
'data-fv-notempty-message' => __('notEmpty'),
'data-fv-identical' => "true",
'data-fv-identical-field' => "data[User][password]",
'data-fv-identical-message' => __('passwordNotMatch')
)
);
?>
</div>
<div class="form-group mt10">
<div class="clearfix">
<div class="col-lg-6 mobile-custom">
<?php echo $this->Form->input('mobile', array('class' => 'form-control phonenumber', 'placeholder' => 'Mobile number', 'maxlength' => '14', 'minlength' => '10', 'data-fv-stringlength-message' => 'The mobile number must be 10 to 14 characters long', 'data-fv-numeric-message' => __('Please enter valid mobile numbers'), 'data-fv-numeric' => "true")); ?>
</div>
<div class="col-lg-6" id="dropdown-menu">
<?php //echo $this->Form->input('gender', array('class' => 'form-control selectpicker', 'data-fv-notempty-message' => __('notEmpty'),'empty' => 'I Am','error' => false, 'required')); ?>
<select id="UserGender" title="I Am" required="required" data-fv-notempty-message="This field cannot be left blank." class="form-control" name="data[User][gender]" style="display: none;" data-fv-field="data[User][gender]">
<option value="Male">Male</option>
<option value="Female">Female</option>
<option value="Other">Other</option>
</select>
</div>
</div>
</div>
<div class="form-group ph10 mt10"><button type="submit" class="btn btn-info w100">Sign Up</button></div>
<p class="mt10"><small>By Signing up you are agree with <br>Terms & Conditions and Privacy Policy</small></p>
<p class="mt10 signup-text"><strong>Already on HealthDrop?</strong></p>
<div class="ph10">
<?php echo $this->Html->link('Sign In', Router::url('/', true) . 'login', array('class' => 'btn deep btn-primary w100')); ?>
</div>
<?php echo $this->Form->end(); ?>
it was working before bu suddenly stop to showing error and start loosing data.
I have check with this question but it is pointing out at field names in input and I have correct ones.
Any help appreciate.
You lost your data because there is redirect to sign-up url.
$this->redirect(Router::url('/', true) . 'sign-up/');
And after redirection
$this->request->data
is empty because you perform new request, the same with errors
According to your code there are two mistakes I found
you are using ! for validating the validations
Save method itself validate the data so no need to validate again.
So your code should be look like
if ($this->User->save($this->request->data)) {
//your code
}else{
$this->Session->setFlash(__('The Information could not be saved. Please, try again.'), 'message', array('class' => 'danger'));
$this->redirect(Router::url('/', true) . 'sign-up/');
}
and validation error messages are automatically assign to view, no need to worry about them
I have activate ssl with my app and everything is going well... well, exept login. It is impossible to login to my app. Here is my form code that used to work with nude http :
<div class="users form">
<div class="form-login-box">
<?php echo $this->Session->flash('auth'); ?>
<?php echo $this->Form->create('User', array(
'class' => 'form-login',
'inputDefaults' => array(
'label' => false
)
)); ?>
<fieldset>
<?php echo $this->Form->input('username', array(
'class' => 'form-login-username',
'placeholder' => __('Login')
));
echo $this->Form->input('password', array(
'class' => 'form-login-password',
'placeholder' => __('Password')
));
?>
</fieldset>
<input type="submit" value="<?php echo __('Login') ?>" class="form-login-submit">
</div>
</div>
And my controller :
public function login() {
if ($this->request->is('post')) {
if ($this->Auth->login()) {
return $this->redirect($this->Auth->redirectUrl());
} else {
$this->Session->setFlash(__('Username or password is incorrect'), 'default', array('class' => 'authMessage-error'), 'auth');
}
}
}
It looks like your not actually closing the form the Cake way. Try this.
Replace the
<input type="submit" value="<?php echo __('Login') ?>" class="form-login-submit">
With
<?php echo $this->Form->end('Submit'); ?>
I write few files to form submit. But form validators is not working for choices(payment status).
This is my form.
class bookingAddForm extends sfForm
{
protected static $paymentStatus = array(
0 => 'Select Payment Status',
'PAID' => 'Paid',
'PARTIALLY_PAID' => 'Partially Paid',
'NOT_PAID' => 'Not Paid',
);
public function configure()
{
$this->widgetSchema['check_in'] = new sfWidgetFormInputText();
$this->widgetSchema['check_out'] = new sfWidgetFormInputText();
$this->widgetSchema['payment_status'] = new sfWidgetFormSelect(array('choices' => self::$paymentStatus));
unset($paymentStatus[0]);
$this->validatorSchema['check_in'] = new sfValidatorDate(array(
'min' => strtotime('today'),
'date_format' => '~(?P<day>\d{2})/(?P<month>\d{2})/(?P<year>\d{4})~'
),
array(
'required' => 'From date is required',
'bad_format' => '"%value%" does not match the date format (DD/MM/YYYY).',
'min' => 'Invalid Date',
)
);
$this->validatorSchema['check_out'] = new sfValidatorDate(array(
'min' => strtotime('today'),
'date_format' => '~(?P<day>\d{2})/(?P<month>\d{2})/(?P<year>\d{4})~'
),
array(
'required' => 'To date is required',
'bad_format' => '"%value%" does not match the date format (DD/MM/YYYY).',
'min' => 'Invalid Date'
)
);
$this->validatorSchema['payment_status'] = new sfValidatorChoice(array('choices' => array_keys(self::$paymentStatus)));
$this->widgetSchema->setNameFormat('reservation[%s]');
}
}
This is my action.
public function executeAddReservation(sfWebRequest $request)
{
$chaletId = $request->getParameter('id');
$this->chalet = skiChaletTable::getInstance()->getChalet($chaletId);
$this->form = new bookingAddForm();
if ($request->getMethod() == sfRequest::POST) {
$this->form->bind($request->getParameter($this->form->getName()));
if ($this->form->isValid()) {
die('submitted');
}
}
}
This is my view
<div class="form">
<form id="owner-add-reservation" action="<?php print url_for('owner_add_reservation', array('id' => $chalet->getId())); ?>" method="post">
<?php echo $form->renderHiddenFields(); ?>
<div class="row">
<div class="col">
<?php echo $form['check_in']->renderLabel(); ?><br/>
<?php echo $form['check_in']->render(); ?>
<img style="vertical-align:middle;" src="/images/icon_checkin_checkout.jpg">
<span id="<?php echo 'form_error_' . $form->getName() . '_check_in' ?>" class="form_error">
<?php echo $form['check_in']->getError(); ?>
</span>
</div>
<div class="col">
<?php echo $form['check_out']->renderLabel(); ?><br/>
<?php echo $form['check_out']->render(); ?>
<img style="vertical-align:middle;" src="/images/icon_checkin_checkout.jpg">
<span id="<?php echo 'form_error_' . $form->getName() . '_check_out' ?>" class="form_error">
<?php echo $form['check_out']->getError(); ?>
</span>
</div>
</div>
<div class="row">
<div class="col">
<?php echo $form['payment_status']->renderLabel(); ?><br/>
<?php echo $form['payment_status']->render(); ?>
<span id="<?php echo 'form_error_' . $form->getName() . '_payment_status' ?>" class="form_error">
<?php echo $form['payment_status']->getError(); ?>
</span>
</div>
</div>
<div class="row">
<div class="col float-right">
<input type="submit" value="Add Reservation" class="button_black"/>
<div class="col">
</div>
</form>
<div class="clearfix"></div>
</div>
Validation is works for check_in and check_out. But it is nor working for payement_status. Please help me.
This line of code in your form's configure() method
unset($paymentStatus[0]);
has no effect, because you're referencing the forms static variable self::$paymentStatus in the validator's options. You should change your sfValidatorChoice so that its options are
array('choices' => array_keys($paymentStatus))
instead of
array('choices' => array_keys(self::$paymentStatus))
Or what might be easier is to do this:
protected static $paymentStatus = array(
'PAID' => 'Paid',
'PARTIALLY_PAID' => 'Partially Paid',
'NOT_PAID' => 'Not Paid',
);
public function configure()
{
//....
$this->widgetSchema['payment_status'] = new sfWidgetFormSelect(array('choices' => array_merge(array('' => 'Select a payment status'), self::$paymentStatus)));
//...
}