Can somebody help me with a situation I am facing?
I'm using a woocommerce table plugin (wct) + woocommerce product addon. If you click on the button to select a pizza, it opens a lightbox popup with some ingredients options.
It's almost perfect, but the point is that i need the user to choose until three options (and not being able to mark all those options), but at least one (this part is solved, because it is a required field).
What if were 2 (min) and 4 (max) ingredients?
Do you know how can I solve that or even another plugin that does the job? I've checked a demo of a plugin, but it allows you to select how many checkboxes you want and only shows a error msg after you click on "buy" buttom. I guess that this method won't work within a lightbox, that it will just close the popup and show the msg at the top of the page.
Thank you so much for your attention.
ingredients lightbox options
You can use jQuery to count how many checkboxes have been checked. When the number is between 1 und 3, the submit button is clickable. If not, the button is disabled.
In my example your checkboxes have the class of check and your submit button the id of sbmBtn so we have access to the elements. Put this is the footer.php file of your theme or just where you want to place the javascript code in your theme files.
<script>
( function( $ ) {
window.updateCount = function() {
var checkcounter = $(".check:checked").length;
};
if(checkcounter == 1 || checkcounter >= 4) {
$("#sbmBtn").attr("disabled", true);
}
else { $("#sbmBtn").attr("disabled", false); }
}( jQuery ) );
</script>
This code will save the number of checked checkboxes in the variable called checkcounter. After that, we check if it has the value we want it to have and disable or enable the button in the different cases.
Related
I'm trying to get Wordpress' Admin Post Page to display some form of output when a specific category (say, 'Featured') is selected.
Something like this (original page):
When I select the 'Featured' category (selected 'Featured' category), I want something to display, like this:
Meaning the page checks if the specific category is checked, and if it is, Wordpress generates an option menu for the user to fill in.
How do I go about doing this? I'm looking at the Wordpress Codex but so far, no dice.
You'll have to print some jQuery only in that screen, and then it's matter of listening for live changes and making the show/hide actions.
The following is from this WPSE Answer. You have to adjust the elements IDs. Also, jQuery's live method is deprecated, change that as well.
add_action('admin_head', 'wpse_53486_script_enqueuer');
function wpse_53486_script_enqueuer() {
global $current_screen;
if ( 'post' == $current_screen->id )
{
echo <<<HTML
<script type="text/javascript">
jQuery(document).ready( function($) {
if ( $('#in-category-6').is(':checked') ) {
$("form#adv-settings label[for='myplugin_sectionid-hide']").show();
$('#myplugin_sectionid').show();
} else {
$('#myplugin_sectionid').hide();
$("form#adv-settings label[for='myplugin_sectionid-hide']").hide();
}
$('#in-category-6').live('change', function(){
if ( $(this).is(':checked') ) {
$('#myplugin_sectionid').show();
$("form#adv-settings label[for='myplugin_sectionid-hide']").show();
} else {
$('#myplugin_sectionid').hide();
$("form#adv-settings label[for='myplugin_sectionid-hide']").hide();
}
});
});
</script>
HTML;
}
}
Another method to print scripts in targeted admin pages.
If you want that you feature will works after the post is saved (so that it already marked id DB to witch category this post belong to), you should use in_category() function to detect whether this post is in the category that you want, and if so - to show your extra box.
But, as I understand you want that it will work also before the post is saved, so you should use jQuery - detect whether the checkbox with value x (where x is your category id) is checked, and then display your extra box by changing css display property from none to block.
Check out Advanced Custom Fields.
It is a wordpress plugin that allows you to add additional fields to posts, and it can do this by category. I have used it before to set background images on posts for use in a slider.
I've been struggling for 2 hours now, searching all over for a solution to this.
I'm working with a Zen-Cart installation, and I've decided to thrown on some dynamic banners. Basically I use jQuery.get() to load a URL from banner1.php - banner1.php has an array of a few urls (which are product pages), and it echoes out a random url from the array.
Once the random URL is loaded by jQuery, I then use the jQuery.load() function to load the image of the product, the price of the product and the name of the product.
All this works absolutely fine, but the problem is that it seems the load() function is interfering with my Zen-Cart "redirect" function. Say if you are viewing a product, let's call it "Product A" - and you decide to log in from that page by clicking the "Login" button - what happens is that you are taken to the Login page, you enter your login details, and hit "Submit". The standard outcome is that if you are logged in successfully, you are taken back to the "Product A" page. But with my little dynamic jQuery banner concoction, instead of redirecting back the "Product A", it loads one of the pages that the jQuery.load() used to generate the random banner. I have 3 banners, each dynamically loading a random url, but here is an example of Banner 1:
<script type="text/javascript">
$.get("banner1.php", function(getbannerlink1) {
$( document ).ready(function() {
$("#banner1").load(getbannerlink1+ " #globalproductimage");
$('#banner1name').load(getbannerlink1+ " #productName", function(result) {
var banner1text = $('#banner1name').html();
banner1text = jQuery(banner1text).text();
$("#banner1name").html(banner1text);
});
$('#banner1price').load(getbannerlink1+ " #productPrices", function(result) {
var banner1prices = $('#banner1price').html();
banner1prices = jQuery(banner1prices ).text();
$("#banner1price").html(banner1prices );
});
var bannerlink1 = $("<a>").attr("href", getbannerlink1);
$("#banner1name").wrap(bannerlink1);
$("#banner1price").wrap(bannerlink1);
$("#banner1").wrap(bannerlink1);
});
});
</script>
The thing is I'm not too concerned about the wrongful redirection once a customer logs in, the problem also occurs most disappointingly when the customer once to actually Checkout. For instance, if they were to have products in their shopping basket, click the Checkout button, which then asks them to login, and once they login, instead of continuing with the standard shopping cart function of taking them to the first step of the checkout process, it redirects them to one of the pages that the dynamic banner has loaded. I don't know how to sort this out, I tried some weird things to no avail. For the sake of reference, this might be needed, this is the Zen-Cart function that handles redirection after a login:
if (sizeof($_SESSION['navigation']->snapshot) > 0) {
// $back = sizeof($_SESSION['navigation']->path)-2;
//if (isset($_SESSION['navigation']->path[$back]['page'])) {
// if (sizeof($_SESSION['navigation']->path)-2 > 0) {
$origin_href = zen_href_link($_SESSION['navigation']->snapshot['page'], zen_array_to_string($_SESSION['navigation']->snapshot['get'], array(zen_session_name())), $_SESSION['navigation']->snapshot['mode']);
// $origin_href = zen_back_link_only(true);
$_SESSION['navigation']->clear_snapshot();
zen_redirect($origin_href);
} else {
zen_redirect(zen_href_link(FILENAME_DEFAULT, '', $request_type));
}
Please help! Perhaps there is an easier way I should be doing this :/
I noticed that the page it loads is always the last banner that jQuery.load() loaded. Like I mentioned there are 3 banners in total, so if Banner 2's price was the last one to load, that's the URL that's loaded in the redirection.
Edit:
banner1.php (this simply generates a random url from an array, but currently for testing purposes I only have one URL in the array):
<?php
$strings = array('http://example.com/index.php?main_page=product_info&cPath=3&products_id=104');
echo $strings[array_rand($strings)];
?>
It appears that the banner page is setting the snapshot href. I assume you are including some of the Zen cart libraries in your banner urls that are setting the Session navigation snapshot. You maybe able to set something to ignore your url for the snapshot.
Adding the banner code may help solve this issue.
Although I would not recommend it, you could add logic to not redirect to certain pages after login.
I have this checkout page (you will have to add an item) Which uses the JavaScript / jQuery seen in this jsFiddle to show/hide some fields for a separate shipping address. When showing, I set the value of all fields to '' and when hiding I set the values of the fields to the same as their respective fields in the billing form.
When you submit the form you should be taken to the paypal login screen (try filling out the form without toggling the different shipping address and submitting) but if you toggle the shipping address it just comes back to the same page.
I have debugged enough to know that it is modifying the fields with .val() that is breaking the form. If I comment out those bits and manually toggle visibility with dev tools, or if I fill out the billing form and never show/hide the shipping (so .val() is never called), everything works fine.
If you are going to look at that page and give it a try, you know its successful if you get to the paypal screen, otherwise it is just coming back to the same page (the form's action is to the same page, but I can't find anything that processes the data - the full php page can be found here - it is a modified version of WPEC's shopping cart page
Here is (most of) the relevant JavaScript:
$('#reveal-shipping').click(function(){
if ( $('.wpsc_checkout_table.table-2').is(':animated') ) return;
if( $('.wpsc_checkout_table.table-2').css('display') == 'none' ){
$('.wpsc_checkout_table.table-2').slideToggle();
$('.wpsc_checkout_table.table-2').find('input, select, textarea').val('');
document.getElementById('reveal-shipping').innerHTML = 'Ship to my billing address ←';
} else {
for ( i=0; i < fields.length; i++ ){
thisval = $(fields[i][0]).val();
$(fields[i][1]).val( thisval );
}
$('.wpsc_checkout_table.table-2').slideToggle();
document.getElementById('reveal-shipping').innerHTML = 'Ship to a different address →';
}
});
You can find the rest on the jsFiddle and on the page itself
Thanks so much in advance for any help I'm really stuck on this!
I think the problem is that you are using display: none to hide the "different shipping adress". When a input field has display none, it will not be sent with your formular. And because of that it redirects you back to the checkout page.
You could use visibility: hidden, but then it would still take up space.
But i strongly recommend you do not do it this way, because if the user has turned javascript off it won't work. You should send all the field and in php, check whether the different adress fields have been submitted, and if they have, use them.
Edit: You could use position to place them outside of the window, like:
position:absolute;
top: -9999px;
visibility:hidden;
I applied tinyMCE to a text area in my sites admin area.
Now there is a page "create category" and and page "edit category."
In edit category, there is a drop-down of the categories, I select one and the text area for category description is filled in with AJAX and a tinyMCE function:_
tinyMCE.activeEditor.setContent(responce);
The category description is filled into the text area on which tinyMCE is applied. But when I click submit, NOTHING happens at all.Similarly, on the create category page, there is no drop down, but when you click submit, nothing happens at all.
This problem does not occur when tinyMCE is not applied. But on the edit category page, it was submitting but not filling in the text area with the category description, when instead of
tinyMCE.activeEditor.setContent(responce);
I used
$("#lang_description").html(responce);
in the callback function for jQuery AJAX.
So the main problem is that the forms are not being submitted and that was the story.
Someone suggested to use the tinyMCE function getContent before I post but I dont understand where and how I would do that.
I've faced a situation once like yours and what I did that was first i set in tinyMCE.init
tinyMCE.init({
mode : "exact", // Used exact
elements : "page_content", // I gave the textarea id and name 'page_content'
...
});
Then I've wrote a function as follows
function get_page_content()
{
var ed = tinyMCE.get('page_content');
return ed.getContent();
}
Then inside my form submit event handler/function I just did
$('#page_content').val(get_page_content()); // I populated my textarea (id=page_content) before the form submission
I received the data using $page_content=$_POST['page_content'] in my php script
Update: May be you can use
var ed=tinyMCE.activeEditor.getContent(); // when you didn't set the mode : "exact" in init function
Reference: getContent and setContent
May be not a solution but If this helps then I'll be glad to know. Also notice Sparky672's comment.
When a user adds an event, they need to be able to add Bands from the "bands" table to the event. It's already all set up with the HABTM, and I have it working when I hard-code multiple select boxes to the page.
The problem is - I'd like to just have one select box, then an "add another band" button - which would add another select input with the list of bands - and so on - as many as they'd like.
I found this post: Add and remove form fields in Cakephp which explains how to add a field dynamically... my issue is, the list of bands is huge, and changes regularly, so I can't imagine this working for me.
Any ideas on the best way to go about this? - Adding a select input dynamically that's populated with a list of bands from my database? Ajax maybe? (I've no idea how to do ajax with cake yet) Ajax seems ok, but do I really want to pull a list of bands every time the user clicks the "add a band" button? Maybe that's ok?
Any help/direction is greatly appreciated. Code example would be GREAT, but if nothing else, a nudge in the right direction would be very helpful.
You could use a single select input with an 'add band' button. When the user hits 'add band', catch the event with javascript, copy the selected band to a list (visually), and add the id to a hidden input (to be used when the form is submitted). jQuery/CakePHP example below.
<ul id='band_list'></ul>
<?php echo $form->create('Event', array('id'=>'event_form'));?>
<?php echo $form->input('band_ids', array('type'=>'hidden', 'id'=>'band_ids')); ?>
<?php echo $form->input('bands', array('type'=>'select', 'options'=>$bands, 'id'=>'bands_selector')); ?>
<button id='add_band'>Add Band</button>
<script type='text/javascript'>
var band_count = 0;
$('#add_band').click(function(event) {
event.preventDefault();
$('<li>' + $('#bands_selector option:selected').text() + '</li>').appendTo('#band_list');
$('<input type="hidden" name="data[Band][Band]['+band_count.toString()+']" value="'+$("#bands_selector option:selected").val()+'">').appendTo('#event_form');
band_count++;
});
</script>