Forums

upload + multiple choice failed - last version

gg4j 03 Jul, 2008
Hi guys!

So I download the last version of CF, and I found an old bug I met already in the previous... possible?!

Upload file failed.

Here's the auto generated script:

<?php
$database =& JFactory::getDBO();
srand((double)microtime()*10000);
$inum = "I" . substr(base64_encode(md5(rand())), 0, 16);

$database->setQuery( "INSERT INTO #__chronoforms_1 VALUES (
'' , '".$inum."','". date('Y-m-d')." - ".date("H:i:s")."', '".$_SERVER['REMOTE_ADDR']."' , '".JRequest::getVar('name','', 'post', 'string', '' )."' , '".JRequest::getVar('titolo','', 'post', 'string', '' )."' , '".JRequest::getVar('descrizione','', 'post', 'string', '' )."' , '".JRequest::getVar('email','', 'post', 'string', '' )."' , '".JRequest::getVar('allegato','', 'post', 'string', '' )."' , '".JRequest::getVar('tema','', 'post', 'string', '' )."' , '".JRequest::getVar('tag','', 'post', 'string', '' )."' , '".JRequest::getVar('region','', 'post', 'string', '' )."');" );
if (!$database->query()) {
echo "<script> alert('".$database->getErrorMsg()."'); window.history.go(-1); </script>
";
}
?>




for this form:

[quote]
<fieldset class="ccform"><legend><strong>Your artwork</strong>
</legend>
<dl class="ccform">

<dt class="ccform"> <label for="name">Author:<b>*</b></label>
</dt>

<dd class="ccform"><input name="name" id="name" type="text">
</dd>

<dt class="ccform"><label for="titolo">Title:<b>*</b></label>
</dt>

<dd class="ccform"><input name="titolo" id="titolo" type="text"> </dd>

<dt class="ccform"><label for="descrizione">Description:</label>
</dt>





<dd class="ccform"><textarea cols="30" name="descrizione" id="descrizione" style="height: 63px; width: 100% " rows="3"></textarea> </dd>

<dt class="ccform"> <label for="email">Your e-mail:<b>*</b></label>
</dt>

<dd class="ccform"><input name="email" id="email" type="text">
</dd>





<dt class="ccform"><label for="allegato">Attach your artwork:<b>*</b></label></dt>

<dd class="ccform"> <input name="allegato" id="allegato" type="file"> <br>

<span class="hint">Maximum size 10MB<span class="hint-pointer">
gg4j 03 Jul, 2008
sorry guys, to make the life easier:

"allegato" is the name of the field expected to do the upload.

File upload enabled,
allegato:jpg|tif|tiff|png|raw|pdf



the multiple choice field is "tema"
gg4j 03 Jul, 2008
Hi again
I read topic:
http://www.chronoengine.com/component/option,com_fireboard/Itemid,37/func,view/id,5260/catid,5/

and check for chronocontact.php
I found the fileperms commented.
Is it correct?

function handle_uploaded_files($uploadedfile, $filename, $limits = TRUE, $directory = FALSE)
{
//global $mosConfig_absolute_path, $mosConfig_fileperms;
//$fileperms = "0644";
/*if ( strlen($mosConfig_fileperms) > 0 ) {
$fileperms = octdec($mosConfig_fileperms);
}*/
$uploaded_files = "";
$upload_path = JPATH_SITE.'/components/com_chronocontact/upload/';
if ( is_file($uploadedfile) ) {
$targetfile = $upload_path.$filename;
while ( file_exists($targetfile) ) {
$targetfile = $upload_path.rand(1,1000).'_'.$filename;
}
move_uploaded_file($uploadedfile, $targetfile);
//if ( strlen($fileperms) > 0 ) {
// chmod($targetfile, $fileperms);
//}
$uploaded_files = $targetfile;
}
return $uploaded_files;
}

GreyHead 03 Jul, 2008
Hi gg4j,

I thought that Max had updated the Files code in the last release but maybe not :-( I'm confused over which bugs have been fixed in which release.

To save multiple options you must use an array name like
name="tema[]"
Bob
gg4j 03 Jul, 2008
:dry: so greyhead, I tryed to change the name for multiple choice:
<dt class="ccform">
<label for="tema">
Please select the domain(s) area(s) described by your photograph. 
To select multiple choices, press <em>CTRL</em> 
and click on the options.</label></dt>
<dd class="ccform">
<select multiple="multiple" name="tema[]" style="width: 100% " >
but what I get in the registered record is just
tema: Array
, and it doesn't display the choices.

Maybe sm update in autogenerated code ? (see two thread above..)

:huh: Any news for uploading images ?
Here J 1.5.3
and last version of CF...

Many thanks for your help!!!
gg4j 03 Jul, 2008
Sorry, I saw messy code before.

1- multiòple choices

<dt class="ccform">
<label for="tema">
Please select the domain(s) area(s) described by your photograph. 
To select multiple choices, press <em>CTRL</em> 
and click on the options.</label></dt>

<dd class="ccform">
<select multiple="multiple" name="tema[]" style="width: 100% " >
name="tema[]"
for multiple choices

as I said, in the record it is registered only Array.. not the choosen values

2- news for uploading images?
GreyHead 03 Jul, 2008
Hi gg4j,

If you want to save it in the database then you will need the implode/explode code.

Bob
gg4j 07 Jul, 2008
1) what do you mean explode/implode the code?
I'd like jus to save the name of the options of multiple choices in the database.. is it possible to do it easily?

2) any news to fix the uploading images?

THANK YOU SO MUCH!
GreyHead 08 Jul, 2008
Hi ggj4,

To save the value sof an array in the database you need to use the implode() function to convert the array into a string. This is just an extra line in the Autogenerated code field.

ChronoForms will do this automatically if it recognises an array field, if you change the field name after using 'Create table' then the code has to be added by hand - or you need to delete and recreate the table.

The code is in these forums several times - please search on 'implode'.

Bob
gg4j 08 Jul, 2008
:laugh:

UUUh, thanks Greyhead, I learned again something new.

I'll put here down the code for reference for others:

to change a set of selection for choice to multiple choice:
$database =& JFactory::getDBO();
	srand((double)microtime()*10000);
	$inum	=	"I" . substr(base64_encode(md5(rand())), 0, 16);
	$_POST['field'] = implode(',', $_POST['field']);
This topic is locked and no more replies can be posted.