It appears you have not yet registered with DEVPPL. To register please click here... (it's fast, easy and free!)

Forum

Log In Sponsors
Board index Programming JavaScript Forum

Posting canvas data with other inputs

Posting canvas data with other inputs

Postby fiddlesticksfinn on Fri Mar 25, 2011 5:44 pm

Okay so please can somebody tell me what Im doing wrong here.
Im trying to convert the contents of a canvas into a data url and then post it along with other inputs to the controller in order to save an image.

The PHP:
Code: Select all
<form method="post" accept-charset="utf-8" action="<?php echo ($base_url . 'template/new_template'); ?>" name="form" id=form" />
<?php
$edit_template_code = array(
        'name' => 'edit_template_code',
        'id' => 'edit_template_code',
        'value' => set_value('edit_template_code')
    );
?>
<canvas id="processing-canvas"> </canvas>

<?php echo form_textarea($edit_template_code); ?>
<input type='hidden' name='save_image' />
<?php echo form_submit(array('name' => 'save'), 'Save Template'); ?>

<?php echo form_close(); ?>

The jquery:
Code: Select all
$(document).ready(function() {
    $("#form").submit(function() {
        var canvas = document.getElementById("processing-canvas"); //in your pjs sketch this is externals.canvas
        var save_image = canvas.toDataURL("image/png");
       
        $('input[name=save_image]').val(save_image);       
    });
});

Or maybe somebody knows of a different way to do it…?
Thanks in advance
fiddlesticksfinn
 
Posts: 2
Joined: Fri Mar 25, 2011 5:40 pm

Re: Posting canvas data with other inputs

Postby fiddlesticksfinn on Mon Mar 28, 2011 10:03 am

Anybody with any ideas? Im beating my head against the wall here
fiddlesticksfinn
 
Posts: 2
Joined: Fri Mar 25, 2011 5:40 pm


Who is online

Users browsing this forum: No registered users and 3 guests