Jump to content

ThunderVike

Members
  • Posts

    58
  • Joined

  • Last visited

    Never

Everything posted by ThunderVike

  1. I am using the Classipress Classified Ads theme which must disable various WP functions and rewrite them to work at all. Classipress uses the wp_term_taxonomy table to assign ALL categories in the "taxonomy" field the value "ad_cat". So, all queries are by default looking for Categories and sub-categories of posts that are marked by "ad_cat" in this taxonomy. So post category id 142 might be one child of category id 12, etc. etc. But all posts are grouped by the common distinction of "ad_cat" so that they can be separated from pages and blogs. A series of posts are then listed as ADS belonging to such groups as Parent Category... Rentals....sub-category ... Apartments ( with, in my case just two levels...Parent...child of) But I cannot find a single wordpress function or query which in or outside of the loop of posts looks at the ad/post category id number and then goes UP the hierarchy to retrieve the PARENT Category which the child belongs to and then display the "nice name" such as "Rentals". It seems that there ought to be a query that keeps track of the parent category of every child category with that information ready to be displayed in every single ad every single time no matter where it is called from or how the ad is sorted. I created a function which shows the Parent category name extracted from the breadcrumb script but it only returns this information on pages related to the parent category to start with. Is there a fool-proof "always on" query which displays the Parent category of each post whether as a post summary in a list of posts or on a single post page as easily as it already displays the post title, sub category name, and all post particulars? So an Ad for "Apartment Rentals" as the sub-category or for "House Rentals" as the sub-category, whether shown in a list of Ad summary boxes or on a single page by itself, always has the Parent category name displayed with the Title and other information? So that, for instance, a search for NEWEST ADS might show the following....(right now it just shows the "Sub category" name) Breadcrumbs relies on current page values for categories.... I need something INDEPENDENT of the page values where the ads might be displayed ---------------------------------------- New Apartment in Belle Haven "Rentals" >> "Apartment Rentals" ---------------------------------------- ---------------------------------------- Customized Chevrolet Bel Air "Cars" >> "Customizations" ---------------------------------------- Thank you very much for your help!
  2. Hello David! At LAST, at last! I grabbed a function I had already created and modified it a little to give me all the checkbox names associated with the Post ID. There may be 1 to any number of separate checkbox forms that I create and save for later use...one checkbox form may hold 6 values to be used to display checkboxes for selecting property amenities. Another checkbox form may hold 7 values to list the days of the week, another checkbox may hold values to display a checkbox form for necessary requirements of a renter, etc. So one category of Ad may have different checkboxes assigned to the Ad form for that particular category. I have so many categories that I need more than six or seven checkbox forms available to assign to the different category forms. That is why I needed a dynamic way to automatically generate lines of conditional code that would vary depending on what Ad category this Edit Post/Ad page was displaying. The key to knowing WHICH checkbox names to return was the Post ID. So I modified another function that I had created that relied on the Post ID being returned for each ad that is called for in the edit page php. So, here is the ENTIRE working code.....and I thank you very much for helping me so much with this. It now creates what I needed and allows me to dispense with the hardcode, which was going to be impractical for who knows how many checkbox forms with different names and different values in the future. There is only one place in all this working code that looks awkward in terms of number of CPU load, or efficiency....where I call for the three different conditional IFS just before updating the Post id, meta_key, and meta_value in the database. I had to create TWO update actions to get it done. The second update uses the $$variable you showed me. And the whole thing works, but looks inefficient.... at any rate, David, in case you are interested in what I finally did with your generous help, here is the whole WORKING code that updates unselected checkboxes as well as newly selected checkboxes! I comment some of the lines with Questions to you about efficiency or tidying up..... // saves the ad on the tpl-edit-item.php page template after user makes any changes in custom field values function cp_update_listing() { global $wpdb; // check to see if html is allowed if (get_option('cp_allow_html') != 'yes') $post_content = cp_filter($_POST['post_content']); else $post_content = $_POST['post_content']; // keep only numeric, commas or decimal values if (!empty($_POST['cp_price'])) $_POST['cp_price'] = cp_clean_price($_POST['cp_price']); // keep only values and insert/strip commas if needed and put into an array if (!empty($_POST['tags_input'])) $_POST['tags_input'] = cp_clean_tags($_POST['tags_input']); $new_tags = explode(',', $_POST['tags_input']); // put all the ad elements into an array // these are the minimum required fields for WP (except tags) $update_ad = array(); $update_ad['ID'] = trim($_POST['ad_id']); $update_ad['post_title'] = cp_filter($_POST['post_title']); $update_ad['post_content'] = trim($post_content); $update_ad['tags_input'] = $new_tags; // array //$update_ad['post_category'] = array((int)cp_filter($_POST['cat'])); // maybe use later if we decide to let users change categories // update the ad and return the ad id $post_id = wp_update_post($update_ad); $substitute = array(0); if($post_id) { // I got tired here and simply made a copy of the existing post ID value that my modified function dh_return_checkboxnames // could read as-is // instead of just changing the way I had already written the post Id $postid=$post_id; // I forget whether it was you or wildteen88 who came up with this following code // the code I wanted to generate automatically according to each Ad's requirements: // if (! isset($_POST['cp_checkbox_charley'])) $_POST['cp_checkbox_charley'] = array(); // if (! isset($_POST['cp_checkbox_help'])) $_POST['cp_checkbox_help'] = array(); // if (! isset($_POST['cp_checkbox_hello'])) $_POST['cp_checkbox_hello'] = array(); // now my function to return ALL the relevant CHECKBOX names needed to generate the code above // with your contribution modified by $option substitution function dh_return_checkboxnames($postid) { global $wpdb; // give us the complete checkbox field names held in the $meta_key values -- for just this Ad $sql = $wpdb->prepare("SELECT `wp_cp_ad_fields` . `field_label` , `wp_cp_ad_fields` . `field_name` ,`wp_postmeta` . `post_id` , `wp_postmeta` . `meta_key` , `wp_postmeta` . `meta_value` FROM wp_cp_ad_fields , wp_postmeta WHERE `wp_cp_ad_fields` . `field_name` = `wp_postmeta` . `meta_key` AND `wp_postmeta` . `meta_key` LIKE '%%checkbox%%' AND `wp_postmeta` . `post_id` = ($postid) ORDER by `field_label` ASC "); $results = $wpdb->get_results($sql); if($results) { foreach ($results as $result) : if(!empty($result->meta_key)) {$options = explode(',', $result->meta_key); foreach ($options as $option) { if (!isset($_POST[$option])) $_POST[$option] = array(); } }endforeach; } } dh_return_checkboxnames($postid); // now update all the custom fields foreach($_POST as $meta_key => $meta_value) { // if changed the next line to-- if (cp_str_starts_with($meta_key, 'cp_ && ! 'cp_checkbox')) // would that keep the first IF from also processing all the cp_checkbox strings, since cp_ does not exclude cp_checkbox ? if (cp_str_starts_with($meta_key, 'cp_')){ if ((cp_str_starts_with($meta_key, 'cp_checkbox')) && (isset($_POST[$meta_key]))){ $meta_value=implode(',', $_POST[$meta_key]); } update_post_meta($post_id, $meta_key, $meta_value); } } // here is where I do this again for foreach($_POST as $meta_key => $meta_value) { if ((cp_str_starts_with($meta_key, 'cp_checkbox')) && (! isset($_POST[$meta_key]))){ $meta_value=''; } update_post_meta($$post_id, $$meta_key, $$meta_value); } $errmsg = '<div class="box-yellow"><b>' . __('Your ad has been successfully updated.','cp') . '</b> <a href="' . CP_DASHBOARD_URL . '">' . __('Return to my dashboard','cp') . '</a></div>'; } else { // the ad wasn't updated so throw an error $errmsg = '<div class="box-red"><b>' . __('There was an error trying to update your ad.','cp') . '</b></div>'; } return $errmsg; } Thank you so much for your help, DavidAM! If you see areas for improvement of this code above I would appreciate any comments...
  3. I have discovered that I am trying to do something like This: function checkbox() { foreach($_POST as $meta_key => $meta_value) { if(cp_str_starts_with($meta_key, 'cp_checkbox')) {'if (! isset($_POST[' . $meta_key. '])) $_POST[' .$meta_key. '] = array();'; } } } checkbox(); However, I need to change this: foreach($_POST as $meta_key => $meta_value) I need it to give me not the $Post values, because that filters out the very checkboxes which are unselected....since they are NOT posted at the time of the Submission of all these custom fields. I need to get the returned NAMES of the checkboxes, ALL of them, checked or unchecked, Before the user decides to do something.... NOT AFTER . So, whether or not the user is going to wind up selecting or unselecting the returned checkboxes stored in the database and retrieved from this form....I need a PRE save...that gets all three or four...or whatever checkbox names from the $meta_keys.
  4. Jcbones, thank you so much for taking the time to respond and give me a response. I tried your code and it did not work, and I suspected it would not ahead of time. Here is the "problem"...and I have tried to say this over and over... No, I do NOT WANT TO CHECK ANYTHING FOR WHAT IS WRITTEN....THE CODE IS ALREADY PRECISELY ESTABLISHED THAT I NEED. I cannot more explicitly say this .... I AM NOT CHECKING for any conditions whatsoever WHILE THIS FUNCTION IS LOOPING. THE ONLY THING THIS FUNCTION IS FOR IS TO GENERATE THE NEEDED CODE WITH THE $META_KEY INSERTING THE NAME OF EACH CHECKBOX TWICE PER LINE. The code that WORKS EVERY SINGLE TIME FLAWLESSLY I have posted so many times in this forum over the past weeks. You are the only kind person to have responded, and I thank you! This is frustrating to me because my English is pretty clear. THIS DOES NOT REQUIRE THINKING OUTSIDE THE BOX... I HAVE ALREADY SUPPLIED THE PRECISE CODE...IT ALREADY WORKS AS A HARDCODE I JUST NEED THE EXACT LINES GENERATED AUTOMATICALLY since a simple loop for each $meta_key gives me the cp_checkbox names I need to substitute into the page code. if (! isset($_POST['cp_checkbox_ONE'])) $_POST['cp_checkbox_ONE'] = array(); if (! isset($_POST[$meta_key])) $_POST[$meta_key] = array(); But something is NOT happening correctly when I try this dynamically...whatever is outputted is not working because unselected checkboxes are not wiped out on the save....the old array values return. When I reinstall the hard code I keep including here for reference it works perfectly all the time. Unselected checkboxes, where every single checkbox is unselected, return unselected....just what I wanted. The HARD CODE sits there ready to be checked against the posted field strings, when a string starts with the Meta Key 'cp_checkbox', and THAT PARTICULAR CHECKBOX IS UNSELECTED THEN IT IS and MUST BE EQUAL TO AN ARRAY. THIS WILL NEVER WORK for this page...it has been tried and failed....: if (!is_array($_POST[$meta_key])) The hard code PRESUPPOSES THE EXACT SITUATION AHEAD OF TIME, THE CODE ALREADY KNOWS WHAT IS BEING LOOKED FOR AND WHAT IS NEEDED FOR THIS PARTICULAR SITUATION AND NOTHING ELSE WORKS!! NO CHECKING FOR ARRAYS while this function "decides" anything ...IT DOES NOT WORK THAT WAY...PERIOD. It absolutely has to be....no exceptions, no other supposItions....what has to be AVAILABLE BEFORE THE DATABASE IS UPDATED WITH ANY CHANGED CUSTOM FIELD VALUES IS THIS---VERBATIM, CHARACTER FOR CHARACTER... THIS CODE HAS TO BE AVAILABLE TO FOR COMPARISON....COMPARISON.... IF THE CUSTOM FIELDS WITH 'CP_CHECKBOX_ONE' OR 'CP_CHECKBOX_TWO' OR 'CP_CHECKBOX_THREE' ARE UNSELECTED....if (! isset($_POST['cp_checkbox_ONE'])) THEN THE FUNCTION IS TOLD THAT $_POST['cp_checkbox_ONE'] = array(); IS GOING TO BE AN ARRAY This has to exist when the checkbox is UNSELECTED because I have another function that says that IN THIS CASE $meta_value = '' Because if the checkbox is unselected before the edit form is saved again then we STILL have to return an array with '' -- we have to empty out that previous checkbox array....if the previous returned checkbox array has Sunday,Monday,Tuesday,Wednesday then THAT array has to be overwritten by ' '....nothing, erased in the database. So, again, I don't want to check for anything as a condition for running this loop. I am trying like crazy to simply DYNAMICALLY WRITE these lines.... // Make sure the checkbox arrays exist if (! isset($_POST['cp_checkbox_ONE'])) $_POST['cp_checkbox_ONE'] = array(); if (! isset($_POST['cp_checkbox_TWO'])) $_POST['cp_checkbox_TWO'] = array(); if (! isset($_POST['cp_checkbox_THREE'])) $_POST['cp_checkbox_THREE'] = array(); So, again, I must find a way to make some variation of this function work..... function checkboxloop() { //function start. foreach($_POST as $meta_key => $meta_value) { //loop the $_POST key/values. if(cp_str_starts_with($meta_key, 'cp_checkbox')) { //if the POST key starts with cp_checkbox. if (! isset($_POST[$meta_key])) $_POST[$meta_key] = array(); //if POST[key] is not set <<This condition will always revert to false, because you are checking to see if a set condition is NOT set. AND THIS IS EXACTLY WHAT I NEED----THIS CODE MUST SIT HERE READY TO CHECK IF THE POST KEY IS NOT SET ! } } } The only problem is that something about it is not working.....in practice....
  5. if (! isset($_POST['cp_checkbox_three'])) this is what gives me problems.... I just want it to be WRITTEN, NOT PROCESSED for the if (! isset($_POST['cp_checkbox_three'])) WHILE the function is substituting the $meta_key return in the loop I posted as my "solution" if I simply put an echo $meta_key . '<br>'; in that loop it will give me back the values I need, like this... cp_checkbox_one cp_checkbox_two cp_checkbox_three So I want to substitute the $meta_key iteration into if (! isset($_POST['cp_checkbox_one'])) $_POST['cp_checkbox_one'] = array(); by doing if (! isset($_POST[$meta_key])) $_POST['$meta_key] = array(); and it keeps going, line after line, but the "IF" in if (! isset($_POST is not a LIVE condition at the time of the looping action, it is the thing that causes errors in the different ways that I try to create a dynamic write.....
  6. Sorry for the confusion....if I post the whole code then no-one answers. So, I tried to break it down to the simplest terms. As I said; I have three lines in existing code PHP code -- here they are again-- if (! isset($_POST['cp_checkbox_one'])) $_POST['cp_checkbox_one'] = array(); if (! isset($_POST['cp_checkbox_two'])) $_POST['cp_checkbox_two'] = array(); if (! isset($_POST['cp_checkbox_three'])) $_POST['cp_checkbox_three'] = array(); These exist inside a function that updates a form and allows a user to look at the form just filled out and saved to the database. When the user looks at this form they see the values they previously filled out and have a chance at this point in the process to CHANGE the values in the form fields. Most of these are Custom fields stored in a Wordpress table. The PROBLEM has been with the CHECKBOX forms. One checkbox form may have values in common, such as Property amenities of a real estate listing, as an example. Another checkbox form may store values for days of the week. [] stores the arrays from Checkboxes....and another function IMPLODES the values selected and puts a comma between them and saves them back in the appropriate checkbox arrays with commas separating the values. So, here we go: If I know ahead of time WHICH checkbox forms are going to be used then I can write a necessary line of code for each checkbox form that says, essentially, "If this condition is present then the checkbox named 'cp_checkbox_one'[] will be an array" ...and the same for the other named checkboxes I have referred to. Again, this is the code...hard code in PHP--- I wrote it and there it sits ready to help out if referenced later. if (! isset($_POST['cp_checkbox_one'])) $_POST['cp_checkbox_one'] = array(); if (! isset($_POST['cp_checkbox_two'])) $_POST['cp_checkbox_two'] = array(); if (! isset($_POST['cp_checkbox_three'])) $_POST['cp_checkbox_three'] = array(); So, all well and good. -But I have to REPLACE those lines with something dynamic.... so that when the function checks for any strings that contain a 'cp_checkbox' it will dynamically write the lines above so that if this form returns in the future 'cp_checkbox_three' and 'cp_checkbox_six' (you get the idea) then it will write if (! isset($_POST['cp_checkbox_three'])) $_POST['cp_checkbox_three'] = array(); if (! isset($_POST['cp_checkbox_six'])) $_POST['cp_checkbox_six'] = array(); When I tried different ways of making PHP write these kinds of lines EXACTLY as my examples based on the Form names returned I can see the names come back 'cp_checkbox...whatever, whatever'....if I test with an echo $meta_key ; But, the IF, the IF is a LIVE condition...I do not know how else to say that.... I have posted the way I was trying to do the same thing.... function checkboxloop() { foreach($_POST as $meta_key => $meta_value) { if(cp_str_starts_with($meta_key, 'cp_checkbox')) { if (! isset($_POST[$meta_key])) $_POST[$meta_key] = array(); } } } // HERE I ASK FOR THE FUNCTION BUT WHILE I GET NO ERRORS I GET NO RESULTS // WHICH IS A PROPER SAVE OF UNCHECKED CHECKBOXES ON SUBMIT checkboxloop;
  7. I am trying to make a loop simply write "static" code...if that is the correct explanation.... But it seems PHP wants to "process" such things as 'IF' and other Conditions which is defeating the purpose. The problem specifically is that I NEED for a dynamic write to happen based on a variable that will put the following lines that start with IF (! isset // Make sure the checkbox arrays exist if (! isset($_POST['cp_checkbox_one'])) $_POST['cp_checkbox_one'] = array(); if (! isset($_POST['cp_checkbox_two'])) $_POST['cp_checkbox_two'] = array(); if (! isset($_POST['cp_checkbox_three'])) $_POST['cp_checkbox_three'] = array(); // here in the lines below is one way I have tried to make the the LINES ABOVE get written Dynamically // THIS PART returns the values I need, the checkbox names ---- // // foreach($_POST as $meta_key => $meta_value) { // if(cp_str_starts_with($meta_key, 'cp_checkbox')) { echo $meta_key; } // } // So that code WILL RETURN THE VALUES I NEED : // cp_checkbox_one, cp_checkbox_two, cp_checkbox_three // BASED ON THIS I WROTE THE FOLLOWING CODE-- BUT IT DOES NOT WORK AS A REPLACEMENT FOR A LINE // SUCH AS--- if (! isset($_POST['cp_checkbox_one'])) $_POST['cp_checkbox_one'] = array(); // function checkboxloop() { foreach($_POST as $meta_key => $meta_value) { if(cp_str_starts_with($meta_key, 'cp_checkbox')) { if (! isset($_POST[$meta_key])) $_POST[$meta_key] = array(); } } } // HERE I ASK FOR THE FUNCTION BUT WHILE I GET NO ERRORS I GET NO RESULTS // WHICH IS A PROPER SAVE OF UNCHECKED CHECKBOXES ON SUBMIT checkboxloop; I would very much appreciate knowing how to make the code keep looping whatever $meta_key names turn up on this page and then use those names to write the complete lines as STATIC PHP so that the IF conditions don't get "processed" while this function is called. In effect, I want to duplicate the effect of having the code lines WRITTEN, so that they perform exactly as if I had written them as PHP hard-code, as many lines as there will be $meta_keys, but not SEE the code--- just have it valid PHP. This function does NOT make the same thing happen internally. As soon as I replace the function with the HARD CODE PHP then it works...but, I have reached the stage where these lines of code have to happen dynamically. I am baffled how to get this to happen! If I use Echo then I get errors about the "IF". Thank you very much for your help!
  8. Well, it has been fun replying to myself. I have tried scads of things including $$variable to loop through variables but nothing works. I am stuck. Nothing I have learned or tried in the past months and a half has worked for my problem.
  9. I have been trying all things trying to find the logic of if,foreach, while, case... for a nested conditional... The shared server environment most basically; PHP Version 5.2.14 mysql 5.0.67 magic_quotes_gpc I apparently successfully converted the following hardcode in a WordPress functions file for an online form that returns previously entered form values....text, textarea, dropdown, and checkbox array. The following lines treat the checkbox values differently because they get put into an array according to the $META_KEY name such as 'cp_checkbox_charley' or 'cp_checkbox_help'.....any number of different names may come up. 1-- In short, wherever the $meta_key that defines a string of values contains "CP_CHECKBOX ......." THOSE VALUES WILL ALREADY BE IN AN ARRAY --- AN ARRAY OF VALUES REPRESENTING EVERY SEPARATE CHECK BOX THAT WAS SELECTED FOR THAT VALUE. THE ARRAY IS HELD IN THIS [] and 'cp_checkbox_charley[]‘ can hold as many values as are default values for that particular checkbox. 2-- And, additionally, when those checkboxes show up in a string the individual values must be IMPLODED with a comma between. 3-- And, last condition, if the isset condition for a posted checkbox is FALSE--(! isset($_POST[$meta_key])) then that can ONLY MEAN that the checkboxes have this time around been completely unchecked. According to the formula then, the $META_VALUE can only equal an empty array...represented by ''. When the tables are now updated-- even if 1, 2, 3...or more values are sitting in the 'meta'value' field from the previous saved version, i.e. "Sunday, Tuesday, Thursday, Friday" and comma limited--they must be replaced with nothing, no value...not even a "Null". This code below works -- it first makes sure that the checkboxes Exist and are NOT set...nothing selected this time....but that in expectation of changing their pre-existing values when they WERE checked in a previous save we set them specifically ready to save something in an array : // Make sure the checkbox arrays exist if (! isset($_POST['cp_checkbox_charley'])) $_POST['cp_checkbox_charley'] = array(); if (! isset($_POST['cp_checkbox_help'])) $_POST['cp_checkbox_help'] = array(); if (! isset($_POST['cp_checkbox_hello'])) $_POST['cp_checkbox_hello'] = array(); I converted those lines into this. foreach($_POST as $meta_key => $meta_value) { if(cp_str_starts_with($meta_key, 'cp_checkbox')) if (! isset($_POST[$meta_key])) { echo $_POST[$meta_key] = array(); } The following little code goes through each posted field looking for the individual strings of $meta_key associated with $meta_value and for each of them where the string starts with 'cp_checkbox' then it loops through what is left....so it returns the same names just one time of each checkbox form that begins with 'cp_checkbox' but also writes in the complete name for each $meta_key. foreach($_POST as $meta_key => $meta_value) { if(cp_str_starts_with($meta_key, 'cp_checkbox')) And here is the section that has consumed many hours because I cannot figure out how to write a loop that does the same thing....again, the code below works perfectly...but it depends on knowing the checkboxes ahead of time. I need to output a DYNAMIC LOOP using the values already detected---the checkbox names contained in $meta_keys where they begin with 'cp_checkbox'. // this code works perfectly and OVERWRITES the UNCHECKED checkboxes // now update all the custom fields foreach($_POST as $meta_key => $meta_value) { if (cp_str_starts_with($meta_key, 'cp_')) { if (cp_str_starts_with($meta_key, 'cp_checkbox_charley')) { if (isset($_POST['cp_checkbox_charley'])) $meta_value= implode(',', $_POST['cp_checkbox_charley']); else $meta_value = ''; } if (cp_str_starts_with($meta_key, 'cp_checkbox_help')) { if (isset($_POST['cp_checkbox_help'])) $meta_value = implode(',', $_POST['cp_checkbox_help']); else $meta_value = ''; } if (cp_str_starts_with($meta_key, 'cp_checkbox_hello')) if (isset($_POST['cp_checkbox_hello'])) $meta_value= implode(',', $_POST['cp_checkbox_hello']); else $meta_value = ''; } update_post_meta($post_id, $meta_key, $meta_value); } I tried the FOLLOWING...among many radically different experiments....It does not error, and saves changes to the 'cp_' custom fields, and saves the changes to the 'cp_checkbox...' fields. So, up to that point it is looping and identifying that I am using 3 checkbox forms and what the names or $meta_key values are and IMPLODING the values with commas. // now update all the custom fields foreach($_POST as $meta_key => $meta_value) { if (cp_str_starts_with($meta_key, 'cp_' && !'cp_checkbox')) { if (cp_str_starts_with($meta_key, 'cp_checkbox')) { if(! isset($_POST[$meta_key])) { $meta_value= "''"; } { $meta_value= implode(',', $_POST[$meta_key]); } } } update_post_meta($post_id, $meta_key, $meta_value); } What THE CODE ABOVE does NOT do is overwrite the unselected checkboxes....if I completely UNCHECK every checkbox in a checkbox form such as 'cp_checkbox_charley', for example, it does not replace the previous values with nothing, no value. The same previously saved values return with the same checked values as before. I cannot get this loop to look for the checkboxes that are ! isset during posting and replace the $meta_value with ''. I would appreciate the ANSWER very much!
  10. Let me try this again The following is a section of code in WordPress in a form that updates the database...the problem I am having is that it does not update different checkbox arrays, it does not wipe out the previous stored array IF those checkboxes are all unchecked. I have some hardcode that does it perfectly...but I have to make this function dynamic so that it will create the same loop once it knows what checkboxes are used in the form and it produces the names of those checkboxes stored as $meta_key Here is the dynamic loop that I created that will update the checkboxes and other custom fields just fine...whatever changes are made they are updated when the form is submitted...EXCEPT that if these checkboxes are COMPLETELY unselected...then I keep getting the previously saved array..... // update the ad and return the ad id $post_id = wp_update_post($update_ad); $substitute = array(0); if($post_id) { foreach($_POST as $meta_key => $meta_value) { if(cp_str_starts_with($meta_key, 'cp_checkbox')) if (! isset($_POST[$meta_key])) { echo $_POST[$meta_key] = array(); } } // now update all the custom fields foreach($_POST as $meta_key => $meta_value) { if (cp_str_starts_with($meta_key, 'cp_')){ if (cp_str_starts_with($meta_key, 'cp_checkbox')) { if(!isset($_POST[$meta_key])) { $meta_value= ''; } else { $meta_value= implode(',', $_POST[$meta_key]); } } } ! isset or isset is used to determine if a checkbox such as "cp_checkbox_charley" is unchecked or checked with some values being passed into the new array held in cp_checkbox_charley[] The hardcode that WORKS does this simply but in the ten-thousand different ways I have re-written and tested the code ABOVE (trying to make it Replace the code below) I cannot get the (!isset($_POST[$meta_key])) { $meta_value= ''; to do the same thing as the ELSE below where if the particular checkbox ISSET then it implodes the values....ELSE it sets the $meta_value for this iteration as NOTHING.... So, looking at the code BELOW can you tell me what I should change in the code ABOVE to make it loop through and perform the same comparison of "not set" and ""? Trying to duplicate the hardcode with the else does not work...either PHP objects strenuously with Errors or nothing happens when all checkboxes are unselected....by "nothing" I mean, I get back the same array that was last saved when it had one value or more. foreach($_POST as $meta_key => $meta_value) { if (cp_str_starts_with($meta_key, 'cp_')) { if (cp_str_starts_with($meta_key, 'cp_checkbox_charley')) { if (isset($_POST['cp_checkbox_charley'])) $meta_value= implode(',', $_POST['cp_checkbox_charley']); else $meta_value = ''; } if (cp_str_starts_with($meta_key, 'cp_checkbox_help')) { if (isset($_POST['cp_checkbox_help'])) $meta_value = implode(',', $_POST['cp_checkbox_help']); else $meta_value = ''; } if (cp_str_starts_with($meta_key, 'cp_checkbox_hello')) if (isset($_POST['cp_checkbox_hello'])) $meta_value= implode(',', $_POST['cp_checkbox_hello']); else $meta_value = ''; } update_post_meta($post_id, $meta_key, $meta_value); } Thank you very much for shedding light in darkness. I am on PHP 5.3.
  11. This function in WP for a classified ad theme needs to "empty out" a checkbox array that has already been saved with values IF this POST form is modified so that the checkboxes are now completely unchecked. I have a hard-coded series of actions that WORK....in this editing mode if various checkbox forms come back with values (that have been imploded with commas when saved) the following lines detect that these three specific checkbox forms are NOW UNCHECKED (if that is true) when the ad submit button is clicked to UPDATE the ad. // Make sure the checkbox arrays exist if (! isset($_POST['cp_checkbox_charley'])) $_POST['cp_checkbox_charley'] = array(); if (! isset($_POST['cp_checkbox_help'])) $_POST['cp_checkbox_help'] = array(); if (! isset($_POST['cp_checkbox_hello'])) $_POST['cp_checkbox_hello'] = array(); // now update all the custom fields foreach($_POST as $meta_key => $meta_value) { if (cp_str_starts_with($meta_key, 'cp_')) { if (cp_str_starts_with($meta_key, 'cp_checkbox_charley')) { if (isset($_POST['cp_checkbox_charley'])) $meta_value= implode(',', $_POST['cp_checkbox_charley']); else $meta_value = ''; } if (cp_str_starts_with($meta_key, 'cp_checkbox_help')) { if (isset($_POST['cp_checkbox_help'])) $meta_value = implode(',', $_POST['cp_checkbox_help']); else $meta_value = ''; } if (cp_str_starts_with($meta_key, 'cp_checkbox_hello')) if (isset($_POST['cp_checkbox_hello'])) $meta_value= implode(',', $_POST['cp_checkbox_hello']); else $meta_value = ''; } update_post_meta($post_id, $meta_key, $meta_value); } All well and good, except that I need to make the above code dynamic, responding to situations where the checkbox forms may have different names and instead of 3 checkboxes a variable number of checkboxes associated with this post. In the following code I have made some of the code dynamic so that it loops, finds all the $meta_key values that reflect the name of the individual checkbox forms...such as "cp_checkbox_charley"...etc....etc. And in the following code if the checkboxes are re-checked for different values the ad / post DOES store the new checkbox values in a comma delimited array. That part is successful. However, if the checkboxes are UNSELECTED now before saving, the $meta_value for each checkbox form "checkbox_charley, checkbox_help, checkbox_hello" (in this situation) is not overwritten , not updated. The form returns the previously saved array instead of an empty ' ' array. So the LOOP is not getting included that causes the $meta_value = ' '; I am hoping someone can spot what is wrong. The if (isset('cp_checkbox_name' is supposed to ELSE if that isset check is false and the checkbox is NOT set because all checkboxes in that checkbox form name have been unselected. Most ways I have tried to rewrite this give me an error on the "else". The following does not error and allows updating the checkboxes accurately. The only condition that does not work is the NOT SET condition that is supposed to assign that checkbox with an empty value. // update the ad and return the ad id $post_id = wp_update_post($update_ad); $substitute = array(0); if($post_id) { foreach($_POST as $meta_key => $meta_value) { if(cp_str_starts_with($meta_key, 'cp_checkbox')) if (! isset($_POST[$meta_key])) { echo $_POST[$meta_key] = array(); } } // now update all the custom fields foreach($_POST as $meta_key => $meta_value) { if (cp_str_starts_with($meta_key, 'cp_')) { if ((cp_str_starts_with($meta_key, 'cp_checkbox')) && (isset($_POST[$meta_key]))) { $meta_value= implode(',', $_POST[$meta_key]); } if ((cp_str_starts_with($meta_key, 'cp_checkbox')) && (! isset($_POST[$meta_key]))) { $meta_value= ''; return $meta_value; } } update_post_meta($post_id, $meta_key, $meta_value); } $errmsg = '<div class="box-yellow"><b>' . __('Your ad has been successfully updated.','cp') . '</b> <a href="' . CP_DASHBOARD_URL . '">' . __('Return to my dashboard','cp') . '</a></div>'; } else { // the ad wasn't updated so throw an error $errmsg = '<div class="box-red"><b>' . __('There was an error trying to update your ad.','cp') . '</b></div>'; } return $errmsg; }
  12. colmustard, you say... "interesting, I have seen people using wordpress as a standalone cms for non-blog websites, but I've just never seen the practicality in it as you can accomplish the same effects using another cms or framework that is built specifically for the functionality you are trying to create in a much more time efficient manner." Installing WP is extremely easy and as soon as it is up you can start writing pages and then specify which one is the index page, and then generate post afer post or page after page. Indicate which pages are linked to which pages. Do an entire site by simply selecting that these are Pages and not posts. Indicate which pages are related to each other by categories you make up,...whatever. I just do not see what "practicality" you can be talking about. I have just looked at mod x and ez publish. Despite the name ez publish looks like it is is a long learning curve. They talk about components and cool stuff but not once anywhere on the website do they actually get "user-friendly" the way WordPress does. It is definitely a geek-techno website that is written by engineers. Mod X looks cool and more upfront user-friendly but YOU, colmustard, say you are using mod x AND Wordpress to get the "functionality" you are trying to create "in a more time efficient manner", but, honestly, you are not even using WordPress's everyday functions. Your site is suffering some huge issues so I don't think you have enough of a grasp to even compare "usability" or "functionality" between CMS programs, complex or simple. If you want to talk about "usability"....everything, and I mean everything is EASILY achieved using WordPress.
  13. wildteen88 and DavidAM have been of enormous help so far and I must again extend my grateful thanks. Now I have discovered the rest of the hard-code in the same Wordpress example that I must replace with a dynamic looping equivalent. This function takes custom fields that have already been entered into a form and passes them along to another page so that the user can revise or modify the original values in the form that the user filled out. The complication in this has been that it used checkboxes whose final arrays of values have to be "exposed" and imploded with commas before being saved to the database. Then when retrieved just those checkbox fields with comma delimited values have to be exploded and put into lists separate from other custom fields which only store a simple string. The other factor is that the editing form must detect if duplicated checkboxes in the Edit form have been completely UNselected this time before saving. If this time checkboxes are completely unselected then on UPDATE the old array must be emptied out when saved to the database this time. Here is the version that WORKS...with Hardcode for 3 checkboxes with known names. But, I want to convert any code that refers to 'cp_checkbox.....' with a dynamic loop that does the same thing. And it will then depend on knowing which checkboxes are being called and returned to this form for editing. This function is called on the tpl-edit-item.page as // update the ad content $the_msg .= cp_update_listing(); and now, without further ado, ladies and gentlemen, the function in question !! // // saves the ad on the tpl-edit-item.php page template function cp_update_listing() { global $wpdb; // check to see if html is allowed if (get_option('cp_allow_html') != 'yes') $post_content = cp_filter($_POST['post_content']); else $post_content = $_POST['post_content']; // keep only numeric, commas or decimal values if (!empty($_POST['cp_price'])) $_POST['cp_price'] = cp_clean_price($_POST['cp_price']); // keep only values and insert/strip commas if needed and put into an array if (!empty($_POST['tags_input'])) $_POST['tags_input'] = cp_clean_tags($_POST['tags_input']); $new_tags = explode(',', $_POST['tags_input']); // put all the ad elements into an array // these are the minimum required fields for WP (except tags) $update_ad = array(); $update_ad['ID'] = trim($_POST['ad_id']); $update_ad['post_title'] = cp_filter($_POST['post_title']); $update_ad['post_content'] = trim($post_content); $update_ad['tags_input'] = $new_tags; // array //$update_ad['post_category'] = array((int)cp_filter($_POST['cat'])); // maybe use later if we decide to let users change categories //print_r($update_ad).' <- new ad array<br>'; // for debugging // update the ad and return the ad id $post_id = wp_update_post($update_ad); $substitute = array(0); if($post_id) { // Make sure the checkbox arrays exist // these lines must be replaced with dynamic equivalent !!! if (! isset($_POST['cp_checkbox_charley'])) $_POST['cp_checkbox_charley'] = array(); if (! isset($_POST['cp_checkbox_help'])) $_POST['cp_checkbox_help'] = array(); if (! isset($_POST['cp_checkbox_hello'])) $_POST['cp_checkbox_hello'] = array(); // here is a function I wrote that seems to create the same thing as above // it returns the three checkbox names when I do a print command // cp_checkbox_charley // cp_checkbox_help // cp_checkbox_hello // I would like someone to comment on this if it makes sense in a strict PHP sense of logic // foreach($_POST as $meta_key=> $meta_value) { // if (cp_str_starts_with($meta_key, 'cp_checkbox')) { // if (! isset($_POST[$meta_key])) $_POST[$meta_key] = array(); // } // now comes the next hard code that I must duplicate in a loop // I thought I would build on what I had done above // and make it loop through for each $meta_key that my condition above creates // and re-create the same essential statements and actions // however, different ways I have tried this don't seem to loop the $meta_key= '' if one of those checkboxes // in completely unselected--after update the checkboxes still retain their original values // so instead of showing you my code that fails to update unchecked checkboxes I will leave the WORKING FUNCTION // that I must recreate in a dynamic loop version where the code will not hardcode the cp_checkbox names // now update all the custom fields foreach($_POST as $meta_key => $meta_value) { if (cp_str_starts_with($meta_key, 'cp_')) { if (cp_str_starts_with($meta_key, 'cp_checkbox_charley')) { if (isset($_POST['cp_checkbox_charley'])) $meta_value= implode(',', $_POST['cp_checkbox_charley']); else $meta_value = ''; } if (cp_str_starts_with($meta_key, 'cp_checkbox_help')) { if (isset($_POST['cp_checkbox_help'])) $meta_value = implode(',', $_POST['cp_checkbox_help']); else $meta_value = ''; } if (cp_str_starts_with($meta_key, 'cp_checkbox_hello')) if (isset($_POST['cp_checkbox_hello'])) $meta_value= implode(',', $_POST['cp_checkbox_hello']); else $meta_value = ''; } update_post_meta($post_id, $meta_key, $meta_value); } $errmsg = '<div class="box-yellow"><b>' . __('Your ad has been successfully updated.','cp') . '</b> <a href="' . CP_DASHBOARD_URL . '">' . __('Return to my dashboard','cp') . '</a></div>'; } else { // the ad wasn't updated so throw an error $errmsg = '<div class="box-red"><b>' . __('There was an error trying to update your ad.','cp') . '</b></div>'; } return $errmsg; } So, again the code I need to make dynamic so that if I use 5 or 6 checkboxes with different names and values or just 1 or 2...the code will loop and handle it....... // / / now update all the custom fields foreach($_POST as $meta_key => $meta_value) { if (cp_str_starts_with($meta_key, 'cp_')) { if (cp_str_starts_with($meta_key, 'cp_checkbox_charley')) { if (isset($_POST['cp_checkbox_charley'])) $meta_value= implode(',', $_POST['cp_checkbox_charley']); else $meta_value = ''; } if (cp_str_starts_with($meta_key, 'cp_checkbox_help')) { if (isset($_POST['cp_checkbox_help'])) $meta_value = implode(',', $_POST['cp_checkbox_help']); else $meta_value = ''; } if (cp_str_starts_with($meta_key, 'cp_checkbox_hello')) if (isset($_POST['cp_checkbox_hello'])) $meta_value= implode(',', $_POST['cp_checkbox_hello']); else $meta_value = ''; } update_post_meta($post_id, $meta_key, $meta_value); } [ THANK YOU VERY MUCH if you can HELP.
  14. Thanks so MUCH! I am reading your post. You should write some Tutorials!! I have read a lot of them but they usually wind up with examples that JUST MISS "my" situation. I am running PHP 5+ It must be a pain trying to write public software with "fall back" options in case the PHP is an earlier version. It was weird watching the IMPLODE happening, seeing it, but not being able to Update it. Thank you for your thoroughness and willingness to wade through all that!
  15. You said "Functions do not have access to the variables that are defined OUTSIDE the function." THAT is an important point. I thought that since I could SEE the other $postvals being stored in the lines above this function that by following sequentially those stored $postvals already stored in the session with my function and naming $postvals AGAIN in my function that I was lining them up for INCLUSION on the update. PASSING the values THROUGH this function was a big concept to learn! THANK YOU AGAIN!
  16. WOWWWW!!!! THAT WAS IT! It works, it works!!! Your addition of function cp_show_form_checkboxes($catid, &$postvals) { was CRUCIAL! What an AMAZING difference THAT made so the &$postvals PASSES the other $postvals THROUGH? I thought that the postvals were being assembled in little modules along the way waiting for the checkbox additions. What exactly did your change do in the flow? Thanks a MILLION! DAVID---YOU the man! And thank you again wildteen88!
  17. Hello David, thanks so much for taking another look! There are several files that contain functions that are referred to but the image loader always works perfectly. And the full Image handler script is not included here! It is in a separate file. I am going to try right now to see what happens with your suggestions!
  18. Radar, you may be correct....IF you are absolutely a master at PHP. When you consider that the people who code and have coded Wordpress over the years ARE PHP masters and they ARE STILL LEARNING every single day it makes them the Masters of the Masters. If you are at the level that you custom code each function in a client's website does that mean that you do not borrow or are not inspired by thousands of other coder's examples posted on the internet? Each PHP expert has become an expert in a FEW issues above the normal level of mastery. These are the guys who other experts ask for help from because PHP is a HUGE HUGE code base of expressions and functions and NOBODY is equally expert on the multitudinous ways to solve the same problem. As any PHP forum will show. The thing I began to appreciate about Wordpress is that thousands of people have contributed to it over years, not just ADDING functions, but STREAMLINING functions, as well. You get the benefit of a huge, huge expert catalogue of ways to solve not just PHP problems but CSS and Javascript issues. About a year and a half ago, after a year of skepticism, I gained enough experience to understand how to use and modify Wordpress. And then I saw that it quickly gave me everything I needed for any website. And since I don't want my Wordpress websites to LOOK LIKE WORDPRESS I discovered how to use Wordpress as a very competent and "unlimited" CMS. And to radically customize templates to take out the appearance of a blog-based site. When I do a Wordpress site I clean out out the functions that I don't need and that I am pretty confident will not be needed by some essential plugin. And I rewrite the plugins to accomplish more specifically what I need. And then I keep the plugins to a minimum. I think you would be hard-pressed as a coder to offer your clients all the capability of Wordpress.
  19. OOOPS, I see that my assumption was wrong.... the () WAS CAUSED BY THE PRINT FUNCTION! MY MISTAKE. But evidently my assumption is correct that what I need is the equivalent of the hardcode.... separate postvals for each checkbox that hold the result of the IMPLODE and to not get all of the separate checkboxes then PREMATURELY Enclosed in one big array holding all the newly imploded checkbox values.
  20. Hello David, Here is what I think is critically DIFFERENT about your method from the Hardcode example below which WORKS $postvals['cp_checkbox_charley']= implode(',', $_POST['cp_checkbox_charley']); $postvals['cp_checkbox_help']= implode(',', $_POST['cp_checkbox_help']); $postvals['cp_checkbox_hello']= implode(',', $_POST['cp_checkbox_hello']); //these are the two lines that do the final wrap up and save to the database //and note that these are meant to be values distinguished from the regular Wordpress save of values. $option_name = 'cp_'.$postvals['oid']; update_option($option_name, $postvals); In your function I notice you do the update while distinguishing the checkbox values as $postVals with a capital 'V' However, in the hardcode above the $postvals['cp_checkbox_charley'] STAYS like that -- IMPLODED with commas. It sits there as a static value now. it does not get wrapped with another ARRAY. In your function, apparently once all the checkboxes have been imploded then they get saved all together as one more unnamed "bundled" Array. This Array now HIDES my imploded checkboxes rather than exposing them to being saved as separate checkboxes.... Once each checkbox is imploded then it should stay separate, just as the hardcode example does. Nothing happens to each checkbox until it is assembled for the $postvals array for updating....so the checkboxes arrive ready to be put into their appropriate fields. The function you have given me stuffs all the imploded checkboxes back into an anonymous array and THEN into $postvals. Unless I am seeing this wrong.
  21. Hello David, thanks so much for sticking with me this far! I STILL DO NOT GET what I must have, the saving of the checkbox arrays in the final Post / Ad. Here is the read out from the page that Displays what fields have been filled in and what individual checkbox forms have been checked. The print_r just after the $postvals have been looped and the implosion takes place shows that this IS HAPPENING...these are TEST NAMES until I can finally get this working.... Array ( [cp_checkbox_help] => Wednesday, Thursday, Saturday [cp_checkbox_charley] => Cook, Watchman [cp_checkbox_hello] => Pet Friendly: Small dogs allowed with an additional pet deposit,Smoking Allowed: Outdoor areas only,No smoking at all ) But I notice that the each checkbox, while being imploded is encapsulated in another unnamed Array ()....is this the problem? Don't I have to get rid of the Array () that HOLDS the imploded checkboxes? This function sticks this all back into a holder Array and it is the Array that keeps getting saved, hiding the Checkbox comma delimited [] I notice that you although the function I gave you refers to $postvals in the last foreach loop to update that you deliberately use $postVals. These two lines are the last update lines that seem to take all the postvals put into the $postvals array thus far and update the database when the form is posted. $option_name = 'cp_'.$postvals['oid']; update_option($option_name, $postvals); I know that what I must do is make sure that in the sequence of things that the last update action does not go back and Re-UPDATE my custom fields checkbox fields with Array or null just after they have been saved correctly with commas separating values. So, I have experimented over and over with different way to write this and NONE work, including your function...the Ad gets saved incorrectly. Showing the Title and Price and all those fields fine, but blank Checkboxes...the checkbox fields-- $meta_values, just show Array. So here is what I have, the complete page,including your print_r command. <?php /** * This is step 2 of 3 for the ad submission form * * here we are processing the images and gathering all the post values. * using sessions would be the optimal way but WP doesn't play nice so instead * we take all the form post values and put them into an associative array * and then store it in the wp_options table as a serialized array. essentially * we are using the wp_options table as our session holder and can access * the keys and values later and process the ad in step 3 * */ global $userdata; global $wpdb; // check to see if there are images included // then valid the image extensions if (!empty($_FILES['image'])) $error_msg = cp_validate_image(); // images are valid if(!$error_msg) { // create the array that will hold all the post values $postvals = array(); // upload the images and put into the new ad array if (!empty($_FILES['image'])) $postvals = cp_process_new_image(); // keep only numeric, commas or decimal values if (!empty($_POST['cp_price'])) $postvals['cp_price'] = cp_clean_price($_POST['cp_price']); // keep only values and insert/strip commas if needed if (!empty($_POST['tags_input'])) $postvals['tags_input'] = cp_clean_tags($_POST['tags_input']); // put all the posted form values into session vars foreach($_POST as $key => $value) $postvals[$key] = cp_clean($value); // store the user IP address, ID for later $postvals['cp_sys_userIP'] = cp_getIP(); $postvals['user_id'] = $current_user->ID; // see if the featured ad checkbox has been checked if ($_POST['featured_ad']) { $postvals['featured_ad'] = $_POST['featured_ad']; // get the featured ad price into the array $postvals['cp_sys_feat_price'] = get_option('cp_sys_feat_price'); } // calculate the ad listing fee and put into a variable if(get_option('cp_charge_ads') == 'yes') $postvals['cp_sys_ad_listing_fee'] = cp_ad_listing_fee($_POST['cat'], $_POST['ad_pack_id'], $_POST['cp_price']); // check to prevent "Notice: Undefined index:" on php strict error checking. get ad pack id and lookup length $adpackid = ''; if(isset($_POST['ad_pack_id'])) { $adpackid = $_POST['ad_pack_id']; $postvals['pack_duration'] = cp_get_ad_pack_length($adpackid); } // calculate the total cost of the ad $postvals['cp_sys_total_ad_cost'] = cp_calc_ad_cost($_POST['cat'], $adpackid, $postvals['cp_sys_feat_price'], $_POST['cp_price']); // Debugging section //echo '$_POST ATTACHMENT<br/>'; //print_r($postvals['attachment']); //echo '$_POST PRINT<br/>'; //print_r($_POST); //echo '<br/><br/>$postvals PRINT<br/>'; //print_r($postvals); // now put the array containing all the post values into the database // instead of passing hidden values which are easy to hack and so we // can also retrieve it on the next step $catid = ($_POST['cat']); $catid = ($_POST['cat']); // queries the db for the custom ad form based on the cat id and names any checkboxes to be included function cp_show_form_checkboxes($catid) { global $wpdb; $fid = ''; //$catid = '129'; // used for testing // get the category ids from all the form_cats fields. // they are stored in a serialized array which is why // we are doing a separate select. If the form is not // active, then don't return any cats. $sql = "SELECT ID, form_cats " . "FROM ". $wpdb->prefix . "cp_ad_forms " . "WHERE form_status = 'active'"; $results = $wpdb->get_results($sql); if($results) { // now loop through the recordset foreach ($results as $result) { // put the form_cats into an array $catarray = unserialize($result->form_cats); // now search the array for the $catid which was passed in via the cat drop-down if (in_array($catid,$catarray)) { // when there's a catid match, grab the form id $fid = $result->ID; // put the form id into the post array for step2 $_POST['fid'] = $fid; } } // now we should have the formid so show the form layout based on the category selected $sql = $wpdb->prepare("SELECT f.field_label, f.field_name, f.field_type, f.field_values, f.field_perm, m.meta_id, m.field_pos, m.field_req, m.form_id " . "FROM ". $wpdb->prefix . "cp_ad_fields f " . "INNER JOIN ". $wpdb->prefix . "cp_ad_meta m " . "ON f.field_id = m.field_id " . "WHERE f.field_type = 'checkbox' " . "AND m.form_id = '$fid' " . "ORDER BY m.field_pos asc"); $results = $wpdb->get_results($sql); if($results) { foreach ($results as $result): // now grab all ad fields and print out the field label and value $postvals[$result->field_name]= implode(',', $_POST[$result->field_name]); endforeach; print_r($postvals); return $postvals; // Return the values so we can process them } else { echo __('No checkbox details found.', 'cp'); return array(); // Nothing found so return empty array } } else { return array(); // Nothing found so return empty array } } $catid = ($_POST['cat']); $postVals = cp_show_form_checkboxes($catid); foreach ($postVals as $key => $value) { update_option($key, $value); } //these are the lines below that wrap things all up for the submit form // the oid is the session and the cp_is to distinguish all these values from regular Wordpress $option_name = 'cp_'.$postvals['oid']; update_option($option_name, $postvals); ?> <div id="step2"></div> <h2 class="dotted"><?php _e('Review Your Listing','cp');?></h2> <img src="<?php bloginfo('template_url'); ?>/images/step2.gif" alt="" class="stepimg" /> <?php // this is where the completed form first comes back to look at while in the add new ad process ?> <form name="mainform" id="mainform" class="form_step" action="" method="post" enctype="multipart/form-data"> <ul> <?php // pass in the form post array and show the ad summary based on the formid echo cp_show_review($postvals); // debugging info // debugging info //echo get_option('cp_price_scheme') .'<-- pricing scheme<br/>'; //echo $postvals['cat'] .'<-- catid<br/>'; //echo get_option('cp_cat_price_'.$postvals['cat']) .'<-- cat price<br/>'; //echo $postvals['user_id'] .'<-- userid<br/>'; //echo get_option('cp_price_per_ad') .'<-- listing cost<br/>'; //echo get_option('cp_curr_symbol_pos') .'<-- currency position<br/>'; ?> <li> <?php if($postvals['cp_sys_total_ad_cost'] > 0) : ?> <label><?php _e('Payment Method','cp'); ?>:</label> <select name="cp_payment_method" class="dropdownlist required"> <?php if(get_option('cp_enable_paypal') == 'yes') { ?><option value="paypal"><?php echo _e('PayPal', 'cp') ?></option><?php } ?> <?php if(get_option('cp_enable_gcheckout') == 'yes') { ?><option value="gcheckout"><?php echo _e('Google Checkout', 'cp') ?></option><?php } ?> <?php if(get_option('cp_enable_2checkout') == 'yes') { ?><option value="2checkout"><?php echo _e('2Checkout', 'cp') ?></option><?php } ?> <?php if(get_option('cp_enable_authorize') == 'yes') { ?><option value="authorize"><?php echo _e('Authorize.net', 'cp') ?></option><?php } ?> <?php if(get_option('cp_enable_chronopay') == 'yes') { ?><option value="chronopay"><?php echo _e('Chronopay', 'cp') ?></option><?php } ?> <?php if(get_option('cp_enable_mbookers') == 'yes') { ?><option value="mbookers"><?php echo _e('MoneyBookers', 'cp') ?></option><?php } ?> </select> <?php endif; ?> <div class="clr"></div> </li> </ul> <div class="pad10"></div> <div class="license"> <?php echo get_option('cp_ads_tou_msg'); ?> </div> <div class="clr"></div> <p class="light"><?php _e('By clicking the proceed button below, you agree to our terms and conditions.','cp'); ?> <br/> <?php _e('Your IP address has been logged for security purposes:','cp'); ?> <?php echo $postvals['cp_sys_userIP']; ?></p> <p class="btn2"> <input type="button" name="goback" class="btn_orange" value="<?php _e('Go back','cp') ?>" onclick="history.back()" /> <input type="submit" name="step2" id="step2" class="btn_orange" value="<?php _e('Proceed ','cp'); ?> ››" /> </p> <input type="hidden" id="oid" name="oid" value="<?php echo $postvals['oid']; ?>" /> </form> <div class="clear"></div> <?php } else { ?> <h2 class="dotted"><?php _e('An Error Has Occurred','cp') ?></h2> <div class="thankyou"> <p><?php echo cp_error_msg($error_msg); ?></p> <input type="button" name="goback" class="btn_orange" value="‹‹ <?php _e('Go Back','cp') ?>" onclick="history.back()" /> </div> <?php } ?> Thanks so much, David, for helping me see the light at the end of a very long dark tunnel! David in Vienna
  22. I am completely through with this...it is heading towards 5 am and it has not worked one single time--- THE ARRAY STAYS AN ARRAY AND NEVER EVER GETS CONVERTED. I SEE THE VALUES REFLECTED ON THE REVIEW PAGE FOR EACH CHECKBOX SELECTED, THE REVIEW PAGE RETURNS A LIST OF THE VALUES SELECTED FOR MY THREE CHECKBOXES. WHEN I SUBMIT AND UPDATE EVERY OTHER VALUE SAVES. THE CHECKBOX ARRAYS DO NOT GET CONVERTED AND THE AD DOES NOT SHOW THEIR VALUES. HERE IS THE ENTIRE FUNCTION THAT IS MEANT TO REPLACE THE HARD CODE (WHICH WORKS PERFECTLY) $catid = ($_POST['cat']); // queries the db for the custom ad form based on the cat id and shows any checkboxes function cp_show_form_checkboxes($catid) { global $wpdb; $fid = ''; //$catid = '129'; // used for testing // get the category ids from all the form_cats fields. // they are stored in a serialized array which is why // we are doing a separate select. If the form is not // active, then don't return any cats. $sql = "SELECT ID, form_cats " . "FROM ". $wpdb->prefix . "cp_ad_forms " . "WHERE form_status = 'active'"; $results = $wpdb->get_results($sql); if($results) { // now loop through the recordset foreach ($results as $result) { // put the form_cats into an array $catarray = unserialize($result->form_cats); // now search the array for the $catid which was passed in via the cat drop-down if (in_array($catid,$catarray)) { // when there's a catid match, grab the form id $fid = $result->ID; // put the form id into the post array for step2 $_POST['fid'] = $fid; } } // now we should have the formid so show the form layout based on the category selected $sql = $wpdb->prepare("SELECT f.field_label, f.field_name, f.field_type, f.field_values, f.field_perm, m.meta_id, m.field_pos, m.field_req, m.form_id " . "FROM ". $wpdb->prefix . "cp_ad_fields f " . "INNER JOIN ". $wpdb->prefix . "cp_ad_meta m " . "ON f.field_id = m.field_id " . "WHERE f.field_type = 'checkbox' " . "AND m.form_id = '$fid' " . "ORDER BY m.field_pos asc"); $results = $wpdb->get_results($sql); if($results) { foreach ($results as $result): // now grab all ad fields and print out the field label and value $postvals[$result->field_name]= implode(',', $_POST[$result->field_name]); endforeach; } else { echo __('No checkbox details found.', 'cp'); } } } // RIGHT HERE I EVEN REFERRED IMMEDIATELY TO FUNCTION TO SEE IF THIS WOULD MAKE A DIFFERENCE // WITH OR WITHOUT THIS LINE BELOW IT MAKES NO DIFFERENCE // THERE ARE NO ERRORS, JUST NO IMPLODED ARRAYS cp_show_form_checkboxes($catid); $option_name = 'cp_'.$postvals['oid']; update_option($option_name, $postvals); ?> I am wondering if here-- foreach ($results as $result): // now grab all ad fields and print out the field label and value $postvals[$result->field_name]= implode(',', $_POST[$result->field_name]); endforeach; if for some reason the $result->field_name doesn't stay the same value all the way through the line as if it becomes $postvals[cp_checkbox_1]= implode(',', $_POST[cp_chckbox_2]); but it seems like it would show an error if that were the case.
  23. Hello David, thanks so much for taking pity on me There must be something different between your version of PHP and what my server at 1and1.com is running on. Your code below is EXACTLY what I had written for myself over and over but enclosing the ' single quote in the double quotes did not work. Never. But I tried, which is why I have kept coming back to the forum. foreach ($results as $result) { // now grab all ad fields and print out the field label and value $postvals["'" . $result->field_name . "'"]= implode(',', $_POST[$result->field_name]); } You are right, now, when I remove the ' ' from the hard code inside the array brackets the implode with commas works and saves the array that way. Sometimes it seems as if this server is teasing with me. So here is the whole function that I have put into the same place in the code JUST before Postvals are updated where the hardcode was $catid = ($_POST['cat']); // queries the db for the custom ad form based on the cat id and shows any checkboxes function cp_show_form_checkboxes($catid) { global $wpdb; $fid = ''; // call tinymce init code if html is enabled if (get_option('cp_allow_html') == 'yes') cp_tinymce($width=540, $height=200); //$catid = '129'; // used for testing // get the category ids from all the form_cats fields. // they are stored in a serialized array which is why // we are doing a separate select. If the form is not // active, then don't return any cats. $sql = "SELECT ID, form_cats " . "FROM ". $wpdb->prefix . "cp_ad_forms " . "WHERE form_status = 'active'"; $results = $wpdb->get_results($sql); if($results) { // now loop through the recordset foreach ($results as $result) { // put the form_cats into an array $catarray = unserialize($result->form_cats); // now search the array for the $catid which was passed in via the cat drop-down if (in_array($catid,$catarray)) { // when there's a catid match, grab the form id $fid = $result->ID; // put the form id into the post array for step2 $_POST['fid'] = $fid; } } // now we should have the formid so show the form layout based on the category selected $sql = $wpdb->prepare("SELECT f.field_label, f.field_name, f.field_type, f.field_values, f.field_perm, m.meta_id, m.field_pos, m.field_req, m.form_id " . "FROM ". $wpdb->prefix . "cp_ad_fields f " . "INNER JOIN ". $wpdb->prefix . "cp_ad_meta m " . "ON f.field_id = m.field_id " . "WHERE f.field_type = 'checkbox' " . "AND m.form_id = '$fid' " . "ORDER BY m.field_pos asc"); $results = $wpdb->get_results($sql); if($results) { foreach ($results as $result): // now grab all the field names and loop through them $postvals[$result->field_name]= implode(',', $_POST[$result->field_name]); endforeach; } else { echo __('No checkbox details found.', 'cp'); } } } And NOW when I try to test it, when I submit an ad it tells me that my session has expired or that I am trying to submit a duplicate ad....even though I have logged out and started a new admin session. At any rate, there's the whole function that is supposed to loop through the cp_checkbox_this and cp_checkbox_that and implode the array with commas just as the code did. It has been reliably giving me back a cp_checkbox_charley & cp_checkbox_help & etc for each loop of $result->field_name. DO I NEED TO SPECIFY A FINAL RETURN OR SOMETHING AT THE END TO MAKE THIS RESPOND?
  24. Will any of these things help me to change the output so when $result->field_name is looped that it keeps outputting 'cp_checkbox_blah', 'cp_checkbox_doubleblah' even when the value is placed inside an associative array that matches this example $postvals['cp_checkbox_blah']= implode(',', $_POST['cp_checkbox_blah']); ?? If you are just joining me the ' single quotes ' have to be inside the array brackets. preg_ filter preg_ grep preg_ last_ error preg_ match_ all preg_ match preg_ quote preg_ replace_ callback preg_ replace preg_ split
  25. Here's latest thing I tried...using trim and join to try to place ' ' single quotes around each returned value BUT, the blankety-blank ' single quote cannot be put there instead of a comma....error, error.... if($results) { foreach ($results as $result): // spit out the array and separate each value with a comma $allcats = trim(join(',', $result->field_name)); // this refuses to work as $allcats = trim(join(''', $result->field_name)); // supposedly this uncommented function above puts a COMMA on BOTH SIDES of the //output value from $result->field_name but that does me no good...I still need the // &%&! single quote ' mark on both sides, not a comma! $postvals[$allcats]= implode(',', $_POST[$allcats]); endforeach; } else { echo __('No checkbox details found.', 'cp'); } } }
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.