1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Please Help Me With: Cannot Modify Header Error

Discussion in 'HTML & Website Design' started by locals, Nov 14, 2015.

  1. ketting00

    ketting00 Well-Known Member

    Messages:
    772
    Likes Received:
    27
    Best Answers:
    3
    Trophy Points:
    128
    #21
    Try this.
    
    <input
        type="checkbox"
        name="job-categories[<?php echo $i; ?>]"
        value="<?php echo $redux_demo['resume-industries'][$i]; ?>"
        style="float: left; width: auto;"
        <?php if(!empty($user_job_categories)) { if (in_array($redux_demo['resume-industries'][$i], $user_job_categories[0])) { ?>
            checked="checked"
       <?php } } ?>
    />
    <?php echo $redux_demo['resume-industries'][$i]; ?>
    
    Code (markup):
    Your code is a mess.
     
    ketting00, Nov 18, 2015 IP
    locals likes this.
  2. locals

    locals Well-Known Member

    Messages:
    1,677
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    153
    #22
    it didn't quite work, I am using this so far

    
    <input
    type="hidden"', (
    !empty($user_job_categories) &&
    in_array($redux_demo['resume-industries'][$i], $user_job_categories[0]) ?
    ' checked' : ''
    ), '
    name="job-categories[', $i, ']"
    id="jobCategories_', $i, '"
    >
    
    
    
    
    
    <input type="checkbox" name="job-categories[<?php echo $i; ?>]" value="<?php echo $redux_demo['resume-industries'][$i]; ?>" style="float: left; width: auto;" <?php if(!empty($user_job_categories)) { if (in_array($redux_demo['resume-industries'][$i], $user_job_categories[0])) { ?> checked="checked" <?php } } ?> ><?php echo $redux_demo['resume-industries'][$i]; ?>
    
    
    
    Code (markup):
     
    Last edited: Nov 19, 2015
    locals, Nov 19, 2015 IP
  3. ketting00

    ketting00 Well-Known Member

    Messages:
    772
    Likes Received:
    27
    Best Answers:
    3
    Trophy Points:
    128
    #23
    I see you posted in another thread that you can get it done. I'm glad about that.

    Don't do it that that way if you have no idea know what you are doing. Those codes make a novice confused. DeathShadow knows exactly what he is doing. He can do that shorthand ifelse trick. I'll do something like below before I jump to something like that.
    
    <?php
        if(!empty($user_job_categories)) {
            if (in_array($redux_demo['resume-industries'][$i], $user_job_categories[0])) {
    ?>
                <input
                    type="checkbox"
                    name="job-categories[<?php echo $i; ?>]"
                    value="<?php echo $redux_demo['resume-industries'][$i]; ?>"
                    style="float: left; width: auto;"
                    checked="checked"
                />
    <?php
            } else {
    ?>
                <input
                    type="checkbox"
                    name="job-categories[<?php echo $i; ?>]"
                    value="<?php echo $redux_demo['resume-industries'][$i]; ?>"
                    style="float: left; width: auto;"
                />
    <?php
            }
        } else {
    ?>
        ....... // do something if $user_job_categories does not exists or empty
    <?php } ?>
    
    Code (markup):
    Like that you would have an idea which part is executed.

    I guess the author unnecessary complicating things up. Why he checks if an array exists and there's a specific value in the array. And it was in a loop :(

    This can be done in much more simple fashion.

    Note that I'm a fan of HTML5 I will prefer self closing tag then 4.0 style.
     
    Last edited: Nov 19, 2015
    ketting00, Nov 19, 2015 IP
  4. deathshadow

    deathshadow Acclaimed Member

    Messages:
    9,732
    Likes Received:
    1,998
    Best Answers:
    253
    Trophy Points:
    515
    #24
    While I would probably punch someone in the face before allowing the same markup to be generated twice, much less the ENDLESS STUPID MALFING HALFWIT DUMBASS PHP SHORTTAGS!!!

    Not a fan...

    Seriously, I still say <?php ?> needs to be stricken from PHP entirely. It just teaches sloppy coding habits and makes the logic WAY harder to follow for NO good reason.

    I mean seriously, the only difference between the two is the checked attribute, so you're going to piss out twice the code for ONE attribute?

    ... and of course again, that STUPID MALFING style attribute that has NO damned business in the markup. But again, it's turdpress so garbage like that is pretty much the order of the day. Seriously, how ****ing ignorant do you have to be to use that garbage by choice?
     
    deathshadow, Nov 19, 2015 IP
  5. locals

    locals Well-Known Member

    Messages:
    1,677
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    153
    #25
    LMAO - well it didn't work anyways... I do not know what will work. So I have just turned the area into an advertisement block :D

    I used this code from ketting, but I get the "else" value returned

    // do something if $user_job_categories does not exists or empty .......


     
    Last edited by a moderator: Aug 9, 2017
    locals, Nov 19, 2015 IP
  6. ketting00

    ketting00 Well-Known Member

    Messages:
    772
    Likes Received:
    27
    Best Answers:
    3
    Trophy Points:
    128
    #26
    Yep, stupid but you start learning. Nothing perfect.

    @locals,
    You got that because $user_job_categories is empty, which causes the error in the first place.

    Now that you can improve your code accordingly. Sorry, I don't have time to do it right now. Other people may offer help.
     
    Last edited: Nov 19, 2015
    ketting00, Nov 19, 2015 IP
  7. deathshadow

    deathshadow Acclaimed Member

    Messages:
    9,732
    Likes Received:
    1,998
    Best Answers:
    253
    Trophy Points:
    515
    #27
    Which I think you just hit that nail we've all been blindly flailing at... which probably means a few lines up that this:
    $user_job_categories = get_user_meta( $td_user_id, 'user_job_categories_subcriptions' );
    Code (markup):
    Is failing. How/why it's failing might be better asked of someone who knows Wordpress guts... but, if we look at the documentation for that function:
    https://codex.wordpress.org/Function_Reference/get_user_meta

    It takes THREE parameters... and it only returns an array if the last parameter is FALSE... As such changing that line to this:

    $user_job_categories = get_user_meta( $td_user_id, 'user_job_categories_subcriptions', false );
    Code (markup):
    May in fact be what it should be.

    As I think I mentioned somewhere, I would do:

    $user_job_categories = get_user_meta( $td_user_id, 'user_job_categories_subcriptions', false );
    echo '<pre>', print_r($user_job_categories), '</pre>';
    Code (markup):
    Trying it with both true and false to see what it returns. THOUGH, I'm pretty sure that with the default state of true it's returning a string and not an array of all categories they are a member of; or at least that's how the WP docs read. As such you are getting a string of the FIRST category as a result with the default state of true, and not the whole list. Try it with the false first, WITHOUT the [0] part in the query. "user-job-locations" in the same file may have that same flaw of only pulling the first of many possible values, and that could be part of what's sending it tits up...

    THOUGH, are you sure that's even a valid index into the user meta?
     
    deathshadow, Nov 19, 2015 IP
  8. locals

    locals Well-Known Member

    Messages:
    1,677
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    153
    #28
    I will probably use this listing script on another one of my sites, because the theme and layout look really good and it converts very well when viewing on a mobile phone... But I have changed to much of the files in order to apply this code to see if it will work. I will however apply it once I use the theme on another domain.

    I changed the area into an advertising area in the theme and it is not displaying any part of that code anymore which is why I can not tell if it will work or not, but I will revisit this thread when I re install the theme again.

    Thanks again for everyones continued effort in assisting me with this.
     
    locals, Nov 20, 2015 IP