integrated with JQGrid not loading data into custome edit JQForm - php

I am trying to integrate jqgrid and jqform but the data is not being populated into my jqform. I tested to make sure the jqgrid is passing over search key value for the form, and that works. But for some reason, my reform will not query correctly and populate form objects.
<?php
if(!isset($_SESSION))
session_start();
// Include class
include_once 'jqformconfig.php';
if(!class_exists('jqGridUtils'))
{
include_once $CODE_PATH.'jqUtils.php';
}
include_once $CODE_PATH.'jqForm.php';
$today = getdate(time());
$displayDate = $today['mon']."/".$today['mday']."/".$today['year'].' '.$today['hours'].':'.$today['minutes'].':'.$today['seconds'];
$machrecs = null;
// Create instance
$newForm = new jqForm('MWOForm',array('action' => 'forms/mwoForm.php', 'method' => 'post', 'id' => 'MWOForm'));
// Demo Mode creating connection
if(!class_exists('jqGridDB'))
{
include_once $CODE_PATH.'/jqGridPdo.php';
}
$conn = new PDO(DB_DSN, DB_USER, DB_PASSWORD);
$conn->query("SET NAMES utf8");
$newForm->setConnection( $conn );
// Set url
$newForm->setUrl($SERVER_HOST.$SELF_PATH.'forms/mwoForm.php');
// Set parameters
$mwo_id = jqGridUtils::GetParam('mwo_id',0901270825);
$mwo_id = is_numeric($mwo_id) ? (int)$mwo_id : 0;
$jqformparams = array($mwo_id);
// Set SQL Command, table, keys
$newForm->SelectCommand = 'SELECT mwo_id, asset_id, short_desc as machDesc
FROM mfg_eng_mwo.mwo
WHERE mwo_id =?';
$newForm->table = 'mfg_eng_mwo.mwo';
$newForm->setPrimaryKeys('mwo_id');
$newForm->serialKey = true;
// Set Form layout
$newForm->setColumnLayout('twocolumn');
$newForm->setTableStyles('width:500px;','','');
$statusSQL = 'SELECT distinct type FROM mfg_eng_mwo.wo_status';
$prioritySQL = 'SELECT distinct type FROM mfg_eng_mwo.wo_priority';
$deptSQL = 'SELECT dept_id FROM mfg_eng_mwo.department';
$deptData = '-1:Select a Department';
$machData = "";
$assetData = "";
$postData = "";
if(isset($row))
{
$deptData = "$row[dept]:$row[dept]";
$machData = "$row[asset_no]:$row[machDesc]";
$assetData =$row['asset_no'];
$postData = $row['post'];
}
$parts = '-:Order Parts?;1:YES;0:NO';
$tools = '-:Order Tools?;1:YES;0:NO';
// Add elements
$newForm->addElement('woStatus', 'select', array('label' => '<b>Status</b>', 'datasql' => $statusSQL, 'id' => 'woStatus', 'required'=>true));
$newForm->addElement('WOPriority', 'select', array('label' => '<b>Priority</b>', 'datasql' => $prioritySQL, 'id' => 'woPriority'));
$newForm->addElement('dept', 'select', array('label' => '<b>Deptartment</b>', 'datalist' => $deptData, 'datasql' => $deptSQL, 'id' => 'dept', 'required'=>true));
$newForm->addElement('machDesc', 'select', array('label' => '<b>Machine Desc</b>', 'datalist' => $machData, 'id' => 'machDesc','required'=>true));
$newForm->addElement('asset_id', 'text', array('label' => '<b>Asset ID#</b>', 'value' => $assetData, 'size' => '20', 'id' => 'MWOForm_asset_id', 'readonly'=>true, 'required'=>true));
$newForm->addElement('post', 'text', array('label' => '<b>Post</b>', 'value' => $postData, 'maxlength' => '40', 'id' => 'post', 'readonly'=>true, 'required'=>true));
$newForm->addElement('requester', 'text', array('label' => '<b>Requester</b>', 'value' => $_SESSION['user'], 'maxlength' => '60', 'id' => 'requester', 'readonly'=>true, 'required'=>true));
$newForm->addElement('enterTime', 'text', array('label' => '<b>Created</b>', 'value' => $displayDate, 'maxlength' => '15', 'size' => '20', 'id' => 'enterTime', 'readonly'=>true,'required'=>true));
//$newForm->addElement('short_desc', 'text', array('label' => '<b>Short Description</b>', 'maxlength' => '15', 'size' => '20', 'id' => 'short_desc', 'required'=>true));
//$newForm->addElement('parts', 'select', array('label' => '<b>Parts Needed</b>', 'datalist' => $parts, 'id' => 'parts', 'required' => 'true', 'hidden' => 'true'));
//$newForm->addElement('tools', 'select', array('label' => '<b>Tools</b>', 'datalist' => $tools, 'id' => 'tools', 'hidden' => 'true'));
$newForm->addElement('problem', 'textarea', array('label' => '<b>Problem</b>', 'rows' => "3", 'cols' => "50", 'id' => 'problem', 'required'=>true));
$newForm->addElement('solution', 'textarea', array('label' => '<b>Solution</b>', 'rows' => "3", 'cols' => "50", 'id' => 'solution'));
$elem_8[]=$newForm->createElement('newSubmit','submit', array('value' => 'Submit'));
$newForm->addGroup("newGroup",$elem_8, array('style' => 'text-align:right;', 'id' => 'newForm_newGroup'));
// Add events
$onchangeDept = <<< CHANGEDEPT
function(event)
{
$("#machDesc").show();
var deptval = $("#dept").val();
jQuery.ajax(
{
url: 'machine.php',
dataType: 'json',
data: {q:deptval},
success : function(response)
{
$('#machDesc').find('option').remove();
$('#machDesc').append('<option value=-1>Select Equipment</option>');
jQuery.each(response, function(i,mach)
{
$('#machDesc').append('<option value='+mach.asset_no+'>'+mach.asset_no+'::'+mach.short_desc+'</option>');
});
$('#asset_no').val('');
$('#post').val('');
}
});
}
CHANGEDEPT;
$newForm->addEvent('dept','change',$onchangeDept);
$onchangeMach = <<< CHANGEMACH
function(event)
{
var assetval = $("#machDesc").val();
jQuery.ajax(
{
url: 'post.php',
dataType: 'json',
data: {q:assetval},
success : function(response)
{
jQuery.each(response, function(i,mach)
{
$('#MWOForm_asset_id').val(mach.asset_no);
$('#post').val(mach.post);
});
}
});
}
CHANGEMACH;
$newForm->addEvent('machDesc','change',$onchangeMach);
$beforeSubmit = <<< BS
function(arr, form, options)
{
var toolval = $("#tool").val();
var partval = $("#part").val();
if(toolval == 0 || toolval == 1)
{
alert("Please select 'YES' or 'NO' for tools.");
return false;
}
if(partval != 1 || partval != 0)
{
alert("Please select YES or NO for tools.");
return false;
}
}
BS;
// Add events
$onclicknewButton = <<< CLICKNEWBUTTON
function(event)
{
if($("#ajax-dialog") ) {
$("#ajax-dialog").remove();
}
}
CLICKNEWBUTTON;
$newForm->addEvent('close_modal','click',$onclicknewButton);
// Add ajax submit events
$success = <<< SU
function( response, status, xhr) {
if(response=='success')
{
$("#grid").trigger("reloadGrid", [{current:true}]);
}
}
SU;
// Add ajax submit events
$newForm->setAjaxOptions( array('dataType'=>null,
'resetForm' =>false,
'clearForm' =>false,
'success' =>'js:'.$success,
'beforeSubmit' =>'js:'.$beforeSubmit,
'iframe' => false,
'forceSync' =>false) );
// Render the form
echo $newForm->renderForm($jqformparams);
?>
</body>

Related

PrestaShop: How to remove 'new' button from my backoffice controller

I want to remove the add button from the bo list view toolbar in prestashop is there any way ,(only for my page which I created as a seperate module
or atleast when I click the add button it must not do anything .
require_once(_PS_MODULE_DIR_.'addsocialmedia/addsocialmedia.php');
require_once(_PS_MODULE_DIR_.'addsocialmedia/classes/SocialMedia.php');
class AdminAddSocialMediaController extends ModuleAdminController
{
public $module;
public $html;
public $tabName = 'renderForm';
public function __construct()
{
$this->tab = 'socialmedia';
$this->module = new addsocialmedia();
$this->addRowAction('edit');
$this->explicitSelect = false;
$this->context = Context::getContext();
$this->id_lang = $this->context->language->id;
$this->lang = false;
$this->ajax = 1;
$this->path = _MODULE_DIR_.'addsocialmedia';
$this->default_form_language = $this->context->language->id;
$this->table = _DB_KITS_PREFIX_.'social_media';
$this->className = 'SocialMedia';
$this->identifier = 'id_social_media';
$this->allow_export = true;
$this->_select = '
id_social_media,
name_social_media,
social_media_url,
status
';
$this->name = 'SocialMedia';
$this->bootstrap = true;
$this->initList();
parent::__construct();
}
private function initList()
{
$this->fields_list =
array(
'id_social_media' => array(
'title' => $this->l('Social Media ID'),
'width' => 25,
'type' => 'text',
),
'name_social_media' => array(
'title' => $this->l('Social Media Name'),
'width' => 140,
'type' => 'text',
),
'social_media_url' => array(
'title' => $this->l('Social Media Url'),
'width' => 140,
'type' => 'text',
),
'status' => array(
'title' => $this->l('Enabled'),
'align' => 'text-center',
'status' => 'status',
'type' => 'bool',
'orderby' => false,
'callback' => 'changeStatus',
),
);
$helper = new HelperList();
$helper->shopLinkType = '';
$helper->simple_header = true;
// Actions to be displayed in the "Actions" column
$helper->actions = array('edit');
$helper->identifier = 'code';
$helper->show_toolbar = true;
$helper->title = 'HelperList';
$helper->table = $this->name.'check';
$helper->token = Tools::getAdminTokenLite('AdminModules');
$helper->currentIndex = AdminController::$currentIndex.'&configure='.$this->name;
return $helper;
}
public function initPageHeaderToolbar()
{
$this->page_header_toolbar_title = $this->l('Edit Social Media Image and url/link');
parent::initPageHeaderToolbar();
}
public function initToolbar()
{
parent::initToolbar();
$this->context->smarty->assign('toolbar_scroll', 1);
$this->context->smarty->assign('show_toolbar', 1);
$this->context->smarty->assign('toolbar_btn', $this->toolbar_btn);
}
public function postProcess()
{
parent::postProcess();
$id = (int)Tools::getValue('id_social_media');
$file = Tools::fileAttachment('social_media_image_name');
if (!empty($file['name']) && $id > 0)
{
if (ImageManager::validateUpload($file, Tools::convertBytes(ini_get('upload_max_filesize'))))
die('Image size exceeds limit in your Bigticket Back Office settings');
if (!is_dir('../modules/addsocialmedia/social_media_img'))
#mkdir('../modules/addsocialmedia/social_media_img', 0777, true);
if (!is_dir('../modules/addsocialmedia/social_media_img/'.$id))
#mkdir('../modules/addsocialmedia/social_media_img/'.$id, 0777, true);
$path = '../modules/addsocialmedia/social_media_img/'.$id.'/';
$absolute_path = $path.$file['name'];
move_uploaded_file($file['tmp_name'], $absolute_path);
$imgPath = 'social_media_img/'.$id.'/'.$file['name'];
//Save in DB if needed
Db::getInstance()->execute('UPDATE `'._DB_PREFIX_.''._DB_KITS_PREFIX_.'social_media`
SET `social_media_image_name` = "'.pSQL($imgPath).'"
WHERE `id_social_media` = '.(int)$id);
}
if (Tools::isSubmit('changeStatusVal') && $this->id_object) {
if ($this->tabAccess['edit'] === '1') {
$this->action = 'change_status_val';
d("chnage");
} else {
$this->errors[] = Tools::displayError('You do not have permission to change this.');
}
}
}
//Call back for change status
public function changeStatus($value, $socialMedia)
{
return '<a class="list-action-enable '.($value ? 'action-enabled' : 'action-disabled').'" href="index.php?'.htmlspecialchars('tab=AdminAddSocialMedia&id_social_media='
.(int)$socialMedia['id_social_media'].'&changeStatusVal&token='.Tools::getAdminTokenLite('AdminAddSocialMedia')).'">
'.($value ? '<i class="icon-check"></i>' : '<i class="icon-remove"></i>').
'</a>';
}
/**
* Toggle the Social media to Enabled or Disabled flag- Here the update action occurs
*/
public function processChangeStatusVal()
{
d("hii");
$socialMedia = new SocialMedia($this->id_object);
if (!Validate::isLoadedObject($socialMedia)) {
$this->errors[] = Tools::displayError('An error occurred while updating the Status .');
}
d("going to change");
$socialMedia->status = $socialMedia->status ? 0 : 1;
if (!$socialMedia->update()) {
$this->errors[] = Tools::displayError('An error occurred while updating Social Media Status .');
}
Tools::redirectAdmin(self::$currentIndex.'&token='.$this->token);
}
//When a winner is deleted , delete the image
public function processDelete()
{
$ob=parent::processDelete();
PrestaShopLogger::addLog(sprintf($this->l('%s DELETED social media IMAGE', 'AdminTab', false, false), $this->className), 1, null, $this->className, (int)$id, true, (int)$this->context->employee->id);
if ($ob->deleted==1){
$id = (int)Tools::getValue('id_social_media');
$unlink_path = '../modules/addsocialmedia/social_media_img/'.$id.'/';
unlink($unlink_path); // this must delete the img folder from the winners module dir
//log the delete
PrestaShopLogger::addLog(sprintf($this->l('%s DELETED social media IMAGE', 'AdminTab', false, false), $this->className), 1, null, $this->className, (int)$id, true, (int)$this->context->employee->id);
}
}
//If the user updates the image delete the old image from server
public function processUpdate(){
//d("updating..");
$id = (int)Tools::getValue('id_social_media');
$file = Tools::fileAttachment('social_media_image_name');
if (!empty($file['name']) && $id > 0)
{
$get_previous_image_sql = 'SELECT social_media_image_name FROM `'._DB_PREFIX_._DB_KITS_PREFIX_.'social_media`
where id_social_media='.$id.'';
$get_previous_image_path = Db::getInstance()->getValue($get_previous_image_sql) ;
//d($get_previous_image_path);
$unlink_path = '../modules/addsocialmedia/'.$get_previous_image_path.'';
unlink($unlink_path); // this must delete the img folder from the winners module dir
//log the delete when deleting
PrestaShopLogger::addLog(sprintf($this->l('%s DELETED social media IMAGE while updating new image', 'AdminTab', false, false), $this->className), 1, null, $this->className, (int)$id, true, (int)$this->context->employee->id);
}
}
// This form is populated when add or edit is clicked
public function renderForm()
{
$firstArray =
array(array(
'type' => 'text',
'label' => $this->l('Name'),
'name' => 'name_social_media',
'required' => true,
'col' => '4',
'hint' => $this->l('Invalid characters:').' 0-9!<>,;?=+()##"°{}_$%:'
),
array(
'type' => 'text',
'label' => $this->l('Social Media URL'),
'name' => 'social_media_url',
'required' => true,
'col' => '4',
'hint' => $this->l('Invalid characters:').' 0-9!<>,;?=+()##"°{}_$%:'
),
array(
'type' => 'file',
'label' => $this->l('Social Media Image'),
'name' => 'social_media_image_name',
'display_image' => true,
'required' => false,
'desc' => $this->l('Add .JPG or .PNG File Format.Prefered Width:381 pixels and Height 285 pixels.Prefered File size -50KB .'),
'hint' => array(
$this->l('Add .JPG or .PNG File Format.Prefered Width:381 pixels and Height 285 pixels.Prefered File size -50KB .')
)
),
array(
'type' => 'switch',
'label' => $this->l('Enable Or Disable this Social Media'),
'name' => 'status',
'required' => false,
'class' => 't',
'is_bool' => true,
'values' => array(
array(
'id' => 'status_on',
'value' => 1,
'label' => $this->l('Enabled')
),
array(
'id' => 'status_off',
'value' => 0,
'label' => $this->l('Disabled')
)
),
'hint' => $this->l('Enable or disable this Social Media From front END.')
),
);
if (Tools::getIsset('addkits_social_media') ){
$secondArray = array(
array(
'type' => 'hidden',
'label' => $this->l('Add Date'),
'name' => 'date_add',
'col' => '4',
'values'=>date("Y-m-d H:i:s"),
'hint' => $this->l('Invalid characters:').' 0-9!<>,;?=+()##"°{}_$%:'
),
array(
'type' => 'hidden',
'label' => $this->l('Winner Image Name'),
'name' => 'social_media_image_name',
'col' => '4',
'values'=>"default_value"
)
);
$mainArray = array_merge($firstArray,$secondArray);
}
if (Tools::getIsset('updatekits_social_media') ){
$thirdArray = array(
array(
'type' => 'hidden',
'label' => $this->l('Update Date'),
'name' => 'date_upd',
'col' => '4',
'values'=>date("Y-m-d H:i:s"),
'hint' => $this->l('Invalid characters:').' 0-9!<>,;?=+()##"°{}_$%:'
),
array(
'type' => 'hidden',
'label' => $this->l('Winner Image Name'),
'name' => 'social_media_image_name',
'col' => '4',
'values'=>"default_value"
));
$mainArray = array_merge($firstArray,$thirdArray);
}
$this->fields_form = array(
'tinymce' => true,
'legend' => array(
'title' => $this->l('Configure your Social Media Image and URL'),
'icon' => 'icon-user'
),
'input' => $mainArray
);
//Assign value to hidden
$this->fields_value['date_add'] = $date = date("Y-m-d H:i:s");
$this->fields_value['social_media_image_name'] ="default_image.jpg";
$this->fields_form['submit'] = array(
'title' => $this->l('Save'),
);
$date = date("Y-m-d H:i:s");
$this->addJqueryUI('ui.datepicker');
return parent::renderForm();
}
You have to override the initToolbar method:
public function initToolbar() {
parent::initToolbar();
unset( $this->toolbar_btn['new'] );
}
Cheers ;)
Yes it is at the helper of your module. Could you put the code of the page so I am indicating or remove. Otherwise solution less "clean" applied CSS to hide this button.
Regards,

Magento - How to set up a custom variable in custom Adminhtml form

I am working on a custom Magento extension. Version: 1.9.0.1.
I have a custom Adminhtml form, here it is:
Here is the Form code:
<?php
class VivasIndustries_SmsNotification_Block_Adminhtml_Sms_Status_Edit_Form extends Mage_Adminhtml_Block_Widget_Form
{
protected function _prepareForm()
{
$form = new Varien_Data_Form(array(
'id' => 'edit_form',
'action' => $this->getUrl('*/*/save', array('id' => $this->getRequest()->getParam('id'))),
'method' => 'post',
));
$fieldset = $form->addFieldset('edit_form', array('legend'=>Mage::helper('smsnotification')->__('SMS Information')));
$statuses = Mage::getResourceModel('sales/order_status_collection')
->toOptionArray();
$statuses = array_merge(array('' => ''), $statuses);
$fieldset->addField('state', 'select',
array(
'name' => 'state',
'label' => Mage::helper('smsnotification')->__('Order Status'),
'class' => 'required-entry',
'values' => $statuses,
'required' => true,
)
);
$fieldset->addField('smstext', 'textarea', array(
'label' => Mage::helper('smsnotification')->__('SMS Text'),
'class' => 'required-entry',
'required' => true,
'name' => 'smstext',
'onclick' => "",
'onchange' => "",
'after_element_html' => '<br><small>SMS text must <b>NOT</b> be longer then 160 characters!</small>',
'tabindex' => 1
));
if ( Mage::getSingleton('adminhtml/session')->getsmsnotificationData() )
{
$form->setValues(Mage::getSingleton('adminhtml/session')->getsmsnotificationData());
Mage::getSingleton('adminhtml/session')->setsmsnotificationData(null);
} elseif ( Mage::registry('smsnotification_data') ) {
$form->setValues(Mage::registry('smsnotification_data')->getData());
}
// Add these two lines
$form->setUseContainer(true);
$this->setForm($form);
////
return parent::_prepareForm();
}
}
I use this code to get the customer name from the order:
$CustomerName = $observer->getOrder()->getBillingAddress()->getName();
How can I check the whole text and if it finds CustomVariable_CustomerName to replace it with the real customer name ?

How to get posted data from from to email in SocialEngine?

I edited standard contact form in SocialEngine. Added new 4 fields to it - BirthDate, address, country & postal code field.
First question - how to properly set the default value of Country Select = "USA"?
Second question - how to get posted data from new form's fields (BirthDate, address, country & postal code) to user's email? How need to edit my controller?
My code:
class Pagecontact_Form_Contact extends Engine_Form
{
private $page_id;
public function __construct($page_id)
{
$this->page_id = $page_id;
parent::__construct();
}
public function init()
{
parent::init();
$this
->setTitle('Send Message to Apply for Sponsorship')
->setAttrib('id', 'page_edit_form_contact')
->setAttrib('class', 'global_form');
$topicsTbl = Engine_Api::_()->getDbTable('topics', 'pagecontact');
$topics = $topicsTbl->getTopics($this->page_id);
$viewer_id = Engine_Api::_()->user()->getViewer()->getIdentity();
$options[0] = '';
foreach($topics as $topic)
{
$options[$topic['topic_id']] = $topic['topic_name'];
}
$this->addElement('Date', 'birthdate', array('label' => 'Birthdate:',
'class' => 'date_class', 'name' => 'birthdate'));
$this->addElement('Text', 'address', array('label' => 'Address:',
'class' => 'address_class', 'name' => 'address'));
$this->addElement('Select', 'country', array('label' => 'Country:',
'class' => 'country_class', 'name' => 'country')); //->setValue("USA");
$this->addElement('Text', 'postal', array('label' => 'Postal Code:',
'class' => 'postal_class', 'name' => 'postal'));
$this->addElement('Select', 'topic', array(
'label' => 'PAGECONTACT_Topic',
'class' => 'topic_class',
'multiOptions' => $options,
));
$this->getElement('topic')->getDecorator('label')->setOption('class','element_label_class topic_label_class');
$this->addElement('Hidden', 'visitor', array(
'value' => 0,
'order' => 3,
));
if ($viewer_id == 0)
{
$this->addElement('Text', 'sender_name', array(
'label' => 'PAGECONTACT_Full name',
'class' => 'subject_class',
'allowEmpty' => false,
'size' => 37,
'validators' => array(
array('NotEmpty', true),
array('StringLength', false, array(1, 64)),
),
'filters' => array(
'StripTags',
new Engine_Filter_Censor(),
new Engine_Filter_EnableLinks(),
),
));
$this->getElement('sender_name')->getDecorator('label')->setOption('class','element_label_class sender_name_label_class');
$this->addElement('Text', 'sender_email', array(
'label' => 'PAGECONTACT_Email',
'class' => 'subject_class',
'allowEmpty' => false,
'size' => 37,
'validators' => array(
array('NotEmpty', true),
array('StringLength', false, array(1, 64)),
),
'filters' => array(
'StripTags',
new Engine_Filter_Censor(),
new Engine_Filter_EnableLinks(),
),
));
$this->getElement('sender_email')->getDecorator('label')->setOption('class','element_label_class sender_email_label_class');
$this->addElement('Hidden', 'visitor', array(
'value' => 1,
'order' => 3,
));
}
$this->addElement('Text', 'subject', array(
'label' => 'PAGECONTACT_Subject',
'class' => 'subject_class',
'allowEmpty' => false,
'size' => 37,
'validators' => array(
array('NotEmpty', true),
array('StringLength', false, array(1, 64)),
),
'filters' => array(
'StripTags',
new Engine_Filter_Censor(),
new Engine_Filter_EnableLinks(),
),
));
$this->getElement('subject')->getDecorator('label')->setOption('class','element_label_class subject_label_class');
$this->addElement('Textarea', 'message', array(
'label' => 'PAGECONTACT_Message',
'maxlength' => '512',
'class' => 'message_class',
'filters' => array(
new Engine_Filter_Censor(),
new Engine_Filter_Html(array('AllowedTags' => 'a'))
),
));
$this->getElement('message')->getDecorator('label')->setOption('class','element_label_class message_label_class');
$this->addElement('Hidden', 'page_id', array(
'value' => $this->page_id,
'order' => 7,
));
$this->addElement('Button', 'send', array(
'label' => 'Send',
'type' => 'button',
'class' => 'btn_send_class',
'name' => 'submitted'
));
}
}
Controller:
public function sendAction()
{
$page_id = $this->_getParam('page_id');
$topic_id = $this->_getParam('topic_id');
$subject = $this->_getParam('subject');
$message = $this->_getParam('message');
$senderName = $this->_getParam('sender_name');
$senderEmail = $this->_getParam('sender_email');
$birthDate = $this->getRequest()->getPost('birthdate'); // Empty set
$address = $this->getRequest()->getPost('adress'); // Empty set
$country = "USA"; // Works
$postal = $this->getRequest()->getPost('postal'); // Empty set
$pagesTbl = Engine_Api::_()->getDbTable('pages', 'page');
$select = $pagesTbl->select()
->from(array($pagesTbl->info('name')), array('displayname'))
->where('page_id = ?', $page_id);
$query = $select->query();
$result = $query->fetchAll();
$pageName = $result[0]['displayname'];
$viewer = $this->_helper->api()->user()->getViewer();
$user_id = $viewer->getIdentity();
$topicsTbl = Engine_Api::_()->getDbTable('topics', 'pagecontact');
$emails = $topicsTbl->getEmails($page_id, $topic_id);
$i = 0;
$emails = explode(',',$emails);
foreach($emails as $email) {
$emails[$i] = trim($email);
$i++;
}
if ($user_id != 0) {
$senderName = $viewer['displayname'];
$senderEmail = $viewer['email'];
}
foreach($emails as $email) {
// Make params
$mail_settings = array(
'date' => time(),
'page_name' => $pageName,
'sender_name' => $senderName,
'sender_email' => $senderEmail,
'subject' => $subject,
'message' => $message." ".$birthDate." ".$address." ".$country." ".$postal,
);
// send email
Engine_Api::_()->getApi('mail', 'core')->sendSystem(
$email,
'pagecontact_template',
$mail_settings
);
};
}
}
Eugene,
There is not country field in the your form. But you can do in controller where you are calling the form function like.
{
$form->getElement('country')->setvalue('USA');
}
Please feel free to ask your questions.

Second dialog box doesn't show

I'm developping with Yii framework. I create two dialog boxes in a Yii page to create some model. The first one pops up correctly, but the second one doesn't.
I've written the view file. The view.php is as follow:
<?php
$this->menu=array(
//array('label' => Yii::t('app', 'Publier à un contact'), 'url' => array('publierAContact', 'id_p'=> $model->id_publication, 'id_e' => $model->id_evenement)),
array('label' => Yii::t('app', 'Publier à un contact'), 'url' =>'#','linkOptions' => array(
'onclick' => "{publierAContact(); $('#dialogContact').dialog('open');}",
)),
array('label' => Yii::t('app', 'Publier à un groupe'), 'url' => '#', 'linkOptions' => array(
'onclick' => "{publierAGroupe(); $('#dialogGroupe').dialog('open');}",
))
);
$this->beginWidget('zii.widgets.jui.CJuiDialog', array(
'id' => 'dialogContact',
'options' => array(
'title' => 'Publier à un contact',
'autoOpen' => false,
'modal' => true,
'width' => 550,
'height' => 200,
),
));
echo "<div class='divForForm'></div>";
$this->endWidget('zii.widgets.jui.CJuiDialog');
$this->beginWidget('zii.widgets.jui.CJuiDialog', array(
'id' => 'dialogGroupe',
'options' => array(
'title' => 'Publier à un groupe',
'autoOpen' => false,
'modal' => true,
'width' => 550,
'height' => 200,
),
));
echo "<div class='divForForm'></div>";
$this->endWidget('zii.widgets.jui.CJuiDialog');
?>
<script type='text/javascript'>
function publierAContact()
{
<?php echo CHtml::ajax(array(
'url' => array('Publication/PublierAContact', 'id_p'=>$id_p, 'id_e' =>$id_e),
'data' => "js:$(this).serialize()",
'type' => 'post',
'dataType' => 'json',
'success' => "function(data)
{
if(data.status == 'failure')
{
$('#dialogContact div.divForForm').html(data.div);
//Here is the trick: on submit-> once again this function!
$('#dialogContact div.divForForm form').submit(add);
}
else
{
$('#dialogContact div.divForForm').html(data.div);
setTimeout(\"$('#dialogContact').dialog('close');refreshDisciplines();\", 1000);
document.location.reload();
}
}"
));?>
return false;
}
function PublierAGroupe()
{
<?php echo CHtml::ajax(array(
'url' => array('Publication/PublierAGroupe', 'id_p' => $id_p, 'id_e' => $id_e),
'data' => "js:$(this).serialize()",
'type' => 'post',
'dataType' => 'json',
'success' => "function(data)
{
if(data.status == 'failure')
{
$('#dialogGroupe div.divForForm').html(data.div);
//Here is the trick: on submit-> once again this function!
$('#dialogGroupe div.divForForm form').submit(add);
}
else
{
$('#dialogGroupe div.divForForm').html(data.div);
setTimeout(\"$('#dialogGroupe').dialog('close');refreshDisciplines();\", 1000);
document.location.reload();
}
}"
));?>
return false;
}
</script>
Unfortunately, my second dialog can not appear. Can somebody help me know what's wrong ?
Edit :
The function must be called properly :
'onclick' => "{PublierAGroupe(); $('#dialogContact').dialog('open');}",
as the function's identifier is publierAGroupe.

When Zend_Form validation, validate and find an error all the jQuery hidden fields show up?

I am using Zend_Form and form validation. The issue is I am hiding some of the form fields using jQuery show() and hide() functions.
The problem here is that if the validation finds an error, all the form fields will show up and what I want is to keep the state of the hidden and visible fields. Any idea why this is happening?
If the code makes a difference please ask for it I will provide it immediately.
Zend_Form code:
$this->setMethod('post');
$element = new Zend_Form_Element_File("file", array(
'validators' => array(
array('Extension', true, 'hume')
)
));
$element->setDestination("/var/www/testGraduationProject1/public/TempFolder/");
$element->setLabel("Upload");
$this->addElement($element);
$this->addElement('submit', 'Upload', array(
'ignore' => true,
'label' => 'Upload',
));
$this->addElement('select', 'Work_Space', array(
'Multioptions' =>
array(
'Hume_Compile_Selection' => 'Please Select Compiling type',
'Hume_Recourses' => 'Hume Recourses',
'Hume_Compile' => 'Hume Compile',
),
'id' => 'Work_Space',
'label' => 'Compiler'
));
$this->addElement('select', 'Editor', array(
'Multioptions' =>
array(
'Choose Editor' => 'Choose Editor',
'TinyMce' => 'TinyMce',
'Ymacs' => 'Ymacs',
),
'id' => 'Editor',
'label' => 'Editor'
));
$this->addElement('text', 'File_Name', array(
'label' => 'File name',
'required' => true,
));
$this->addElement('checkbox', 'Advanced_Settings', array(
'checked' => '0',
'label' => 'Advanced Settings',
'id' => 'Advanced_Settings',
));
$this->addElement('textarea', 'Advanced_Options', array(
'label' => 'Advanced Options',
'cols' => 50,
'rows' => 7,
'id' => 'Advanced_Options',
'validators' => array(
array('regex', true, array(
'pattern' => '/[^[a-zA-Z ><+.,!##$%^&*()\"\'=]/',
'messages' => 'Please only numbers without spaces'
)
)
),
'attribs' => array('disabled' => 'disabled'),
));
$this->addElement('textarea', 'comment', array(
'label' => 'Hume Code',
'required' => true,
'class' => 'markItUp',
'id' => 'comment'
));
$this->addElement('checkbox', 'Few_Compile', array(
'checked' => '1',
'label' => 'Fewer Results',
'class' => 'Fewer_Results'
));
$this->addElement('submit', 'Compile_Recourses', array(
'ignore' => true,
'label' => 'Compile Recourses',
'class' => 'Compile_Recourses'
));
$this->addElement('radio', 'Time_Out', array(
'label' => 'Compiling Time',
'multiOptions' => array(
'5' => '5s',
'10' => '10s',
'15' => '15s',
),
'value' => array('5s' => '5s')
));
$this->addElement('checkbox', 'Compile_Advanced', array(
'checked' => '0',
'label' => "Set Heap Wire Stack Size's",
'id' => 'Compile_Advanced',
));
$this->addElement('textarea', 'Heap_Size', array(
'label' => 'Heap Size',
'Id' => 'Heap-Size',
'cols' => 5,
'rows' => 1,
'validators' => array(
array('regex', true, array(
'pattern' => '/[0-9]/',
'messages' => 'Please only numbers without spaces'
)
)
),
'attribs' => array('disabled' => 'disabled'),
));
$this->addElement('textarea', 'Wire_Heap_Size', array(
'label' => 'Wire_Heap Size',
'Id' => 'Wire-Heap-Size',
'cols' => 5,
'rows' => 1,
'validators' => array(
array('regex', false, array(
'pattern' => '/[0-9]/',
'messages' => 'Please only numbers without spaces'
)
)
),
'attribs' => array('disabled' => 'disabled'),
));
$this->addElement('textarea', 'Stack_Size', array(
'label' => 'Stack Size',
'Id' => 'Stack-Size',
'cols' => 5,
'rows' => 1,
'validators' => array(
array('regex', false, array(
'pattern' => '/[0-9]/',
'messages' => 'Please only numbers without spaces'
)
)
),
'attribs' => array('disabled' => 'disabled'),
));
$this->addElement('submit', 'Execute_Hume', array(
'ignore' => true,
'label' => 'Execute And Compile Hume',
));
$this->addElement('submit', 'Compile_Hume', array(
'ignore' => true,
'label' => 'Compile Hume',
));
// die($this->UserHasId);
if ($this->UserHasId) {
$this->addElement('submit', 'Save_File', array(
'ignore' => true,
'label' => 'Save File',
));
}
jQuery hide() and show() functions
<script type="text/javascript">
$(document).ready(function(){
$("#Advanced_Settings").click(function(){
if ($('#Advanced_Settings').is(':checked')) {
$('#Advanced_Options').removeAttr('disabled');
$('#Few_Compile').attr("disabled", "disabled");
} else {
$('#Advanced_Options').attr("disabled", "disabled");
$('#Few_Compile').removeAttr('disabled');
}
});
});
</script>
<script type="text/javascript">
$(document).ready(function(){
$("#Compile_Advanced").click(function(){
if ($('#Compile_Advanced').is(':checked')) {
$('#Heap_Size').removeAttr('disabled');
$('#Wire_Heap_Size').removeAttr('disabled');
$('#Stack_Size').removeAttr('disabled');
} else {
$('#Heap_Size').attr("disabled", "disabled");
$('#Wire_Heap_Size').attr("disabled", "disabled");
$('#Stack_Size').attr("disabled", "disabled");
}
});
});
</script>
<script type="text/javascript">
$(document).ready(function(){
var WorkSpace = $("#Work_Space").val();
if(WorkSpace == "Hume_Compile_Selection"){
$('#Time_Out-label').hide();
$('#Time_Out-element').hide();
$('#Compile_Advanced-label').hide();
$('#Compile_Advanced-element').hide();
$('#Heap_Size-label').hide();
$('#Heap_Size-element').hide();
$('#Wire_Heap_Size-label').hide();
$('#Wire_Heap_Size-element').hide();
$('#Stack_Size-label').hide();
$('#Stack_Size-element').hide();
$('#Compile_Hume-element').hide();
$('#Execute_Hume').hide();
$('#Advanced_Settings-label').hide();
$('#Advanced_Settings-element').hide();
$('#Advanced_Options-label').hide();
$('#Advanced_Options-element').hide();
$('#Few_Compile-label').hide();
$('#Few_Compile-element').hide();
$('#Compile_Recourses-label').hide();
$('#Compile_Recourses-element').hide();
}
$("#Work_Space").change(function(){
var WorkSpace = $(this).val();
if(WorkSpace == "Hume_Recourses"){
$('#Time_Out-label').hide();
$('#Time_Out-element').hide();
$('#Compile_Advanced-label').hide();
$('#Compile_Advanced-element').hide();
$('#Heap_Size-label').hide();
$('#Heap_Size-element').hide();
$('#Wire_Heap_Size-label').hide();
$('#Wire_Heap_Size-element').hide();
$('#Stack_Size-label').hide();
$('#Stack_Size-element').hide();
$('#Compile_Hume-element').hide();
$('#Execute_Hume').hide();
$('#Advanced_Settings-label').show();
$('#Advanced_Settings-element').show();
$('#Advanced_Options-label').show();
$('#Advanced_Options-element').show();
$('#Few_Compile-label').show();
$('#Few_Compile-element').show();
$('#Compile_Recourses-label').show();
$('#Compile_Recourses-element').show();
}else if(WorkSpace == "Hume_Compile"){
$('#Time_Out-label').show();
$('#Time_Out-element').show();
$('#Compile_Advanced-label').show();
$('#Compile_Advanced-element').show();
$('#Heap_Size-label').show();
$('#Heap_Size-element').show();
$('#Wire_Heap_Size-label').show();
$('#Wire_Heap_Size-element').show();
$('#Stack_Size-label').show();
$('#Stack_Size-element').show();
$('#Compile_Hume-element').show();
$('#Execute_Hume').show();
$('#Advanced_Settings-label').hide();
$('#Advanced_Settings-element').hide();
$('#Advanced_Options-label').hide();
$('#Advanced_Options-element').hide();
$('#Few_Compile-label').hide();
$('#Few_Compile-element').hide();
$('#Compile_Recourses-label').hide();
$('#Compile_Recourses-element').hide();
}else if(WorkSpace == "Hume_Compile_Selection"){
$('#Time_Out-label').hide();
$('#Time_Out-element').hide();
$('#Compile_Advanced-label').hide();
$('#Compile_Advanced-element').hide();
$('#Heap_Size-label').hide();
$('#Heap_Size-element').hide();
$('#Wire_Heap_Size-label').hide();
$('#Wire_Heap_Size-element').hide();
$('#Stack_Size-label').hide();
$('#Stack_Size-element').hide();
$('#Compile_Hume-element').hide();
$('#Execute_Hume').hide();
$('#Advanced_Settings-label').hide();
$('#Advanced_Settings-element').hide();
$('#Advanced_Options-label').hide();
$('#Advanced_Options-element').hide();
$('#Few_Compile-label').hide();
$('#Few_Compile-element').hide();
$('#Compile_Recourses-label').hide();
$('#Compile_Recourses-element').hide();
}
});
});
</script>
<script type="text/javascript">
$(document).ready(function(){
var count = 0;
var Editor = $("#Editor").val();
if(Editor == "Choose Editor"){
$('#File_Name-label').hide();
$('#File_Name-element').hide();
$('#File_Name').hide();
$('#comment-label').hide();
$('#comment-element').hide();
$('#comment').hide();
$('#iframe-ymacs').hide();
$('#ymacs-use').hide();
}
$("#Editor").change(function(){
var Editor = $(this).val();
if(Editor == "TinyMce"){
$('#File_Name-label').show();
$('#File_Name-element').show();
$('#File_Name').show();
$('#comment-label').show();
$('#comment-element').show();
$('#comment').show();
$('#iframe-ymacs').hide();
$('#ymacs-use').hide();
$('#accordionResizer').show();
if(count != 0){
$('#comment').hide();
$('#comment_parent').show();
}
if(count == 0){
$('#comment-label').show();
$('#comment-element').show();
$('#comment').show();
tinyMCE.init({
// General options
mode : "exact",
elements : "comment",
theme : "advanced",
skin : "o2k7",
skin_variant : "black",
plugins : "safari,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template",
save_onsavecallback : "saveContent",
// Theme options
theme_advanced_buttons1 : "save,newdocument,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull",
theme_advanced_buttons2 : "search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,forecolor,backcolor",
theme_advanced_buttons3 : "hr,removeformat,|,sub,sup,|,charmap,|,print,|,fullscreen,code",
theme_advanced_buttons4 : "styleselect,formatselect,fontselect,fontsizeselect",
theme_advanced_toolbar_location : "top",
theme_advanced_toolbar_align : "left",
theme_advanced_statusbar_location : "bottom",
theme_advanced_resizing : false,
// Drop lists for link/image/media/template dialogs
template_external_list_url : "lists/template_list.js",
external_link_list_url : "lists/link_list.js",
external_image_list_url : "lists/image_list.js",
media_external_list_url : "lists/media_list.js",
// Replace values for the template plugin
template_replace_values : {
username : "Some User",
staffid : "991234"
}
});
count++;
}
}else if(Editor == "Choose Editor"){
$('#File_Name-label').hide();
$('#File_Name-element').hide();
$('#File_Name').hide();
$('#comment-label').hide();
$('#comment-element').hide();
$('#comment').hide();
$('#iframe-ymacs').hide();
$('#ymacs-use').hide();
$('#accordionResizer').show();
}else if(Editor == "Ymacs"){
$('#File_Name-label').show();
$('#File_Name-element').show();
$('#File_Name').show();
$('#comment-label').hide();
$('#comment-element').hide();
$('#comment').hide();
$('#iframe-ymacs').show();
//$('#iframe-ymacs').contentWindow.location.reload(true);
// document.getElementById("#iframe-ymacs").contentDocument.location.reload(true);
//var iframe = document.getElementById("#iframe-ymacs");
//alert(iframe);
// iframe.src = iframe.src;
jQuery.each($("#iframe-ymacs"), function() {
$(this).attr({
src: $(this).attr("/index/editor")
});
});
$('#iframe-ymacs').attr('src', '/index/editor');
$('#ymacs-use').show();
$('#accordionResizer').hide();
//autoResize('#ymacs');
//$('#accordionResizer').hide();
}
});
});
</script>
If I understand, the form is posted, validated server side and when it has errors, it is populated and sent back to the user. Then, the user sees the form with the error message, am I right? If that is the case, you will need to trigger your Advanced_Settings and Compile_Advanced checkboxes to check if it should be displayed or not. Something like:
<script type="text/javascript">
$(document).ready(function(){
$("#Advanced_Settings").click(function(){
if ($('#Advanced_Settings').is(':checked')) {
$('#Advanced_Options').removeAttr('disabled');
$('#Few_Compile').attr("disabled", "disabled");
} else {
$('#Advanced_Options').attr("disabled", "disabled");
$('#Few_Compile').removeAttr('disabled');
}
});
$('#Advanced_Settings').click(); //This should trigger you checkbox click event
});
</script>
That should hide your advanced settings if the checkbox was not clicked when the form was first submitted.

Categories