CKEditor textarea created with display:none - ckeditor

I have recently cloned a script, and while the CKEditor text area in the original works fine, the one in the new script does not.
The original script has the following code:
<td align="left" valign="top">Description: <a target="_blank" href="faq_bb.php#edit"><img title = "<?= $bb_help; ?>" alt="<?= $bb_help; ?>" height=17 width=19 border=0 src="/images2/query_icon.gif"></a>
</td>
<td valign=top align="left" colspan=2>
<?php
$winsize = strlen($bb_desc);
if ($winsize < 255)
{
$editorheight = 10;
}
else
{
$editorheight = 20;
}
$text = html_entity_decode($bb_desc, ENT_QUOTES);
?>
<textarea name="_bb_desc" cols=<?= $editorheight ?>>
<?= $text ?>
</textarea>
<script type="text/javascript">
CKEDITOR.replace( '_bb_desc');
</script>
</td>
The new script has:
<td align="left" valign="top">Description: <a target="_blank" href="faq_bb.php#edit"><img title = "<?= $bb_help; ?>" alt="<?= $bb_help; ?>" height=17 width=19 border=0 src="/images2/query_icon.gif"></a>
</td>
<td valign=top align="left" colspan=2>
<?php
$winsize = strlen($bb_desc);
if ($winsize < 255)
{
$editorheight = 10;
}
else
{
$editorheight = 20;
}
$text = html_entity_decode($bb_desc, ENT_QUOTES);
?>
<textarea name="_bb_desc" cols=<?= $editorheight ?>>
<?= $text ?>
</textarea>
<script type="text/javascript">
CKEDITOR.replace( '_bb_desc');
</script>
</td>
Viewing the rendered page in the Web Console Element Inspector, the original script produces:
<iframe src="" style="width: 100%; height: 100%;" class="cke_wysiwyg_frame cke_reset" title="Rich Text Editor, _bb_desc" aria-describedby="cke_87" tabindex="0" allowtransparency="true" frameborder="0"></iframe>
The new script produces:
<iframe src="" style="width: 100%; height: 100%; display: none !important;" class="cke_wysiwyg_frame cke_reset" title="Rich Text Editor, _bb_desc" aria-describedby="cke_72" tabindex="0" allowtransparency="true" hidden="" frameborder="0"></iframe>
The 2 scripts execute in the same environment, using the same version of CKEditor (4.5.3.Full).
Any suggestions as to what might be causing the different behaviour would be gratefully received.

Well, I found a solution, although I am no more aware of what the issue was than before.
It appears that the issue was caused by the name of the script. If it was called tracker.php, CKEditor did not function correctly. Changing it to, apparently, anything else, solved the problem.
Weird.

Related

ajax only works once a refresh

I was doing a cart section where you can change your product quantity, at first i did it with a normal form, but i change it to ajax because i want to the page doesn´t need to refresh at all to show you your new quantity with your new price and your new total, so i did the following:
$('.actform').on('submit', function(ev) {
var id2 = $(this);
$.ajax({
type: $(id2).attr('method'),
url: $(id2).attr('action'),
data: $(id2).serialize(),
success: function(data) {
$('.container').load(' .container');
},
error: function() {
alert('Ha ocurrido un error');
}
});
ev.preventDefault();
});
It was all okay when you change 1 product for first time, but the second time the forms submits like it doesn´t have ajax, to fix this problem i replaced $('.container').load(' .container'); to $('.container').load(window.location.reload(false)); and it works, but i wanna know if there is another way to do it because this reload stutters a bit the page reload and it looks weird
cart.php whithout ajax (if you need to see):
<main id="main" class="main">
<?php if(!empty($_SESSION['cart'])){ ?>
<div class="container">
<h2 class="carrito-title">Mi Carrito</h2>
<div class="container2">
<div class="container-cart">
<table>
<thead>
<tr>
<th class="product-image">Imagen</th>
<th class="product-name">Producto</th>
<th class="product-price">Precio</th>
<th class="product-quantity">Cantidad (Modificar)</th>
<th class="product-total">Total</th>
<th class="product-remove">Eliminar</th>
</tr>
</thead>
<tbody>
<?php
$total= 0;
foreach($_SESSION['cart'] as $indice=>$producto){
$ID = $producto['ID'];
$select_products = $connect->prepare("SELECT * FROM `productos` WHERE id=$ID") or die('query failed');
$select_products->execute();
$list_products = $select_products->fetchAll(PDO::FETCH_ASSOC);
foreach($list_products as $product){
$nombre= $product['nombre'];
$precio= $product['precio'];
$codigo = $product['codigo'];
$imagen = "media/productos/$codigo.png";
?>
<tr>
<td class="product-image">
<img src="<?php echo $imagen?>" alt="<?php $nombre?>">
</td>
<td class="product-name">
<h2 class="name"><?php echo $nombre?></h2>
</td>
<td class="product-price"><h2 class="precio">$<?php echo number_format($precio, 0, ',', '.') ; ?></h2></td>
<td class="product-quantity">
<form action="backend/actProduct.php" method="post" class="actform" id="<?php echo $ID ?>">
<div class="cantidad">
<div class="cantidad-container">
<input type="hidden" name="id" min="1" value="<?php echo openssl_encrypt($ID,COD,KEY);?>">
<input type="number" class="nro updateCant" onchange="btnCart.click()" name="cantidadupd" value="<?php echo $producto['CANTIDAD'];?>">
<button name="btnCart" value="Update" type="submit" class="actualizar"><i class="fa-solid fa-rotate"></i></button>
</div>
</div>
</form>
</td>
<?php
$sub_total = $precio * $producto['CANTIDAD'];
$total = $total + $sub_total;
?>
<td><h2 class="subtotal">$<?php echo number_format($sub_total, 0, ',', '.'); ?></h2></td>
<td>
<form action="backend/deleteProduct.php" method="post">
<input type="hidden" name="id" value="<?php echo openssl_encrypt($ID,COD,KEY);?>">
<button class="delete" name="btnCart" type="submit" value="Remove" onclick="return confirm('Seguro que quieres eliminar este artículo?');">X</button>
</form>
</td>
</tr>
<?php
}};
?>
</tbody>
</table>
</div>
<?php if(isset($_SESSION['cart'])){ ?>
<div class="nocart">
<div class="final">
<h5 class="final-price preciofinal">Precio sin Impuestos: $<?php echo number_format($total, 0, ',', '.');?></h5>
<form action="backend/emptyCart.php" method="post" class="emptyform" id="<?php echo $ID ?>">
<input type="hidden" name="empty">
<button name="btnCart" type="submit" class ="vaciar" value="Empty" onclick="return confirm('¿Desea vaciar el carrito?');">Vaciar carrito</button>
</form>
</div>
<?php
if ($rol=='representante'){
?>
<div class="checkout">
<form action="productos.php">
<button name="btnFinCart" class="seguircomprando-btn">Seguir comprando</button>
</form>
<a class="checkout-btn" href="clientes.php">Seleccionar cliente</a>
</div>
<?php
}else{?>
<div class="checkout">
<form action="productos.php">
<button name="btnFinCart" class="seguircomprando-btn">Seguir comprando</button>
</form>
<form action="backend/fincompra.php" method="post" onsubmit="showLoad()">
<button name="btnFinCart" class ="checkout-btn" onclick="return confirm('¿Está seguro que desea finalizar la compra?');" value="Fin" >Finalizar compra</button>
</form>
</div>
<?php
}
?>
</div>
</div>
<?php }?>
</div>
<?php }else{
echo '
<div class="nosesion">
<h2 class="cartvacio">El carrito esta vacío</h2>
<a class="comprar-btn" href="productos.php">Comprar ahora</a>
</div>
';
}?>
</main>

What Script, Ajax , Controller codes are responsible for saving quantity

Below code we are using to display quantity text field and update quantity.
I want to know what all code is there in behind to update this quantity.
Means what script, ajax, contoller codes are responsible for saving this quantity.
<li class="fields">
<div class="customer-name">
<div class="field">
<label class="required" for="qty"><em>*</em><?php echo $helper->__('Quantity')?></label>
<div class="input-box">
<input type="text" name="qty" id="qty" value="<?php echo intval($mpAssignProductModel->getQty()) ?>" class="required-entry validate-zero-or-greater input-text"/>
</div>
</div>
</div>
</li>
because when i used above code in another file. It didt worked for me.
another page was displaying like this before :
After i replaced above code in another phtml file, its displaying like this :
This is complete code of file where updating quantity is not working :
phtml code :
<?php
$helper=Mage::helper('mpassignproduct');
$isPartner= Mage::getModel('marketplace/userprofile')->isPartner();
if($isPartner==1){ ?>
<script type="text/javascript">
if (typeof jQuery == 'undefined'){
document.write(unescape("%3Cscript src='http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js' type='text/javascript'%3E%3C/script%3E"));
}
</script>
<script src="//code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
<link rel="stylesheet" href="//code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />
<div>
<div class="page-title">
<h1><?php echo $helper->__('My Assign Product List') ?></h1>
</div>
<div class="wk_mp_design">
<div class="block block-account">
<div class="block-title">
<strong><span><h4><?php echo $helper->__('My Assign Product List'); ?></h4></span></strong>
</div>
</div>
<div class="fieldset wk_mp_fieldset">
<div class="grid">
<div class="hor-scroll">
<?php
if(count($this->getCollection())==0): ?>
<div class="fieldset wk_mp_fieldset">
<div class="wk_emptymsg">
<?php echo $helper->__('No Product Available') ?>
</div>
</div>
<?php else: ?>
<form action="<?php echo Mage::helper('core/url')->getCurrentUrl();?>" method="post">
<table cellspacing="0" class="border wk_mp_list_table">
<thead>
<tr id="wk_mp_tr_heading">
<th><span><?php echo $helper->__('Product Name') ?></span></th>
<th><span><?php echo $helper->__('Date') ?></span></th>
<th><span><?php echo $helper->__('Product Status') ?></span></th>
<th><span> </span></th>
</tr>
</thead>
<tbody class="wk_mp_body">
<tr>
<td>
<input type="text" class="input-text" name="s" placeholder='<?php echo $helper->__('Search by product name') ?>' value="<?php echo $this->getRequest()->getParam('s')?>"/>
</td>
<td>
<span class="wk_mp_td_span">
<?php echo $helper->__('From: ') ?>
<input name="from_date" id="special_from_date" class="input-text" value="<?php echo $this->getRequest()->getParam('from_date')?>" />
</span>
<span class="wk_mp_td_span">
<?php echo $helper->__('To: ') ?>
<input name="to_date" id="special_to_date" class="input-text" value="<?php echo $this->getRequest()->getParam('to_date')?>" />
</span>
</td>
<td>
<select name="prostatus" class="input-text">
<option value=""><?php echo $helper->__('All') ?></option>
<option value="1" <?php if($this->getRequest()->getParam('prostatus') == 1) echo 'selected="selected"'?>>
<?php echo $helper->__('Approved') ?>
</option>
<option value="2" <?php if($this->getRequest()->getParam('prostatus') == 2) echo 'selected="selected"'?>>
<?php echo $helper->__('Unapproved') ?>
</option>
</select>
</td>
<td>
<button class="button" title="Save" type="submit">
<span><span><span><?php echo $helper->__('Submit') ?></span></span></span>
</button>
</td>
</tr>
</tbody>
</table>
</form>
<form name="formmassdelete" id="form-customer-product-delete" method="post" action="<?php echo $this->getUrl('mpassignproduct/index/massdeletepro') ?>">
<input type="hidden" name="form_key" value="<?php echo Mage::getSingleton('core/session')->getFormKey(); ?>" />
<button id="mass_delete_butn" style="float: left;padding: 5px 5px 5px 0;" type="submit" title="Delete Sellers" class="button">
<span><span>Delete Products</span></span>
</button>
<table cellspacing="0" class="border wk_mp_list_table wk_mp_list_container_table">
<thead>
<tr class="wk_content">
<th class="wk_check_first_td">
<span><input type="checkbox" id="mpselecctall" value="all" name="mpselecctall"></span>
</th>
<th class="wk_first_td">
<span class="label "><?php echo $helper->__('Product Name')?></span>
</th>
<th>
<span class="label name"><?php echo $helper->__('Price')?></span>
</th>
<th>
<span class="label name"><?php echo $helper->__('SKU')?></span>
</th>
<th>
<span class="label name"><?php echo $helper->__('Delivery Time')?></span>
</th>
<th>
<span class="label name"><?php echo $helper->__('Replacement Guarantee')?></span>
</th>
<th>
<span class="label qty"><?php echo $helper->__('Status')?></span>
</th>
<th>
<span class="label qty"><?php echo $helper->__('Qty.')?></span>
</th>
<th>
<span class="label qty"><?php echo $helper->__('Condition')?></span>
</th>
<th>
<span class="label"><?php echo $helper->__('Action')?></span>
</th>
</tr>
</thead>
<tbody>
<?php foreach($this->getCollection() as $assinproducts): ?>
<?php $products=Mage::getModel('catalog/product')->load($assinproducts->getProductId()); ?>
<tr class="wk_row_view ">
<td class="wk_check_first_td">
<span>
<input type="checkbox" value="<?php echo $assinproducts->getMpassignproductId(); ?>" class="mpcheckbox" name="product_mass_delete[]">
</span>
</td>
<td class="wk_first_td">
<span class="label name" title="<?php echo $products->getName(); ?>">
<?php
$productname=strlen($products->getName())>7?substr($products->getName(),0,7)."..":$products->getName();
echo $products->getName();
?>
</span>
</td>
<td>
<span class="label price">
<?php echo Mage::helper('core')->currency($assinproducts->getPrice(), true, false);?>
</span>
</td>
<td>
<span class="label sku">
<?php echo $assinproducts->getsku() ?>
</span>
</td>
<td>
<span class="label replacement">
<?php echo $assinproducts->getdeliverytime() ?>
</span>
</td>
<td>
<span class="label delivery">
<?php echo $assinproducts->getreplacement() ?>
</span>
</td>
<td>
<span class="label pro_status">
<?php if($assinproducts['flag']==1): ?>
<?php echo Mage::helper('mpassignproduct')->__('Approved')?>
<?php else: ?>
<?php echo Mage::helper('mpassignproduct')->__('Un-Approved')?>
<?php endif; ?>
</span>
</td>
<td>
<li class="fields">
<div class="customer-name">
<div class="field">
<label class="required" for="qty"><em>*</em><?php echo $helper->__('Quantity')?></label>
<div class="input-box">
<input type="text" name="qty" id="qty" value="<?php echo intval($mpAssignProductModel->getQty()) ?>" class="required-entry validate-zero-or-greater input-text"/>
</div>
</div>
</div>
</li>
</td>
<td>
<span class="label">
<?php
if($assinproducts['product_condition']=='new')
echo Mage::helper('mpassignproduct')->__('New');
else
echo Mage::helper('mpassignproduct')->__('Used');
?>
</span>
</td>
<td>
<span class="label wk_action">
<img src="<?php echo $this->getSkinUrl('marketplace/images/icon-edit.png'); ?>" data-type="<?php echo $assinproducts->getMpassignproductId(); ?>" alt="<?php echo $helper->__('Edit')?>" title="<?php echo $helper->__('Edit')?>" class="mp_edit"/>
<img data-type="<?php echo $assinproducts->getMpassignproductId(); ?>" src="<?php echo $this->getSkinUrl('marketplace/images/icon-trash.png'); ?>" alt="<?php echo $helper->__('Delete')?>" title="<?php echo $helper->__('Delete')?>" class="mp_delete"/>
</span>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</form>
<?php endif; ?>
</div>
</div>
<?php echo $this->getPagerHtml(); ?>
</div>
</div>
<div class="buttons-set">
<p class="back-link">
« <?php echo Mage::helper('marketplace')->__('Back') ?>
</p>
</div>
</div>
<?php }else{
echo "<h2 class='wk_new_msg'>".$helper->__("To BECOME SELLER PLEASE CONTACT TO ADMIN.")."</h2>";
}?>
<script>
function validateNumbers(e)
{
if (jQuery.inArray(e.keyCode, [46, 8, 9, 27, 13, 110, 190]) !== -1 ||
// Allow: Ctrl+A, Command+A
(e.keyCode == 65 && ( e.ctrlKey === true || e.metaKey === true ) ) ||
// Allow: home, end, left, right, down, up
(e.keyCode >= 35 && e.keyCode <= 40)) {
// let it happen, don't do anything
return;
}
// Ensure that it is a number and stop the keypress
if ((e.shiftKey || (e.keyCode < 48 || e.keyCode > 57)) && (e.keyCode < 96 || e.keyCode > 105)) {
e.preventDefault();
}
}
var $wk_jq = jQuery.noConflict();
(function($wk_jq){
$wk_jq( "#special_from_date" ).datepicker({dateFormat: "yy-mm-dd"});
$wk_jq( "#special_to_date" ).datepicker({dateFormat: "yy-mm-dd"});
$wk_jq('#mpselecctall').click(function(event) {
if(this.checked) {
$wk_jq('.mpcheckbox').each(function() {
this.checked = true;
});
}else{
$wk_jq('.mpcheckbox').each(function() {
this.checked = false;
});
}
});
$wk_jq('body').delegate('.mp_edit','click',function(){
var id=$wk_jq(this).attr("data-type");
var dicision=confirm('<?php echo $helper->__(" Are you sure you want to edit this product ? ")?>');
if(dicision==true){
var $type_id=$wk_jq(this).attr('data-type');
window.location = "<?php echo $this->getUrl('mpassignproduct/index/edit/') ?>".concat("id/",id);
}
});
$wk_jq('.mp_delete').click(function(){
var id=$wk_jq(this).attr("data-type");
var dicisionapp=confirm('<?php echo $helper->__(" Are you sure you want to delete this product ? ")?>');
if(dicisionapp==true)
window.location = "<?php echo $this->getUrl('mpassignproduct/index/delete/') ?>".concat("id/",id);
});
$wk_jq('#mass_delete_butn').click(function(e){
var flag =0;
$wk_jq('.mpcheckbox').each(function(){
if (this.checked == true){
flag =1;
}
});
if (flag == 0){
alert("<?php echo $helper->__(' No Checkbox is checked') ?>");
return false;
}
else{
var dicisionapp=confirm('<?php echo $helper->__(" Are you sure you want to delete these product ? ")?>');
if(dicisionapp==true){
$wk_jq('#form-customer-product-delete').submit();
}else{
return false;
}
}
});
})($wk_jq);
function hideReset(product_id)
{
var qtyId='#qty_'+ product_id;
var editLink="#edit_link_"+ product_id;
var updateButton="#update_button_"+ product_id;
var resetButton="#reset_button_"+ product_id;
$wk_jq(qtyId).hide();
$wk_jq(editLink).show();
$wk_jq(updateButton).hide();
$wk_jq(resetButton).hide();
}
function showField(product_id)
{
var qtyId = '#qty_'+ product_id;
var editLink = "#edit_link_"+ product_id;
var updateButton = "#update_button_"+ product_id;
var resetButton = "#reset_button_"+ product_id;
$wk_jq(qtyId).show();
$wk_jq(editLink).hide();
$wk_jq(updateButton).show();
$wk_jq(updateButton).prop('disabled', false);//just in case
$wk_jq(resetButton).show();
return false;
}
function updateField(product_id,assignqty)
{
// alert("Hello! I am an alert box!!");
var qtyId = '#qty_'+ product_id;
var valueId = '#valueqty_'+ product_id;
var updatedqty = '#updatedqty_'+ product_id;
var editLink = "#edit_link_"+ product_id;
var updateButton = "#update_button_"+ product_id;
var resetButton = "#reset_button"+ product_id;
var url = '<?php echo Mage::getUrl('marketplace/marketplaceaccount/updateField/')?>';
$wk_jq(qtyId).toggle();
$wk_jq(editLink).hide();
$wk_jq(updateButton).show();
$wk_jq(resetButton).show();
$qty = $wk_jq(qtyId).val();
jQuery(valueId).html($qty);
hideReset(product_id);
var tmpQty = assignqty+parseInt($qty) ;
new Ajax.Request(url, {
method: 'post',
parameters: {id: product_id, qty: tmpQty},
onComplete: function (transport) {
// alert(tmpQty);
jQuery(priceId).val($price);
jQuery(updatedqty).show().delay(2000).fadeOut();
$updateButton.prop('disabled', false);
}
});
}
</script>
Quantity is working in this file = http://pastebin.com/mByVn3ax

Checkbox Array Validation Codeigniter

On my form each row has it's on submit button and you need to check the check box before you can delete it else it should through error.
Question: My checkbox is in_array but if I do not check the box and then press submit it does not through the codeigniter form_validation error. I have used $this->form_validation->set_rules('selected[]', 'Selected', 'required'); But error not showing up.
What is the best solution in making it getting form_validation error to work?
View
<?php echo form_open('admin/design/layout/delete'); ?>
<?php echo validation_errors('<div class="alert alert-danger">', '</div>'); ?>
<div class="table-responsive">
<table class="table table-striped table-bordered table-hover">
<thead>
<tr>
<td style="width: 1px;" class="text-center">
<input type="checkbox" onclick="$('input[name*=\'selected\']').prop('checked', this.checked);" />
</td>
<td>Layout Name</td>
<td class="text-right">Action</td>
</tr>
</thead>
<tbody>
<?php if ($layouts) { ?>
<?php foreach ($layouts as $layout) { ?>
<tr>
<td class="text-center"><?php if (in_array($layout['layout_id'], $selected)) { ?>
<input type="checkbox" name="selected[]" value="<?php echo $layout['layout_id']; ?>" checked="checked" />
<?php } else { ?>
<input type="checkbox" name="selected[]" value="<?php echo $layout['layout_id']; ?>" />
<?php } ?>
</td>
<td><?php echo $layout['name']; ?></td>
<td class="text-right">
<button type="submit" class="btn btn-danger">Delete</button>
Edit
</td>
</tr>
<?php } ?>
<?php } else { ?>
<?php } ?>
</tbody>
</table>
</div>
</div>
<?php echo form_close(); ?>
Controller Function
public function delete() {
$this->load->library('form_validation');
$this->form_validation->set_rules('selected[]', 'Selected', 'required');
if ($this->form_validation->run() == FALSE) {
echo "Error";
$this->get_list();
} else {
$selected_post = $this->input->post('selected');
if (isset($selected_post)) {
foreach ($selected_post as $layout_id) {
}
echo "Deleted $layout_id";
$this->get_list();
}
}
}
It won't validate per field. selected[] selector in rules means, when you submit your form, it should be at least one selected item. Now you have submit buttons, which are independently submit the form, no matter where are they in the dom, and which checkboxes are selected.
Currently it the same, as you would have one submit button at the end.
I would add some javascript, and set if the checkbox is not selected, you can disable that field:
<script>
$(function() {
$('input:checkbox').on('change', function() {
if($(this).is(':checked')) {
$(this).closest('tr').find('button:submit').prop('disabled', false);
}
else {
$(this).closest('tr').find('button:submit').prop('disabled', true);
}
})
})
</script>
And add disabled to your submit buttons:
<button type="submit" class="btn btn-danger" disabled>Delete</button>
It's not a server side validation, but you can achieve to prevent push the button next unchecked checkboxes.

Magento admin block does not appear

I am experiencing very strange issue:
i have a module and it works in magento 1.4.0.0 - 1.7
recently i have someone that this module does not show in backend.
this the xml layout code
<reference name="content">
<block output="toHtml" type="syncer/adminhtml_mapping" template="wisepricer/mapping.phtml" name="wisepricer.mapping" />
</reference>
another peace of xml layout which goes to head - does appear.
i saw that it finds the block class (if you put die in the block constructor - it works).
But if you put die in the template - nothing. No logging about this.
the path to the template adminhtml/default/default/template/wisepricer/mapping.phtml
any ideas?
thanks
edit:
thanks for the reply guys, here is the additional info:
block declaration in config.xml
<blocks>
<syncer>
<class>Wisepricer_Syncer_Block</class>
</syncer>
</blocks>
part of the block class
<?php
/******************************************
* wisepricer *
******************************************/
class Wisepricer_Syncer_Block_Adminhtml_Mapping extends Mage_Adminhtml_Block_Template
{
function __construct() {
$this->setTemplate("wisepricer/mapping.phtml");
}
public function getHeader(){
$header = "Wisepricer Mapping";
return $header;
}
layout.xml
<?xml version="1.0"?>
<layout version="0.1.0">
<adminhtml_syncer_mapping>
<reference name="head">
<action method="addItem"><type>skin_js</type> <name>wisepricer/prototype17.js</name></action>
<action method="addItem"><type>skin_js</type> <name>wisepricer/chosen.proto.js</name></action>
<action method="addCss"><stylesheet>wisepricer/wisepricer.css</stylesheet> </action>
<action method="addCss"><stylesheet>wisepricer/chosen.css</stylesheet> </action>
<action method="addItem"><type>skin_js</type> <name>wisepricer/chosen.proto.js</name></action>
</reference>
<reference name="content">
<block output="toHtml" type="syncer/adminhtml_mapping" template="wisepricer/mapping.phtml" name="wisepricer.mapping" />
</reference>
</adminhtml_syncer_mapping>
</layout>
template
<?php
$adminobj= new Mage_Adminhtml_Block_Template();
$formkey=$adminobj->getFormKey();
$licenseData=Mage::getModel('wisepricer_syncer/config')->load(1);
?>
<form id="mapping_form" name="mapping_form" method="post" action="<?php echo $this->getUrl('*/*/savemapping')?>">
<input name="form_key" type="hidden" value="<?php echo Mage::getSingleton('core/session')->getFormKey() ?>" />
<input name="mapping_form[stock]" type="hidden" value="qty" />
<div class="top_block">
<div class="top_block_left">
<div class="inner-cont">
<img src="<?php echo $this->getSkinUrl('images/wisepricer/wp-logo.png'); ?>"/>
</div>
</div>
<div class="top_block_right">
<button class="wp-save-btn" onclick="return beforeSubmit()"></button>
</div>
</div>
<div class="mid_block">
<div class="mid_block_left">
<div class="guidelines">
<div class="guidelines-block">
<p><?php echo $this->__('Enter your WisePricer license key you received from WisePricer. This will link this store with your WisePricer account.')?></p>
</div>
<div class="guidelines-block import-guidelines">
<p><?php echo $this->__('Choose which products to import to WisePricer.')?></p>
</div>
<div class="guidelines-block mapping-guidelines">
<h4><?php echo $this->__('Wisepricer mapping guidelines:')?></h4>
<ul>
<li id="rule1"><?php echo $this->__('If you have <span class="field">UPC</span> or <span class="field">ASIN</span> then fields <span class="field">BRAND</span>,<span class="field">MODEL</span>,<span class="field">MPN</span> are not required.')?></li>
<li id="rule2"><?php echo $this->__('If you don\'t have <span class="field">UPC</span> or <span class="field">ASIN</span>, then you should have at least one of the following combinations: <span class="field">BRAND+MODEL</span> or <span class="field">BRAND+MPN</span>')?></li>
<li id="rule3"><?php echo $this->__('You must have either <span class="field">COST</span> or <span class="field">MINPRICE</span> or, you can set fixed rule for <span class="field">MINPRICE</span>')?></li>
<li><?php echo $this->__('<span class="field">NAME</span>, <span class="field">SKU</span>, and <span class="field">PRICE</span> fields are required')?></li>
<li><?php echo $this->__('Other fields are not required, but having them will increase your ability to interact with them within WisePricer(e.g. setting advanced rules, better matching and more)')?></li>
</ul>
</div>
</div>
</div>
<div class="mid_block_right">
<div class="values-block">
<div class="license-block">
<div class="label-block"><label><?php echo $this->__('Enter your License key')?> <span class="required">*</span></label></div>
<input type="text" value="<?php echo $licenseData->getLicensekey()?>" class="input-text required-entry" name="register_form[licensekey]" />
</div>
</div>
<div class="values-block">
<div class="license-block import-settings">
<div class="values-block-sub b10">
<div class="label-block"><label><?php echo $this->__('Import:')?></label></div>
<?php echo $this->renderWebsitesSelect($licenseData->getWebsite())?>
</div>
<div class="values-block-sub b10">
<div class="label-block"><label><?php echo $this->__('Product types:')?></label></div>
<?php echo $this->renderTypesSelect($licenseData->getProduct_type())?>
</div>
<div class="values-block-sub b10 check-block">
<div class="label-block b0"><label><?php echo $this->__('Do not import out of stock items')?></label></div>
<input type="checkbox" name="register_form[import_outofstock]" <?php echo $this->getImportOutStockSet();?>/>
</div>
<div class="values-block-sub check-block">
<div class="label-block b0"><label><?php echo $this->__('Reprice Configurable')?></label></div>
<input type="checkbox" name="register_form[reprice_configurable]" <?php if($licenseData->getReprice_configurable()){ echo 'checked';}?>/>
<p class="wptip"><?php echo $this->__('The Configurable product will be assigned to the price of his cheapest child')?></p>
</div>
</div>
</div>
<p><?php echo $this->__('Please make sure the following fields are assigned correctly:');?></p>
<div class="values-block">
<table cellspacing="0" class="form-list">
<tr class="t-header">
<td><strong><?php echo $this->__('Required Fields')?></strong></td><td><strong><?php echo $this->__('Detected field')?></strong></td>
</tr>
<tr>
<td class="label firstcol"><span><?php echo $this->__('Title')?><span class="required">*</span></span></td>
<td class="input-ele"><?php echo $this->renderAttributesSelect('mapping_form[title]','title','name','required-entry chzn-select')?></td>
<td></td>
</tr>
<tr>
<td class="label firstcol"><span><?php echo $this->__('SKU')?><span class="required">*</span></span></td>
<td class="input-ele"><?php echo $this->renderSkuIdSelect('mapping_form[sku]','sku','sku','required-entry chzn-select')?></td>
<td></td>
</tr>
<tr>
<td class="label firstcol"><span><?php echo $this->__('UPC')?></span></td>
<td class="input-ele">
<?php echo $this->renderAttributesSelect('mapping_form[upc]','upc','upc','chzn-select')?>
</td>
<td class="desc"><p><span><?php echo $this->__('Universal Product Code')?></span></p></td>
</tr>
<tr>
<td class="label firstcol"><span><?php echo $this->__('Brand')?></span></td>
<td class="input-ele"><?php echo $this->renderAttributesSelect('mapping_form[brand]','brand','brand','chzn-select')?></td>
<td></td>
</tr>
<tr>
<td class="label firstcol"><span><?php echo $this->__('Model')?></span></td>
<td class="input-ele"><?php echo $this->renderAttributesSelect('mapping_form[model]','model','model','chzn-select')?></td>
<td></td>
</tr>
<tr>
<td class="label firstcol"><span><?php echo $this->__('MPN')?></span></td>
<td class="input-ele"><?php echo $this->renderAttributesSelect('mapping_form[mpn]','mpn','mpn','chzn-select')?></td>
<td></td>
</tr>
<tr>
<td class="label firstcol"><span><?php echo $this->__('ASIN')?></span></td>
<td class="input-ele">
<?php echo $this->renderAttributesSelect('mapping_form[asin]','asin','asin','chzn-select')?>
</td>
<td class="desc"><p><span><?php echo $this->__('Amazon Standard Identification Number')?></span></p></td>
</tr>
<tr>
<td class="label firstcol"><span><?php echo $this->__('Price')?> <span class="required">*</span></span></td>
<td class="input-ele"><?php echo $this->renderPriceAttributesSelect('mapping_form[price]','price','price','required-entry chzn-select')?></td>
<td></td>
</tr>
<tr>
<td class="label firstcol"><span><?php echo $this->__('Cost')?></span></td>
<td class="input-ele"><?php echo $this->renderAttributesSelect('mapping_form[cost]','cost','0','chzn-select')?></td>
<td></td>
</tr>
<tr>
<td class="label firstcol"><span><?php echo $this->__('Product image')?></span></td>
<td class="input-ele"><?php echo $this->renderAttributesSelect('mapping_form[productimage]','productimage','image','chzn-select')?></td>
<td></td>
</tr>
<tr class="special-opt-cont">
<td colspan="2">
<div class="ship-price-cont minprice">
<div class="ship-price-cont-top">
<div class="label"><?php echo $this->__('MinPrice')?></div>
<div class="value"><?php echo $this->renderAttributesSelect('mapping_form[minprice]','minprice','cost','chzn-select')?></div>
</div>
<div class="ship-price-cont-mid"><span><?php echo $this->__('-Or-')?></span></div>
<div class="ship-price-cont-bott">
<div class="label"><?php echo $this->__('Set a minimum price:')?></div>
</div>
<div class="ship-price-cont-bott desc">
<p><span><?php echo $this->__('this will manually override the choosen attribute.')?></span></p>
</div>
<div class="ship-price-cont-bott">
<div class="label">
<input id="minprice_man" type="text" name="mapping_form[minprice_man]" value="<?php echo $this->getFixedMinPrice()?>"/>
<?php echo $this->renderMinPriceRuleSelects();?>
</div>
</div>
</div>
</td>
<td class="desc"><p><span><?php echo $this->__('Wisepricer will never price below the minimum price you set.')?></span></p></td>
</tr>
<tr>
<td colspan="2">
<div class="ship-price-cont">
<div class="ship-price-cont-top">
<div class="label"><?php echo $this->__('Shipping price')?></div>
<div class="value"><?php echo $this->renderAttributesSelect('mapping_form[shipping]','shipping','0','chzn-select')?></div>
</div>
<div class="ship-price-cont-mid"><span><?php echo $this->__('-Or-')?></span></div>
<div class="ship-price-cont-bott">
<div class="label"><?php echo $this->__('Enter fixed shipping price')?></div>
<div class="value"><input type="text" name="mapping_form[shipping_man]" value="<?php echo $this->getShippingFixedRate()?>"/></div>
</div>
<div class="ship-price-cont-bott desc">
<p><span><?php echo $this->__('this will manually override the choosen attribute.')?></span></p>
</div>
</div>
</td>
<td></td>
</tr>
</table>
</div>
</div>
</div>
<div class="bott_block">
<div class="bott_block_left"></div>
<div class="bott_block_right">
<button class="wp-save-btn" onclick="return beforeSubmit()"></button>
</div>
</div>
</form>
<style>
#wsp-mapping td{
line-height: 20px;
overflow: hidden;
padding: 0 0 20px;
vertical-align: top;
width: 230px;
}
#wsp-mapping td.second-val{
padding-left: 20px
}
#wsp-mapping{
padding-top: 20px
}
</style>
<script type="text/javascript">
document.observe('dom:loaded', function(evt) {
var select, selects, _i, _len, _results;
if (Prototype.Browser.IE && (Prototype.BrowserFeatures['Version'] === 6 || Prototype.BrowserFeatures['Version'] === 7)) {
return;
}
selects = $$(".chzn-select");
_results = [];
for (_i = 0, _len = selects.length; _i < _len; _i++) {
select = selects[_i];
_results.push(new Chosen(select,{disable_search_threshold: 50}));
}
deselects = $$(".chzn-select-deselect");
for (_i = 0, _len = deselects.length; _i < _len; _i++) {
select = deselects[_i];
_results.push(new Chosen(select,{allow_single_deselect:true}));
}
return _results;
});
var editForm = new varienForm('mapping_form');
function beforeSubmit(){
$('rule2').setStyle('border:none');
$('rule1').setStyle('border:none');
$('rule3').setStyle('border:none');
var upc=$('upc').value;
var brand=$('brand').value;
var model=$('model').value;
var asin=$('asin').value;
var mpn=$('mpn').value;
var minprice=$('minprice').value;
var cost=$('cost').value;
var minprice_man=$('minprice_man').value;
var isValid=false;
var failedRule=0;
if(upc!=''||asin!=''){
if(minprice!=''||(cost!=''&&minprice_man!='')){
editForm.submit();
return;
}else{
failedRule=3;
}
}
if((brand!=''&&model!='')||(brand!=''&&mpn!='')){
if(minprice!=''||(cost!=''&&minprice_man!='')){
editForm.submit();
return;
}else{
failedRule=3;
}
}
if(failedRule==3){
$('rule3').setStyle('border:red solid 1px');
}else{
$('rule2').setStyle('border:red solid 1px');
$('rule1').setStyle('border:red solid 1px');
}
alert(Translator.translate('Please follow instructions in your mapping listed on the left.'));
window.location.hash='rule1';
return false;
}
</script>

What is the correct XPath query for 'select onchange'

I'm learning XPath and looking to extract the URL embedded within the following HTML. I've tried variants of #"//table[contains(#option, 'value')]" without success.
<body>
<div id="Wrapper">
<div id="header">
<span id="logoHolder">
<a href="http://www.foo.com">
<img src="/templates/blank_j15/images/nexus_logo.png" width="167" height="65" border="0"/>
</a>
</span>
<span style="float: left; padding-top: 27px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: rgb(0, 182, 222); ">Embracing Diversity. Challenging Minds.</span>
<span id="searchHolder">
<div style="clear: both; "/>
<div id="IE_P_space"/>
<div id="arttotalmenucontent_138" class="hidden">
<script type="text/javascript">
<table cellspacing="0" cellpadding="0" border="0" width="100%" id="wrapper_cont_table">
<tbody>
<tr>
<tr>
<tr>
<td valign="top" id="wrapper_cont_leftNav">
<div class="leftnavCont">
<p>
<select onchange="nl(this.value)" size="8">
<option value="/images/download/newsletter/connect04_300911.pdf">Connect 04: 30/09/2011</option>
<option value="/images/download/newsletter/connect03_230911.pdf">Connect 03: 23/09/2011</option>
<option value="/images/download/newsletter/connect02_150911.pdf">Connect 02: 15/09/2011</option>
<option value="/images/download/newsletter/connect01_120911.pdf">Connect 01: 12/09/2011</option>
</p>
//p/select/option/#value
Seems to work for me.
I think there must be a problem with the usage of your xpath library. It didn't take me long to find the source of your sample.
Here's a working example with my xml library of preference.
#!/usr/bin/env python
import os
from urllib2 import urlopen
from lxml import etree
filename = 'sample.html'
url = 'http://www.foo.example/index.php?option=com_content&view=article&id=186&Itemid=301'
# Some simple caching for a test script...
if os.path.exists(filename):
with open(filename,'r') as f:
data = f.read()
else:
data = urlopen(url).read()
with open(filename,'w') as f:
f.write(data)
doc = etree.HTML(data)
for v in doc.xpath('//p/select/option/#value'):
print v
Produces:
/images/download/newsletter/connect04_300911.pdf
/images/download/newsletter/connect03_230911.pdf
/images/download/newsletter/connect02_150911.pdf
/images/download/newsletter/connect01_120911.pdf

Resources