Zum Inhalt springen

Mailformplus Upload Variablen weitergeben

Erstellt am 8. Februar 2008 · 19 Antworten · letzte Antwort am 22. Februar 2008

Tags: Datei-Upload, Frage

David107 ·

Hallo,

Kann mir jemand sagen wie ich Variablen an ein PHP Skript weitergeben kann, nach dem senden?

mittels

plugin.tx_thmailformplus_pi1.saveUserFunc.dummy = hello

kann man ja den Wert "hello" weitergeben, nur würde ich gerne
den Wert einer Variable weitergeben.
Ich habe einen Upload eingebaut und will den pfad weitergeben, da Mailform den Dateinamen beim upload ändert, ein Upload heißt zum Beispiel "photouploadFiledata10"

Kann man es nicht auf so einem Weg machen?

plugin.tx_thmailformplus_pi1.saveUserFunc.dummy < photouploadFiledata10
Unbekannter Benutzer ·

Die Varaiblenübergabe funktioniert genaus wie bei jeder anderen userFunc.
Sprich: Dein Ansatz sollte funktionieren, solange "photouploadFiledata10" ein TypoScript-Objekt ist.

David107 ·

Leider steht in meinem Objekt nichts drin.
Man kann ja den Pfad auslesen und in der DB speichern über folgendes

plugin.tx_thmailformplus_pi1.saveDB{
   dbTable=user_table
   dbkey=uid
   mapping=photouploadFiledata10:image1
}

wobei photouploadFiledata10 ein input-file Typ ist.
Wenn ich diese Methode nehme wird der Name richtig in der DB gespeichert,
wenn ich aber dann das Objekt für meinen oben angegebenen Code verwende, wird nichts gespeichert.

David107 ·

Kann mir denn keiner helfen? Es muss doch irgendwie möglich sein.
Ich will jetzt nicht am Ende noch einen anderes Formular installieren müssen

Unbekannter Benutzer ·

wenn ich aber dann das Objekt für meinen oben angegebenen Code verwende, wird nichts gespeichert.

Von welchem Objekt sprichst du?

"photouploadFiledata10" ist der Name eines Input-Felds im Formular, soweit ich dich verstanden habe und kein Objekt.

Wenn du in der saveUserFunc auf den eingetragenen Wert im Uploadfeld zugreifen willst, könnte das so funktionieren:

temp.filename = TEXT
temp.filename.data = GPVar:photouploadFiledata10

plugin.tx_thmailformplus_pi1.saveUserFunc.dummy < temp.filename
David107 ·

Hallo,
das funktioniert leider nicht.
Also mit Objekt hatte ich gmeint das das Feld photouploadFiledata10 vielleicht als Attribut noch den neuen Dateinamen enthält, denn wenn ich die mapping funktion nehme, dann wird hier "mapping=photouploadFiledata10:image1" der neue Dateiname in image1 gespeichtert.
Zum Beispiel der originalname ist bild1234.jpg, dann wird der neue Name MD5Hash_bild1234.jpg und genau den brauch ich.
Wenn ich deinen Vorschlag nehme, dann wird "TEXT" in die Datenbank eingetragen, das heißt die Zuweisung zu dummy gibt ausschließlich Text weiter 🙁
Gibt es im TS so eine Art echo-funktion?

Unbekannter Benutzer ·

mit saveUserFunc kannst du deine eigene PHP-Funktion aufrufen und darin kannst du die übergebenen Parameter verarbeiten.

temp.filename = TEXT
temp.filename.data = GPVar:photouploadFiledata10
plugin.tx_thmailformplus_pi1.saveUserFunc = EXT:myext/class.tx_myext.php:tx_myext->doit
plugin.tx_thmailformplus_pi1.saveUserFunc.dummy < temp.filename

In der PHP-Funktion kannst du auf das übergebene TS-Objekt zugreifen.

Ich sehe da kein Problem. Ich denke, ich habe nicht genau verstanden wobei du Schwierigkeiten hast...

lg, Reinhard

David107 ·

Ich hab das auch genauso gemacht, jedes Feld des Formulars wird übergeben, nur nicht der neue Dateiname
In der PHP-Funktion greife ich per $params['config']['picture10'] auf die Variable zu, aber
bei dieser Aktion

plugin.tx_thmailformplus_pi1.saveUserFunc = fileadmin/scripts/class.user_savedb.php:user_savedb->user_save
temp.filename = TEXT
temp.filename.data = GPVar:photouploadFiledata10
plugin.tx_thmailformplus_pi1.saveUserFunc.picture10 < temp.filename

wird nur die bei temp.filename zugewiesene Zeichenkette übergeben, also "TEXT"

Mein PHP-Skript sieht so aus:

class user_savedb {
	function user_save(&$params, &$ref){
		$insertArray = array(
			'image1' => $params['config']['picture10'],
			'image2' => $params['config']['picture11'],
			'image3' => $params['config']['picture12'],
			'image4' => $params['config']['picture13'],
		);		
		$res = $GLOBALS['TYPO3_DB']->exec_INSERTquery('user_mra_enquiry', $insertArray);
	}
}

und in der Datenbank steht dann anstatt z.b. "018b237b0e_89_Bildxy.jpg" nur TEXT

Kann man vielleicht per TS Werte in eine Session schreiben?
Die zuweisung "<" klappt scheinbar wohl nicht richtig...

Unbekannter Benutzer ·

Das TEXT-Objekt muss auch erstmal mit cObjGetSingle() verarbeitet werden, damit du auf den Wert zugreifen kannst.

Such mal hier im Forum oder auf Google nach der Funktion.

lg, Reinhard

David107 ·

Puuh, sag mal gibt es irgendein gutes Buch wo solche Befehle erklärt werden?
Hab nämlich nicht so die Ahnung von Typo3 und in den Büchern die ich hab steht nur allgemeines Geplänkel.

Funktioniert das etwa so mit dem cObjGetSingle?

$picture10 = this->cObj->cObjGetSingle('TEXT', $this->conf['temp.'])

Gruß David

Unbekannter Benutzer ·
$picture10 = $this->cObj->cObjGetSingle($this->conf['temp'], $this->conf['temp.'])

Parameter 1 ist die Info, welches Objekt das ist (eventuell funktionierts auch mit dem String 'TEXT', hab ich noch nie probiert).
Parameter 2 sind dann die TS-Optionen zum Objekt.

Info über die Befehle gibts online in der Doku der TYPO3 API. Wenn man was sucht, ist es sicher Anlaufstelle Nummer 1.

lg, Reinhard

David107 ·

Ok danke schonmal,
habs getestet, aber ich bekomme immer nur eine Fehlermeldung:
"Call to a member function on a non-object in ... "
Muss ich erst irgendwo eine Instanz erstellen um darauf zugreifen zu können?
Die anderen Beispiele hier im Forum haben mir leider nicht weiterhelfen können...
Oder muss ich die cObjGetSingle()Funktion ausführen bevor ich meine saveUserFunc ausführe?

David107 ·

Hallo ich bins nochmal 🙂
Ich hab folgendes probiert:

function user_save(&$params, &$ref){
	$this->params = $params;
	t3lib_div::debug($this->params,'unser debug');  
		
	$this->cObj = t3lib_div::makeInstance('tslib_cObj');
	$picture10 = $this->cObj->cObjGetSingle($this->params['config']['picture10'], $this->params['config']['picture10.']);

...

Über debug sehe ich logischerweise folgende Werte

config
picture10 TEXT
picture10. data GPVar:photouploadFiledata10

Aber in $picture10 steht nix drin

Auf $this->conf kann ich nicht zugreifen, weil es nicht mitübergeben wird.

Unbekannter Benutzer ·

Ich schätze mal du übergibst die Parameter so:

temp.filename = TEXT
temp.filename.data = GPVar:photouploadFiledata10

plugin.tx_thmailformplus_pi1.saveUserFunc = fileadmin/scripts/class.user_savedb.php:user_savedb->user_save
plugin.tx_thmailformplus_pi1.saveUserFunc.picture10 < temp.filename

Dann greifst du in der UserFunc so darauf zu:

...
function user_save($content = "", $conf = array()){
$this->cObj = t3lib_div::makeInstance('tslib_cObj');
$picture10 = $this->cObj->cObjGetSingle($conf['picture10'], $conf['picture10.']);
...
David107 ·

Hallo Reinhard,
Das hat leider nicht geklappt, in $picture10 steht nachwievor nichts drin.
Und wenn ich beim debug nachschaue, steht picture10 nicht unter $conf[picture10], sondern unter $conf[saveUserFunc.][picture10]. Das hat aber auch nicht geklappt.

David107 ·

Hier der Code, alles weiter hast du per PM
Das ist mein zuletzt funktionierender Code, deinen Vorschlag hab ich dort noch nicht drin.

#############################################################################
#### File-Upload Konfiguration
#############################################################################
plugin.tx_thmailformplus_pi1.fieldConf {
  photouploadFiledata10.fileUpload = uploads/mrapics/
  photouploadFiledata11.fileUpload = uploads/mrapics/
  photouploadFiledata12.fileUpload = uploads/mrapics/
  photouploadFiledata13.fileUpload = uploads/mrapics/
  
  photouploadFiledata20.fileUpload = uploads/mrapics/
  photouploadFiledata21.fileUpload = uploads/mrapics/
  photouploadFiledata22.fileUpload = uploads/mrapics/
  photouploadFiledata23.fileUpload = uploads/mrapics/
  
  photouploadFiledata30.fileUpload = uploads/mrapics/
  photouploadFiledata31.fileUpload = uploads/mrapics/
  photouploadFiledata32.fileUpload = uploads/mrapics/
  photouploadFiledata33.fileUpload = uploads/mrapics/  
  
  photouploadFiledata40.fileUpload = uploads/mrapics/
  photouploadFiledata41.fileUpload = uploads/mrapics/
  photouploadFiledata42.fileUpload = uploads/mrapics/
  photouploadFiledata43.fileUpload = uploads/mrapics/
}


#############################################################################
#### Speichern der Daten in der DB:user_mra und user_mra_enquiry mittels Hook
#############################################################################
plugin.tx_thmailformplus_pi1.saveUserFunc = fileadmin/scripts/class.user_savedb.php:user_savedb->user_save

temp.filename = TEXT
temp.filename.data = GPVar:photouploadFiledata10

plugin.tx_thmailformplus_pi1.saveUserFunc.picture10 < temp.filename
<?
class user_savedb extends tslib_pibase{
	function user_save(&$params, &$ref){
		$this->params = $params;
		//t3lib_div::debug($this->params,'Debug params');
		$this->cObj = t3lib_div::makeInstance('tslib_cObj');
	   	$picture10 = $this->cObj->cObjGetSingle($this->params['config']['picture10'], $this->params['config']['picture10.']);
		
		// Die per Formular uebertragenen Daten werden in die DB user_mra eingetragen
		$insertArray = array(
			'title' => $params['data']['title'],
			'firstname' => $params['data']['firstName'],
			'lastname' => $params['data']['lastName'],
			'company' => $params['data']['company'],
			'address' => $params['data']['address'],
			'address2' => $params['data']['address2'],
			'city' => $params['data']['city'],
			'postcode' => $params['data']['zip'],
			'country' => $params['data']['country'],
			'phone' => $params['data']['phone'],
			'fax' => $params['data']['fax'],
			'email' => $params['data']['email'],
			'contacttitle' => $params['data']['contactTitle'],
			'contactfirstname' => $params['data']['contactFirstName'],
			'contactlastname' => $params['data']['contactLastName'],
			'contactcompany' => $params['data']['contactCompany'],
			'contactaddress' => $params['data']['contactAddress'],
			'contactaddress2' => $params['data']['contactAddress2'],
			'contactcity' => $params['data']['contactCity'],
			'contactpostcode' => $params['data']['contactZip'],
			'contactcountry' => $params['data']['contactCountry'],
			'contactphone' => $params['data']['contactPhone'],
			'contactfax' => $params['data']['contactFax'],
			'contactemail' => $params['data']['contactEmail'],
			'deliverytitle' => $params['data']['deliveryTitle'],
			'deliveryfirstname' => $params['data']['deliveryFirstName'],
			'deliverylastname' => $params['data']['deliveryLastName'],
			'deliverycompany' => $params['data']['deliveryCompany'],
			'deliveryaddress' => $params['data']['deliveryAddress'],
			'deliveryaddress2' => $params['data']['deliveryAddress2'],
			'deliverycity' => $params['data']['deliveryCity'],
			'deliverypostcode' => $params['data']['deliveryZip'],
			'deliverycountry' => $params['data']['deliveryCountry'],
			'deliveryphone' => $params['data']['deliveryPhone'],
			'deliveryfax' => $params['data']['deliveryFax'],
			'deliveryemail' => $params['data']['deliveryEmail']
		);
		$res = $GLOBALS['TYPO3_DB']->exec_INSERTquery('user_mra', $insertArray);
		
		// jedes Enquiry wird in die DB user_mra_enquiry eingetragen, mit der pid des Eintrags in user_mra
		$lastID=$GLOBALS['TYPO3_DB']->sql_insert_id();
		for ($i= 1; $i<5; $i++){
			if($params['data']['problemDescription'.$i.'']!=""){
				$insertArray2 = array(
					'pid' => $lastID,
					'productgroup' => $params['data']['productGroup'.$i.''],
					'type' => $params['data']['productType'.$i.''],
					'number' => $params['data']['serialNumber'.$i.''],
					'description' => $params['data']['problemDescription'.$i.''],
					'continously' => ($params['data']['errorFrequencyContinuously'.$i.'']!=""),
					'temperature' => ($params['data']['errorFrequencyTemperature'.$i.'']!=""),
					'installation' => ($params['data']['errorFrequencyInstallation'.$i.'']!=""),
					'months_check' => ($params['data']['errorFrequencyMonthsCheck'.$i.'']!=""),
					'months' => $params['data']['errorFrequencyMonths'.$i.''],
					'minutes_check' => ($params['data']['errorFrequencyMinutesCheck'.$i.'']!=""),
					'minutes' => $params['data']['errorFrequencyMinutes'.$i.''],
					'sometimes' => ($params['data']['errorFrequencySometimes'.$i.'']!=""),
					'never_used' => ($params['data']['errorFrequencyUnused'.$i.'']!=""),
					'cost_estimate' => ($params['data']['costEstimate'.$i.'']!=""),
					'repair_cost' => ($params['data']['repairWithCosts'.$i.'']!=""),
					'calibration_contact' => ($params['data']['workingStandard'.$i.'']!=""),
					'calibration_attached' => ($params['data']['dkdCalibration'.$i.'']!=""),
					'comments' => $params['data']['additionalComments'.$i.''],
					'image1' => $picture10,
					'image2' => $params['config']['picture'.$i.'1'],
					'image3' => $params['config']['picture'.$i.'2'],
					'image4' => $params['config']['picture'.$i.'3'],
				);		
				$res2 = $GLOBALS['TYPO3_DB']->exec_INSERTquery('user_mra_enquiry', $insertArray2);
			}
		}
	}
}

?>
Unbekannter Benutzer ·

Ich hab hier einen Auszug aus dem Quelltext deiner Seite:

...
<ul class="photoupload-queue" id="photoupload-queue-number">
    <li>
      <input type="file" name="photouploadFiledata-number0" id="photouploadFiledata-number0" />

    </li>
  </ul>
  <div id="downloadButton">
    <input type="button" onclick="addDownload(-number)" value="Hinzuf&uuml;gen">
    <input type="button" onclick="removeDownload(-number)" value="L&ouml;schen">
  </div>
...

Das FileUploadfeld heißt offensichtlich "photouploadFiledata-number0" und nicht
"photouploadFiledata10", also schätze ich mal, dass auch kein Get/Post-Parameter "photouploadFiledata10" übertragen wird.

Kann es sein, dass du einen Fehler in deinem JavaScript hast? Es werden die Funktionen addDownload und removeDownload mit dem Parameter "-number" aufgerufen, der anscheinend aber als String angehängt wird und nicht als Zahlenwert. Es ist sicher hiflreich, wenn du mal den Debugmodus von Mailformplus aktivierst und nach Absenden des Formulars schaust, welche Get/Post-Werte übertragen werden.

plugin.tx_thmailformplus_pi1.debug = 1

Vielleicht passiert tatsächlich ein Fehler bei der Namensgebung für die UploadFelder und das Problem liegt nicht im TS oder PHP!

lg, reinhard

David107 ·

Der Wert number wird vom JavaScript in die jeweilige nummer umgesetzt, das klappt soweit auch, kann man mit dem Firebug sehen.
Auch wenn ich folgende TS-Anweisung ausführe klappt es:

plugin.tx_thmailformplus_pi1.saveDB = 1
plugin.tx_thmailformplus_pi1.saveDB{
   dbTable=user_mra_enquiry
   dbkey=uid
   mapping=photouploadFiledata10:image1,photouploadFiledata11:image1,photouploadFiledata12:image1,photouploadFiledata13:image1
}

Nur möchte ich es ja selbst abspeichern und nicht mittels saveDB