Created
November 18, 2014 13:14
-
-
Save anonymous/bf8eb0ac3879f76c7f55 to your computer and use it in GitHub Desktop.
REDAXO Xform Session Handling action + example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
$objparams["actions"][] = "db"; // z.b. email, datenbank, als datei speichern etc. | |
$objparams["action_params"][] = array( | |
"table" => "REX_VALUE[8]", | |
"where" => "REX_VALUE[8]", | |
); | |
*/ | |
class rex_xform_action_saveinsession extends rex_xform_action_abstract { | |
function execute() { | |
foreach($this->params['value_pool']['sql'] as $key => $value) { | |
$_SESSION['XFORM'][$key] = $value; | |
} | |
if ($this->params["debug"]) { | |
print '<pre>'; | |
print_r($_SESSION['XFORM']); | |
print_r($_POST); | |
print '</pre>'; | |
} | |
} | |
function getDescription() | |
{ | |
return "action|saveinsession"; | |
} | |
} | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$voucher_article_id = 1; | |
$summary_article_id = 2; | |
$thanks_article_id = 3; | |
$show_voucher_summary = ( $REX['ARTICLE_ID'] == $summary_article_id && ( isset($_SESSION['XFORM']) && count($_SESSION['XFORM']) > 0) ) ? true : false; | |
if (! $show_voucher_summary && ($REX['ARTICLE_ID'] != $voucher_article_id && $REX['ARTICLE_ID'] != $thanks_article_id)) { | |
$url = rex_getUrl($voucher_article_id); | |
if ($url != '') { | |
ob_end_clean(); | |
header('Location: ' . $url); | |
exit(); | |
} | |
} | |
$xform = new rex_xform(); | |
//$xform->setDebug(true); | |
$xform->setRedaxoVars(); | |
$form_data = ''; | |
if ($REX['ARTICLE_ID'] == $thanks_article_id) { | |
unset($_SESSION['XFORM']); | |
} elseif ($show_voucher_summary) { | |
// Formular wurde abgeschickt | |
// Zusammenfassung | |
$form_data .= ' | |
objparams|submit_btn_show|0 | |
show_voucher_summary|voucher_summary | |
checkbox|agbs|Ich habe die Allgemeinen Geschäftsbedingungen gelesen und stimme diesen zu. | |
html||<div class="grid voucher-summary"> | |
html||<div class="unit unit2of4"> | |
html||<a class="btn-back" href="' . rex_getUrl($voucher_article_id) . '">Angaben ändern</a> | |
html||</div> | |
html||<div class="unit unit-extends"> | |
submit|submit|Bestellen|no_db|submit | |
html||</div> | |
html||</div> | |
validate|empty|agbs|Bitte bestätigen Sie, dass Sie die Allgemeinen Geschäftsbedingungen gelesen haben und diesen zustimmen. | |
'; | |
$xform->setActionField('db2email', array('voucher', '', $email)); | |
$xform->setActionField('redirect', array($thanks_article_id)); | |
} else { | |
$form_data .= ' | |
html||</div> | |
html||<div class="booking-data"> | |
html||<h2>Ihre Daten</h2> | |
text|daten_vorname|Vorname*|' . (isset($_SESSION['XFORM']['daten_vorname']) ? $_SESSION['XFORM']['daten_vorname'] : '') . ' | |
text|daten_nachname|Nachname*|' . (isset($_SESSION['XFORM']['daten_nachname']) ? $_SESSION['XFORM']['daten_nachname'] : '') . ' | |
text|daten_strasse|Straße*|' . (isset($_SESSION['XFORM']['daten_strasse']) ? $_SESSION['XFORM']['daten_strasse'] : '') . ' | |
text|daten_ort|Postleitzahl, Ort*|' . (isset($_SESSION['XFORM']['daten_ort']) ? $_SESSION['XFORM']['daten_ort'] : '') . ' | |
text|daten_telefon|Telefon (wenn mgl. Mobil)*|' . (isset($_SESSION['XFORM']['daten_telefon']) ? $_SESSION['XFORM']['daten_telefon'] : '') . ' | |
text|daten_email|E-Mail*|' . (isset($_SESSION['XFORM']['daten_email']) ? $_SESSION['XFORM']['daten_email'] : '') . ' | |
html||<p>* Pflichtfelder</p> | |
html||</div> | |
validate|empty|daten_vorname|Bitte geben Sie Ihren Vornamen an | |
validate|empty|daten_nachname|Bitte geben Sie Ihren Nachnamen an | |
validate|empty|daten_strasse|Bitte geben Sie Ihre Straße an | |
validate|empty|daten_ort|Bitte geben Sie Ihre Postleitzahl und Ort an | |
validate|empty|daten_telefon|Bitte geben Sie Ihre Telefonnummer an | |
validate|empty|daten_email|Bitte geben Sie Ihre E-Mail an | |
validate|email|daten_email|Bitte geben Sie eine korrekte E-Mail an | |
'; | |
$xform->setHiddenField('voucher', true); | |
$xform->setActionField('saveinsession'); | |
$xform->setActionField('redirect', array($summary_article_id)); | |
} | |
if ($form_data != '') { | |
$form_data = trim(str_replace('<br />', '', rex_xform::unhtmlentities($form_data))); | |
$xform->setFormData($form_data); | |
//$xform->setObjectparams('form_show', true); | |
//$xform->setObjectparams('send', false); | |
echo $xform->getForm(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment