confirm page with form result in cakephp - cakephp

hi i am making a form with a confirm page where I would like to display what was input from the form and give the user a chance to check it before sending it in.
I have successfully done this by saving the form elements in the session:
$this->Session->write('Visitor.confirm', $this->data);
and get it by:
<? $fields = $this->Session->read('Visitor.confirm')?>
<?php echo $fields['Visitor']['v_firstname']; ?>
<?php echo $this->Form->hidden('v_firstname', array('value'=> $fields['Visitor']['v_firstname']));?>
....for each field. but i cannot get the fields to send as a new form? there must be a simpler way!
many thx

Is the 'confirm' button a submit button within your form with all your hidden fields? Or do you have it as a good old fashioned link, and hoping that it submits your hidden form data?
Is there a reason why you would not grab the values out of the session on the page after confirmation, as opposed to resubmitting everything in a hidden form?

you don't have to post the form again. When user clicks confirm, and a confirm() action is called, you just have to save what's in $this->Session->read('Visitor.confirm');

Related

Joomla Contact Form - default_form.php file modification

I am adding custom checkboxes and radio buttons to my Joomla website.
One of the requirements for replacing the browsers checkboxes and radio buttons, is the Input tags must be above the label tags. Why is a mystery to me, maybe someone can explain this also.
Anyhow, I have attempted to modify the Joomla \components\com_contact\views\contact\tmpl\default_form.php file by simply reversing the order for the send email copy checkbox.
When I review the modified contact page in a browser and inspect, the order has not changed ...... nothing at all.
What am I doing wrong?
The changes are like whats show below....
<dt><?php echo $this->form->getInput('contact_email_copy'); ?></dt>
<dd><?php echo this->form->getLabel('contact_email_copy'); ?></dd>

TinyMCE: cake php plugin [ cannot submit form ]

I use https://github.com/CakeDC/TinyMCE to download plugin and did follow all the step to integrate on my cakePHP project. so right now, all the textarea was successfully changed to tinyMCE editor
But when click "SUBMIT" to submit my form, page cannot submit and post data. Without loading editor my form can submit and post data.
Is any jquery problem ? please advise me.
thank you.
Bootsrab.php
CakePlugin::load('TinyMCE');
Configure::write('TinyMCE.editorOptions', array('width' => '500px','height'=>'250px' ));
Controller:
public $helpers=array('Html','Form','TinyMCE.TinyMCE');
View:
$this->TinyMCE->editor(array('theme' => 'advanced', 'mode' => 'textareas'));
echo $this->Form->input('user_requirements',array('required'=>true) );
Layout : default
loding js file:
echo $this->Html->script(array('ddsmoothmenu','jquery-1.7.1.min','jquery-ui-1.8.17.custom.min'));
You've set the field to be required, so the problem you are experiencing is probably the browser based form validation.
The problem is that the validation applies before TinyMCE injects the contents into the textarea, and so the validation will always fail as the textarea is empty. This is a very long known "bug" btw:
http://www.tinymce.com/develop/bugtracker_view.php?id=4768
http://www.tinymce.com/develop/bugtracker_view.php?id=5671
In Firefox you might notice a validation bubble that appears "behind" the browser in the bottom left corner of the screen, and in Chrome for example it would throw the following error: "An invalid form control with name='...' is not focusable".
The quick and dirty fix would be to set required to false. In order to keep the required class on the generated container div you would have to set this manually using the div option:
'div' => array('class' => 'input text required')
It's also possible to disable browser validation completely by defining the novalidate attribute on the form:
$this->Form->create('ModelName', array('novalidate' => true));
or using the formnovalidate attribute on the submit button:
$this->Form->submit('Submit', array('formnovalidate' => true));
Theoretically it would also be possible to listen to the invalid event and display custom validation bubbles, but the problem here is that the browser behavior is not consistent, ie in Chrome it's not possible to validate invisible (using display or visibility) fields. Also the content would still be missing in the textarea field.
What seems to work is using opacity to hide the field, that way one could position the textarea under the editor, and the validation bubble would be displayed correctly. However that would also require to inject the editor contents in the textarea manually when pressing Enter and when clicking the submit button (or probably even simpler using proper editor change events). I'll see if I can come up with an example for this later on.
Update: I've implemented a fix/workaround in form of a TinyMCE 4.x plugin, as this was bugging me in some of my own applications too, see https://github.com/ndm2/tinymce-validatable

Cakephp forms - Is there a way to make a field read only (in the view)

I have a Cakephp 1.3 form that allows users to edit the profile data. But some of the information in the forms needs to be read only (sometimes).
Is my only option to echo and format the field contents in the read only case or is there a flag in the Cake form that allows for read only fields. Ideally the read only fields would be greyed out similar to other interfaces.
echo $this->Form->create('User', array('url' => array('controller' => 'User', 'action'=>'editUser')));
echo $this->Form->input('id', array('type'=>'hidden'));
If (!isset($IsAdmin)) {
// Only display username - read only! Add code here
echo $this->Form->input('username', array('label' => __d('users', 'User',true)));
} else {
// Admins can edit user names
echo $this->Form->input('username', array('label' => __d('users', 'User',true)));
}
... more fields here
echo $this->Form->end(__d('users', 'Submit',true));
You can add a 'disabled' key to the options array, however realise that this is only the front-end/presentation of the form, people will be able to override the 'disabled' property of the input field and modify its value.
To prevent unwanted changes to be saved, you need to specify a 'fieldList' when saving the data using your model
To output a disabled form field;
echo $this->Form->input('fieldname', array('type'=>'hidden', 'disabled' => 'disabled'));
Then, when saving the data, specify a fieldlist (documentation: http://book.cakephp.org/1.3/en/The-Manual/Developing-with-CakePHP/Models.html#saving-your-data)
$this->MyModel->save($this->data, true, array('field1', 'field2'));
The fieldlist should include all fields that are allowed to be updated by the user
The disabled attribute is fine but actually, input fields have a 'readonly' attribute. And it sounds like you want the field to still be shown to the user so using 'hidden' isn't really addressing what you want done.
So an alternative (and actually specifically addressing your requirement for 'read only'):
echo $this->Form->input('fieldname', array('readonly' => 'readonly'));
I found that using disabled prevents jquery click triggers from firing versus readonly still fires e.g. using a bootstrap datepicker text field
Here's a link to WC3 for it: http://www.w3schools.com/tags/att_input_readonly.asp
if you really want to make a field read only why you want to use form field, just echo the value, one can easily change disable or readonly attribute of form field with simple javascript or firebug.
Okay, after having tried several approaches, here is what I like.
1) Use readonly (disabled will remove the value after hitting "save", when you are in update mode, which sucks):
echo $this->Form->input('email', array('readonly' => 'readonly'));
2) To prevent this from updating when removing 'readonly' via browser plugins, you can add this to beforeSave of your model:
if(isset($this->data[$this->alias]['id'])) // id is only set if we update
{
unset($this->data[$this->alias]['email']);
}
Field lists are not comfortable. Why should I add all the fields, when I actually only want to exclude one?
Unsetting will prevent CakePHP from updating it in the database. Of course, after hitting save with an (invalidly) updated e-mail address, this update will be shown in the form once. But as the user has manipulated the HTML form and since the database field stays unchanged, this should not matter.
You can do either of two things:
Make the field hidden
(Ex. echo $this->Form->input ('username, array ('type' => 'hidden'));
Reset the value of username to it's original value, before submitting the form or possibly in beforeSave.

how to grey out php contact form after submit?

I have a PHP contact form, with a simple submit button. What i want to do is once the user has clicked submit, add a function which greys out all text boxes within the form.
Or the form disappears altogether so i can place a label on the page to say its been completed. Is there anyway to go about this without the use of javascript or jquery?
Currently the code for the submit button is:
<input type="submit" value=" Continue " style="width:200px;height:40px">
which uses the PHP post method.
Upon submission, the values should be posted to the PHP script. You can then implement a method of checking if the user's value has been accepted.
At the top of your code, implement the method that is being used to save the input:
<?php
$form_submit_success = false;
//Your input processing code here.
$form_submit_success = true; //Set this variable to true if form data was accepted.
if($form_submit_success) {
//Message to inform the user that form submission was a success.
} else {
?>
<!-- HTML Form Code here -->
<?php
}
?>

Cakephp - keep selected value for dropdownlist after submit

How can I keep the selected value for a dropdownlist after form submission in Cakephp?
If more info (or some code) is needed just tell me please.
UPDATE
Here is part of the code in my view:
echo $this->Form->create('Chart');
echo $this->Form->input('username',
array('label'=>('Usernames List'),
'default'=>('Select username'),
'options'=>$usernames, 'selected'=>false));
echo $this->Form->end('Create Chart');
So, when I press 'Create Chart', the dropdownlist doesn't keep the username that I selected, but it goes back to the first one.
The Form helper uses the data stored in $this->data to prepopulate fields. Make sure that when you are submitting the form, the view that is rendered after has the appropriate model/key data stored in $this->data in order for the Form helper to correctly fill in the appropriate values.
Can we see your controller action possibly? That may help draw a more accurate conclusion.
you should never use the view to set defaults or values (especially selected/value is wrong as it - like your code - destroys the idea of persistent forms).
use the controller instead
#see http://www.dereuromark.de/2010/06/23/working-with-forms/ (Default Values)
add value in dropdown like this:
<?php echo $this->form->select('Schedule.showsid', array('0'=>'title', '1'=>'description'));?>

Resources