Programmed Under The Influence
Posting checkbox values with PHP and jQuery

For some time I had trouble figuring out how to post checkbox results using jQuery’s $.post function after submitting a form. I searched many different sites finding pieces of the a solution that would fit my needs.
Anyway here’s what I got:

1) Let’s create a simple form.

    <form id="my_form" onsubmit="return processForm()">
        1) <input type="checkbox" class="option" name="options[]" value="1" /><br />
        2) <input type="checkbox" class="option" name="options[]" value="2" /><br />
        3) <input type="checkbox" class="option" name="options[]" value="3" /><br />
        <input type="submit" value="Submit" />
    </form>

2) Create the javascript to handle the form submission.

    function processForm() {
        var options = $('#my_form :input.option');
        var option_array = new Array();
        
        $.each(options, function(index, element) {
            if ($(element).is(':checked')) {
                option_array.push($(element).val());
            }
    
        // Post options to action file
        $.post('/your/path/to/action/file.php', {'options[]': option_array});
        
        return false;
    }

3) Handle the form submission using PHP.

    <?php
        foreach ($_POST['options'] as $option) {
            /* Do whatever you want with your options here. */
        }
        
        // Or you can just print the results to the screen for test purposes
        print_r($_POST);
        exit;
    ?>
Updating your Jaiku status revisited

After failing miserably trying to find a way to successfully updating my Jaiku status externally, I decided to give up. It has seemed like I had tapped all the resources online describing how you do it, but I just couldn’t get it to work on my end. My first attempt was following Jaiku’s instructions in using OAuth to connect to the site, but I soon found out that the callback URL pass doesn’t actually “call back” to your site. Anyway, I started trying my somewhat limited knowledge of cURL until I finally struck gold. Here’s what I got:


$username = "your_username";
$personal_key = "your_personal_key"; // Get yours here
$status = "your_status_message";
$icon = 300; // For the whole list go here
postToJaiku($username, $personal_key, $status, $icon);

function postToJaiku($username, $personal_key, $status, $icon = 300) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://api.jaiku.com/json");
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json"));
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "user=" . urlencode($username) .
"&personal_key=" . urlencode($personal_key) .
"&method=post&message=" . urlencode($message) . "&icon=" . $icon);

curl_exec($ch);
curl_close($ch);
}