This is a combination jquery / php question, so I’m not sure I’ve posted in the correct forum.
In a project I am working on, the user uploads an image. A rectangular template image is placed over top of the uploaded image which the user can resize and drag.
I am using the following jquery code to drag and resize the template, then record the position of the top left corner of the template, and the width of the template.
jQuery(document).ready(function() {
jQuery("#template")
.draggable({
drag: function(event, ui) {
var horizontalPosition = console.log(ui.position.left);
var verticalPosition = console.log(ui.position.top);
}
})
.resizable({
handles: 's,n,e,w',
aspectRatio: 433 / 500,
stop: function(event, ui) {
var width = console.log(Math.round(ui.size.width).toFixed(0));
var height = console.log(Math.round(ui.size.height).toFixed(0));
}
});
[I]...juery code continued below...[/I]
I am able to see the width and position results in the console, so this part is working.
But then I would like to take these values and store them in a database. So I have the following form -
<form action="process.php" method="post" name="image_results" />
<div>
<input type="hidden" name="template_width" id="template_width" value="" />
<input type="hidden" name="template_xpos" id="template_xpos" value="" />
<input type="hidden" name="template_ypos" id="template_ypos" value="" />
<input type="submit" name="submit" id="save_image" value="Save Image" />
</div>
</form>
and added the following code to the end of my jquery to enter the values into the hidden input boxes.
$('input#template_width').attr('value', width);
$('input#template_xpos').attr('value', horizontalPosition);
$('input#template__ypos').attr('value', verticalPosition);
});
Then in my process.php I processed the $_POST values in preparation to storing them in the database, but when I tried echoing them, they were empty.
In my jquery, I tried removing the console.log() first but that didn’t help.
if (isset( $_POST['submit'] ) && $_POST['submit'] == 'Save Image') {
if (isset($_POST['template_width'])) {
$template_width = $_POST['template_width'];
} else {
$template_width = '';
}
if (isset($_POST['template_xpos'])) {
$template_xpos = $_POST['template_xpos'];
} else {
$template_xpos = '';
}
if (isset($_POST['template_ypos'])) {
$template_ypos = $_POST['template_ypos'];
} else {
$template_ypos = '';
}
echo "Template Width: " . $template_width . " :: Template x position: " . $template_xpos . " :: Template y position: " . $template_ypos;
Am I taking the wrong approach? or is there some glaring error in my code that I can’t see?