I have a drupal-7 website and I created a module, where you insert an image.
This is the code for this form at the .module file
function testform($form, &$form_state) {
$form = array();
$form['file'] = array(
'#type' => 'file',
'#id' => 'files',
'#title' => t('Select image'),
'#description' => t('Upload a file, allowed extensions: jpg, jpeg, png, gif'),
'#upload_validators' => array('file_validate_is_image' => array())
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Submit'),
);
return $form;
}
Also, in my module-template.tpl.php file, I have created a form, that gives a preview of the image you submitted in it. This is the code I use:
<form id="form1" runat="server">
<input type='file' id="imgInp" />
<img id="blah" src="#" alt="your image" />
</form>
<script>
function readURL(input) {
if (input.files && input.files[0]) {
var reader = new FileReader();
reader.onload = function (e) {
$('#blah').attr('src', e.target.result);
}
reader.readAsDataURL(input.files[0]);
}
}
$("#imgInp").change(function(){
readURL(this);
});
</script>
I want, when you select an image at the testform, then the form1 to trigger and preview the image that you selected at the testform.
Any ideas?