Review form is not being submitted - php

In my project, I added a new field location in "product reviews" of admin panel going through the following steps as explained in many blogs.
Created a new field in database table review_detail as location.
Added the following code in app/code/code/Mage/Adminhtml/Block/Review/Edit/Form.php
$fieldset->addField('location', 'text', array(
'name' => 'location',
'label' => Mage::helper('adminhtml')->__('Location'),
'required' => false
)
);
Just above:
$fieldset->addField('nickname', 'text', array(
'label' => Mage::helper('review')->__('Nickname'),
'required' => true,
'name' => 'nickname'
));
.Added the following code in app/code/core/Mage/Review/Model/Resource/Review.php
$detail = array(
'title' => $object->getTitle(),
'detail' => $object->getDetail(),
'nickname' => $object->getNickname(),
'location' => $object->getLocation() /* added */
);
Added "location" in below function array. In the file: app/code/core/Mage/Review/Model/Resource/Review/Collection.php
protected function _initSelect()
{
parent::_initSelect();
$this->getSelect()
->join(array('detail' => $this->_reviewDetailTable),
'main_table.review_id = detail.review_id',
array('detail_id', 'title', 'detail', 'nickname', 'customer_id','location'));
return $this;
}
Added the following in {$mytheme}/template/review/form.phtml:
<li>
<label for="location_field" class="required"><em>*</em><?php echo $this->__('Location') ?></label>
<div class="input-box">
<input type="text" name="nickname" id="location_field" class="input-text required-entry" value="<?php echo $this->htmlEscape($data->getLocation()) ?>" />
</div>
</li>
My problem is that though I can see a new field in admin panel, whenever I submit a review form it is not being submitted/stored in database.
I even re-indexed and cleared the cache.
What should I change more to make it work properly?
Please help... I am on magento 1.8.
PS: I know core files should not be changed. I will override this to new module once I have success in this issue.

I did follow exact steps explained in quetion. And find it working properly.
Only issue I faced was that in {$mytheme}/template/review/form.phtml
You have defined name="nickname" for location field instead of name="location"
Correct this and if you still face same issue than then check if Module Classes as being overridden.

Have a look at the html code created in the browser. Check for:
is your field included within -tags?
is the action type and target set correctly?
with a browser console of your choice (e.g. chrome F12) ensure that fields are correctly set and the form is really sent.

Try this, take db backup first. Delete entry of table from core_resource table and load the site.. In short try to recreate the db table with your column 'location'. I don't know ,what is wrong with setters when we add new field in varien forms they didn't work properly.
I hope this will work.

Related

Codeigniter form validation - how to reject default values

I have a form with default values set, e.g.:
<input type="text" id="mail" name="mail" value="<?php echo set_value('mail', 'jdoe#example.com'); ?>" />
I validate the form using Codeigniter's form_validation class. For this field:
$config = array(
array(
'field' => 'user',
'label' => 'Naam',
'rules' => 'trim|required|valid_email'
));
Here's my problem. When the user leaves the field untouched and submits it's default value 'jdoe#example.com', I want to reject this value. I know I can use a callback, but that would mean I have to write a callback for every field of the form. Not nice!
I've looked into the validation rules. 'differs' looked promising, but it only checks whether one field is different from another field.
Now what's the best way to deal with default values in Codeigniter?
Sounds like you should be using a placeholder instead of a default value. Otherwise what you are asking for doesn't make much sense.
<input type="text" id="mail" name="mail" value="<?php echo set_value('mail'); ?>" placeholder="jdoe#example.com" />
Otherwise you could try the built in validation rule "in_list" e.g. in_list[red,blue,green]
$config = array(
array(
'field' => 'user',
'label' => 'Naam',
'rules' => 'trim|required|valid_email|in_list[jdoe#example.com]'
));
EDIT: Actually you would want the opposite of the in_list rule, i think that would require a callback, but you would only need to write one callback to use for each field.

TYPO3 TCA value as a variable on Fluid

I have a base extension so i can version my website. That means i have not a controller or a repository on the extension. So what i want to do, is to create my own settings on existing elements. I was experimenting around with a text align values on the header content element.
Keep in mind, there is already a setting for this, but i am just
experimenting.
I figured out how to add them and the values are saved on the database.
What i now want to do, is to take the values and add them as a class on FLUID. This is where i stuck. I can not get the values. Any idea how to do it?
After this guide How to enable header_position in TYPO3 7.6
i manage to get my code that far:
On the folder /Configuration/TCA/Overrides/tt_content.php
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
ExtensionManagementUtility::addTCAcolumns('tt_content',[
'header_position_custom' => [
'exclude' => 1,
'label' => 'header position',
'config' => [
'type' => 'select',
'renderType' => 'selectSingle',
'items' => [
['left', 'left'],
['right', 'right'],
['center', 'center']
]
]
]
]);
ExtensionManagementUtility::addFieldsToPalette('tt_content', 'header', '--linebreak--,header_position_custom', 'after:header_layout');
ExtensionManagementUtility::addFieldsToPalette('tt_content', 'headers', '--linebreak--,header_position_custom', 'after:header_layout');
On the folder /Configuration/Typoscript/Constants/Base.typoscript
styles.templates.templateRootPath = EXT:my_website_base/Resources/Private/Extensions/Fluid_styled_content/Resources/Private/Templates/
styles.templates.partialRootPath = EXT:my_website_base/Resources/Private/Extensions/Fluid_styled_content/Resources/Private/Partials/
styles.templates.layoutRootPath = EXT:my_website_base/Resources/Private/Extensions/Fluid_styled_content/Resources/Private/Layouts/
On the /Resources/Private/Extensions/Fluid_styled_content/Resourcs/Private/Partials/Header.html
<h1 class="{positionClass} {header_position_custom} {data.header_position_custom} showed">
<f:link.typolink parameter="{link}">{header}</f:link.typolink>
</h1>
I 've put the class showed just to make sure that i am reading the
file from the path i gave on the constants
File ext_tables.php
TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addStaticFile($_EXTKEY,'Configuration/TypoScript', 'Website Base');
File ext_tables.sql
CREATE TABLE tt_content (
header_position_custom varchar(255) DEFAULT '' NOT NULL,
);
With all these i get my selectbox where i wanted to be and i get the values on the database. That means that if i select the value "Center" in the selectbox, then it will be saved on the database. How can i get this value and use it as class on the FLUID?
Thanks in advance,
You will find your field in the data object.
For inspecting your fluid variables you can use the f:debug-VH:
<f:debug title="the data">{data}</f:debug>
for inspecting all (in the current context) available variables you can debug _all:
<f:debug title="all data">{_all}</f:debug>
Hint: use the title attribute to identify the output
and don't forget to write a get* and set* function for new fields!

How do I set the 'value' in my Zend form checkbox?

The Zend Form is proving to be a bit tricky for me, even as much as I am working with it lately...
I have this form and I am attempting to dynamically create the several checkboxes for it. It is working out alright, except I cannot seem to get the 'value' attribute to change.
In my Zend form class I have this snippet...
// psychotic symptoms
$this->addElement('checkbox', 'psychoticsymptom', array(
'label' => 'psychoticsymptom',
'name' => 'psychoticsymptom',
));
In my view (phtml) I am calling it like this...
<div class="element">
<?php // Psychotic Symptoms
$Criteria = new Criteria();
$Criteria->add( DictionaryPeer::CATEGORY, 'MAR: Psychotic Symptoms' );
$Criteria->addAscendingOrderByColumn( 'Ordinal' );
$this->PsychoticSymptomsList = DictionaryPeer::doSelect( $Criteria );
foreach( $this->PsychoticSymptomsList as $Symptom ) {
$form->psychoticsymptom->setValue($Symptom->getDictionaryId());
$form->psychoticsymptom->setAttrib('name', $Symptom->getWord());
echo $Symptom->getDictionaryId(); // prove my id is coming through... (it is)
$form->psychoticsymptom->getDecorator('label')->setTag(null);
echo $form->psychoticsymptom->renderViewHelper();
$form->psychoticsymptom->setLabel($Symptom->getWord());
echo $form->psychoticsymptom->renderLabel();
echo '<br />';
}
?>
</div>
Everything seems to be working fine, except the value attribute on each checkbox is rendering a value of '1'. I have tried moving the 'setValue' line to several different positions, as to set the value before the form element renders but I am having no luck getting this to work. It's worth any effort to me because I need to do the same type of operation in many areas of my application. I would have done this a bit different too, but I am re-factoring another application and am trying to keep some things unchanged (like the database for instance).
Any help is much appriciated
Thanks
you can try to overwrite the "checkedValue" and "uncheckedValue". check this reference
$this->addElement('checkbox', 'psychoticsymptom', array(
'label' => 'psychoticsymptom',
'name' => 'psychoticsymptom',
'checkedValue' => 'checked Value',
'uncheckedValue' => 'unchecked Value'
));
You seem to only have one psychoticsymptom element "checkbox" which your adding (changing) the value too for each $this->PsychoticSymptomsList.
Maybe you would be better off using a multicheckbox element instead.

Localization of array value in CakePHP

I am trying to localize an existing cakephp application. For the most part I have it working the way I want but there is one scenario I can't figure out.
I am using the form helper to create a form like this:
echo $this->Form->create('search', array('url' =>
array('controller' => '/',
'action' => '/search/searcher'),
'onsubmit'=>'return checkForm();',
'class'=>'find-form'));
echo '<fieldset>';
echo $this->Form->input('name', array(
'type'=>'hidden',
'div'=>false,
'id'=>'name',
'class'=>'nice',
'label'=>false,
'value'=>''
));
echo $this->Form->input('myvalue', array(
'type'=>'text',
'div'=>false,
'id'=>'searchval',
'class'=>'nice',
'value'=> __('Enter search string'),
'label'=>false));
The problem is with the line:
'value'=> __('Enter search string'),
The resulting html looks like this:
...
<fieldset>
<input type="hidden" name="data[search][name]"
id="name" value="" />
Enter Search String
<input name="data[search][myvalue]"
type="text"
id="searchval"
class="nice"
and so on.
The value "Enter Search String" is translated properly but it is outside of the input tag so it shows up outside of the search box.
I've tried various permutations of the code like:
'value'=> echo __('Enter search string'),
'value'=> `__('Enter search string')`,
And nothing seems to work. As I said it works in other areas of the view (in as an array value though) but I can't get this one working.
BTW, the code before I started looked like this:
'value'=> 'Enter search string',
Any ideas?
Thanks for your time.
In CakePHP 1.x the __() function echoes the content by default, while in this case you only want to store it. You can use the second argument to return rather than echo the contents, like this:
'value' => __('Enter search string', true),
From CakePHP 2.0 on upwards you should no longer have to do this, as it returns by default.

Magento - Upload file during registration

I want every user, that registers on my Magento instance, to upload a certificate that shows me that he registered a business.
I already added the fields in the template. But how can I fetch the file and save the filename / contents in the customer record?
Is there a way to extend the functionality in the Controllers?
This is actually even easier:
Just make sure you set these parameters on your config.xml:
'attributes' => array(
'prooffile' => array(
'type' => 'text',
'input' => 'file',
'label' => 'Proof file',
'visible' => true,
'required' => false,
'position' => 100,
"user_defined" => false,
),
This adds a nice editor in your admin backend.
The way I did this:
I added the file field to the registration form:
<li class="fields">
<div class="field">
<div class="input-box">
<label for="prooffile"><?php echo $this->__('Proof of business registration') ?><span class="required">*</span></label><br />
<input type="file" name="prooffile" id="prooffile" title="<?php echo $this->__('Proof of business registration') ?>" class="required-entry input-text" />
</div>
</div>
</li>
Also, make sure that you set the form enctype to "multipart/form-data".
After that, I created a class that subscribes to the "user-register-success" Event. Magento has a very solid Event/Observer mechanism built in.
To do this, you have to have a custom module. In the modules etc/config.xml, add these lines for the event listener:
<events>
<customer_register_success> <!-- The name of the Event -->
<observers>
<customfields> <!-- Your module name -->
<type>singleton</type>
<class>customfields/observer</class> <!-- The class name, that holds your callback function -->
<method>handle_file_upload</method>
</customfields>
</observers>
</customer_register_success>
</events>
This registers an event handler for the event customer_register_success. Make sure that you create a file Observer.php in your modules Model folder:
Model/Observer.php:
<?php
class Komola_Customfields_Model_Observer
{
public function __construct()
{
}
public function handle_file_upload($observer)
{
$customer = $observer->getCustomer();
if (isset($_FILES['prooffile']['name']) && $_FILES['prooffile']['name'] != "") {
$uploader = new Varien_File_Uploader("prooffile");
$uploader->setAllowedExtensions(array('jpg', 'jpeg', 'gif', 'png', 'pdf'));
$uploader->setAllowRenameFiles(false);
$uploader->setFilesDispersion(false);
$path = Mage::getBaseDir("media") . DS . "customer" . DS;
$logoName = $customer->getId() . "." . pathinfo($_FILES['prooffile']['name'], PATHINFO_EXTENSION);
$uploader->save($path, $logoName);
$customer->setProoffile($logoName);
$customer->save();
}
}
}
This takes the uploaded file, and saves the file in the folder media/customer (make sure to create this folder and to make it writable!). It also saves the file name in a custom customer attribute.
In the module installer file, create the attribute like this, and it will appear in the customer backend.
An extra part is needed for newer version of Magento (not sure from when exactly, but it is true as of Magento Community Edition 1.6 and up).
The "used_in_forms" key cannot be in the array passed to the addAttribute call directly (won't work). It probably contain the names of the forms from which the customer model will accept the values and not ignore them when being saved.
Known values are at this question's answers: Can no longer add registration fields in Magento 1.4.2.0 (The answer by Folker Schellenberg)
I think it is the name of the controller and action that rendered the form. This name is also the main layout handle name of the page (eg: customer_account_edit).
It should be noted that the customer form in the front-end is HTML-based. It doesn't dynamically render inputs from the attributes like the backend forms. This means that if these attributes should be input by the user, the template needs to be amended to contain the proper input tags as well (and the proper value added in the used_in_forms array).
$attributeCode = "uploaded_file";
$attributeLabel = "Uploaded file";
$installer->addAttribute('customer', $attributeCode, array(
'type' => 'text',
'input' => 'file',
'label' => $attributeLabel,
'global' => true,
'visible' => true,
'required' => false,
'user_defined' => false
));
// For newer versions of Magento, otherwise won't show up.
$eavConfig = Mage::getSingleton('eav/config');
$attribute = $eavConfig->getAttribute('customer', $attributeCode);
$attribute->setData('used_in_forms', array('customer_account_create', 'adminhtml_customer'));
$attribute->setData('sort_order', 200);
$attribute->save();
Another possible type is 'image' which renders exactly as 'file' except it shows the image in a preview box (a small one). Maybe good for customer photo ?
Also, noteworthy is that is this specific for the customer form (the class that handles this type of attribute is: Mage_Adminhtml_Block_Customer_Form_Element_File and Mage_Adminhtml_Block_Customer_Form_Element_Image), so this won't work in a product attribute without custom work.
Hope this helps !

Categories