How create and ACF form with preview button? - ajax

I hava a front end form i want to have a preview button for the form. problem is acf form generates the post id after submitting the form. So can't add a preview link
get_preview_post_link this can be used to get the preview link but it requires a iD to passed..
How can i add a preview button? may be ajax save the post as draft? and allow option to publish in the new page?
<?php
acf_form(array(
'post_id' => 'new_post',
'submit_value' => __("Create", 'acf'),
'return' => '%post_url%',
'updated_message' => __('added Successfully', 'acf'),
'post_title' => true,
'post_content' => false,
'new_post' => array(
'post_type' => 'l',
'post_status' => 'publish',
),
));
?>
Please help thanks

Related

magento admin confirmation popup on invoice creation

I am trying to add a confirmation popup on to a existing button in the Magento Admin. When you press capture it shout ask if you are sure. I have found the code of the button in the adminhtml folder and dont know further. I have found out that you can use the onclick parameter to start a js function but that parameter is already set by magento.
Here is the code of the button
if ($this->_isAllowedAction('capture') && $this->getInvoice()->canCapture()) {
$this->_addButton('capture', array(
'label' => Mage::helper('sales')->__('Capture'),
'class' => 'save',
'onclick' => 'setLocation(\''.$this->getCaptureUrl().'\')'
)
);
}
'onclick' => "confirmSetLocation('Are you sure you want to do this?', '{$this->getUrl('*/*/delete')}')",
You have to replace 'onclick' => 'setLocation(\''.$this->getCaptureUrl().'\')'
with 'onclick' => "confirmSetLocation('{$message}', '{$this->getCaptureUrl()}')",

Magento, precomplete custom options while creating/editing a product in admin

I’m trying to precomplete custom options during the process of creating or editing a product in the Magento admin : after product type choice.
I add an event trigger on the Mage_Adminhtml_Block_Catalog_Product_Edit_Tabs _prepareLayout function. So basically when you open the edition or creation of a product, the event is triggered.
My aim is : when you start editing your new product, 3 custom options are already present in the “Custom Options” tab.
I can’t trigger it with the catalog_product_save_before event because one option is a dropdown type and have to be filled by the admin.
So i’ve coded my observer and succeeded to modify the product name with setName() function, but I can"t find how to precomplete/add custom options.
I tried with the code of the following blog : http://kamal250.wordpress.com/2012/10/22/create-custom-option-programatically-while-creating-product/#comments
But it doesn’t seems to work.
Anyone can help me with that ?
Here is my code in the observer :
$option_data = array(
'is_delete' => 0,
'is_require' => true,
'previous_group' => '',
'title' => 'Height',
'type' => 'field',
'price_type' => 'fixed',
'price' => '0',
'sort_order' => 1,
'values' => array()
);
$product->setHasOptions(1);
$product->setCanSaveCustomOptions(1);
$product->setOptions(array($option_data));
$product->setProductOptions(array($option_data));
$opt = Mage::getSingleton('catalog/product_option');
$opt->setProduct($product);
$opt->addOption($option_data);
$opt->saveOptions();
$product->setOption($opt);
Finally i have found the solution :
I modified the trigger to the action of opening the custom options tab.
And here is my code in the observer :
$product = $observer->getProduct();
$option_data = array(
'is_delete' => 0,
'is_require' => true,
'previous_group' => '',
'title' => 'Height',
'type' => 'field',
'price_type' => 'fixed',
'price' => '0',
'sort_order' => 1
);
$product->setHasOptions(1);
$option = Mage::getModel('catalog/product_option')->setProductId($product->getId())->setStoreId($product->getStoreId())->addData($option_data);
$option->save();
$product->addOption($option);
Hope it will help someone sooner or later.
See ya.

drupal ajax call from click of a link in form

How do I submit a form using AJAX when clicking a link in Drupal?
function search_form($form,$form_state) {
$form['support_email'] = array(
'#theme' => 'link',
'#text' => '',
'#ajax' =>array(
'callback' => 'ajax_change',
'wrapper' => 'email-hidden',
'method' => 'replace',
'click' => 'true',
),
);
}
This is the form link I have inside a form. On clicking the link, I want the AJAX callback function ajax_change to be called, which does not seem to be happening.
The forms api reference for the #ajax functionality says that it is "Used by: button, checkbox, checkboxes, image button, password, radio, radios, select, submit, tableselect, textarea, text_format, textfield". Link is not in the list and thus won't work. The #ajax functionality makes Drupal perform an AJAX call when the specified form element changes. Since a link doesn't change, it is logical that it doesnt work.
The Asaf (ajax submit for any form) module may be able to help you to achieve what you want to do.
Also, it appears you are trying to use this AJAX to hide an element. The Forms API has a states functionality that makes it easy to conditionally show/hide elements. Read this for more info about states.
The #ajax callback is used to make a form that dynamically changes itself.
In Drupal it's not possible (without using third party modules) to use link tag as an AJAX triggering element. The alternative solution may be to create a hidden button element with AJAX functionality, and make link trigger click event on that hidden button.
Here is form function:
function mymodule__form($form, $form_state) {
// JS file contains the code for triggering click event on e hidden button.
$form['#attached']['js'][] =
drupal_get_path('module', 'mymodule') . '/js/mymodule.behaviors.js';
// Our link element.
$form['link_mymodule'] = array(
'#type' => 'link',
'#name' => 'link_mymodule',
'#title' => t('Perform mymodule logic'),
'#href' => current_path(),
'#options' => array(
'attributes' => array(
'class' => array('mymodule_ajax'),
),
),
);
// Hidden AJAX enabled submit button.
$form['mymodule_ajax_submit'] = array(
'#type' => 'button',
'#value' => 'AJAX submit',
'#name' => 'mymodule_ajax_submit',
// You may need this to disable validation.
'#limit_validation_errors' => array(),
'#ajax' => array(
'callback' => '_mymodule__form__pager_callback',
'event' => 'click',
),
'#attributes' => array(
// Class "element-hidden" will hide the button.
'class' => array('element-hidden', 'mymodule_ajax_submit'),
),
);
// Some element for tests.
$form['random_thing'] = array(
'#type' => 'markup',
'#markup' => rand(1, 10000),
// Wrapper is needed since AJAX will use it as a container for incoming data.
'#prefix' => '<div class="ajax_wrapper">',
'#suffix' => '</div>',
);
return $form;
}
You will also need callback function for replacing old data with new one since you are using AJAX:
function _mymodule__form__pager_callback($form, &$form_state) {
return array(
'#type' => 'ajax',
'#commands' => array(
ajax_command_replace('.ajax_wrapper', trim(render($form['random_thing']))),
),
);
}
Also you will have to attach click event to your link, which will trigger click event on a hidden button. That's what stored in /js/mymodule.behaviors.js file.
(function ($, Drupal) {
Drupal.behaviors.mymodule = {
attach: function (context, settings) {
// Since behaviors will be executed every times AJAX is called, it's better to use $.once() method even if you
// are going to use "context" argument. That is needed to be sure that event is attached only once.
$('.mymodule_ajax', context).once('mymodule_ajax', function () {
// Bind click event to out link.
$(this).click(function (e) {
// Prevent browser to follow the link.
e.preventDefault();
// Perform click triggering.
$('input.mymodule_ajax_submit').click();
});
});
}
}
}(jQuery, Drupal));

Allow empty cms page content

When using a cms page in magento I sometimes need an empty content section. Most times this is for my homepage. But magento forces me to put something in content before it can be saved.
Is there a way to get magento to allow empty cms page content?
You can use an empty div or span
The Mage_Adminhtml_Block_Cms_Page_Edit_Tab_Content::_prepareForm() method dispatches the adminhtml_cms_page_edit_tab_content_prepare_form event. You can observe this event, grab the field from the form object which is passed into the event, and change its required property to false.
This is a quick and dirty fix, you should really override the admin class so you won't lose the change when you next upgrade.
Anyways, in file app/code/core/Mage/Adminhtml/Block/Cms/Page/Edit/Tab/Content.php, in function _prepareForm(), line 82, change:
$contentField = $fieldset->addField('content', 'editor', array(
'name' => 'content',
'style' => 'height:36em;',
'required' => true,
'disabled' => $isElementDisabled,
'config' => $wysiwygConfig
));
to
$contentField = $fieldset->addField('content', 'editor', array(
'name' => 'content',
'style' => 'height:36em;',
'required' => false,
'disabled' => $isElementDisabled,
'config' => $wysiwygConfig
));
add <div>‍</div> inside your empty elements to stop magento cms from removing them
Its not particularly elegant, but you can just enter and/or hide the content via CSS

Place an image for submit button in Zend form

I have a form made by Zend Framework that needs a submit button. I want to place an image instead of the default button. The code I have is this:
$submit = new Zend_Form_Element_Submit( 'submit');
However, I can not add an image for the submit button here. If I create the form with the following code, it works:
$this->addElement('image', 'submit', array(
'ignore' => true,
'label'=>'Submit',
'src' => ('/media/css/image/submit.png'),
));
How can I add image instead of the default submit button in the first approach of form creation?
$submit = new Zend_Form_Element_Image('submit', array(
'ignore' => true,
'label' => 'Submit',
'src' => '/media/css/image/submit.png'
));

Resources