change position of a preview fieldset

I hove a script in which I wanted to change the position of the “preview fieldset” (vorschau)
when I submit the form button with “Vorschau”, the Vorschau goes always on the top of the page when it reloads.
How can I put the “vorschau fieldset” just above the two buttons “Vorschau” and “Eintragen”

I made a screencast to see what it should looke like. And the concerning code section is line 161 - 172
Can this done with an anchor to jump on this position with the “preview fieldset” when submit the button “vorschau” ?

example website: http://pantanal.ch/gaestebuch_de.php?eintragen

[code] <?php
/*

include “assets/gaestebuch/gb_konfig.php”;

if (!isset($_GET[“eintragen”])) {

print ‘

In das Gästebuch eintragen

’;

// Anzahl der Seiten berechnen
$AnzahlDatensaetze = $db->query(“SELECT COUNT(*) FROM " . $TABLE_PREFIX . "_gaestebuch WHERE anzeige = ‘1’”)->fetchColumn(0);

if ($AnzahlDatensaetze > 0) {
$Seitenanzahl = ceil($AnzahlDatensaetze / $EINTRAEGE_SEITE);
$AktuelleSeite = isset($_GET[“seite”]) ? $_GET[“seite”] : 1;
$AktuelleSeite = ctype_digit($AktuelleSeite) ? $AktuelleSeite : 1;
$AktuelleSeite = $AktuelleSeite < 1 || $AktuelleSeite > $Seitenanzahl ? 1 : $AktuelleSeite;
$Versatz = $AktuelleSeite * $EINTRAEGE_SEITE - $EINTRAEGE_SEITE;

// Gästebucheinträge auslesen
$select = $db->query("SELECT name, nachricht, homepage, bewertung, datum
FROM " . $TABLE_PREFIX . "_gaestebuch
WHERE anzeige = ‘1’
ORDER BY datum " . ($EINTRAEGE_IO == “Ende” ? “ASC” : “DESC”) . "
LIMIT " . $Versatz . ", " . $EINTRAEGE_SEITE);
if ($datensaetze = $select->fetchAll(PDO::FETCH_OBJ)) {

// Link-, und Formular-Navigation
print ’
’ . $AnzahlDatensaetze . ($AnzahlDatensaetze > 1 ? ’ Einträge’ : ’ Eintrag’) . ’ - Seite: ’ .
(($AktuelleSeite - 1) > 0 ? ‘’ : ‘’) .

<input class="seitencounter" type="text" value="' . $AktuelleSeite . '" name="seite" title="Seitenzahl eingeben und die Eingabetaste drücken." onClick="this.select()">
von ' . $Seitenanzahl . (($AktuelleSeite + 1) <= $Seitenanzahl ? ' ' : '') . ' '; echo "
";

// Gästebucheinträge anzeigen
foreach($datensaetze as $datensatz) {
sscanf($datensatz->datum, “%4s-%2s-%2s”, $jahr, $monat, $tag);
print ‘

’ . $datensatz->name . ’ ’ .
bewertung($datensatz->bewertung, $STERN_NUMMER, $STERNE_ANZAHL) . ’  ’ . (kalender($tag, $monat, $jahr)) . ‘’ .
($datensatz->homepage != “” ? ’ - ’ . $datensatz->homepage . ‘’ : ‘’) .
’ . code($datensatz->nachricht) . ‘
’;
}

// Navigation Zurück /Weiter
if ($AnzahlDatensaetze > $EINTRAEGE_SEITE) {
print ‘

’ . (($AktuelleSeite - 1) > 0 ? '◄ Zurück  ’ : ‘’) . ’ ’ .
(($AktuelleSeite + 1) <= $Seitenanzahl ? ‘Weiter ►’ : ‘’) . ‘

’;
}
}
}
else {
print ‘

Noch keine Einträge vorhanden!

’;
}
}
else {

// In das Gästebuch eintragen
$name = isset($_POST[“name”]) ? $_POST[“name”] : “”;
$nachricht = isset($_POST[“nachricht”]) ? $_POST[“nachricht”] : “”;
$email = isset($_POST[“email”]) ? $_POST[“email”] : “”;
$homepage = isset($_POST[“homepage”]) ? $_POST[“homepage”] : “”;

// Benutzereingaben überprüfen
$Fehler = array(“name”=>"",“nachricht”=>"",“sicherheit”=>"",);
if (isset($_POST[“submit”]) ||
isset($_POST[“vorschau”])) {
$Fehler[“name”] = strlen($_POST[“name”]) <= 5 ? ‘’ : ‘’;
$Fehler[“name”] = strip_tags($_POST[“name”]) != $_POST[“name”] ? ‘HTML-Tags sind nicht erlaubt!
’ : $Fehler[“name”];
$Fehler[“nachricht”] = strlen($_POST[“nachricht”]) < 15 ? ‘’ : ‘’;
$Fehler[“nachricht”] = strip_tags($_POST[“nachricht”]) != $_POST[“nachricht”] ? ‘HTML-Tags sind nicht erlaubt!
’ : $Fehler[“nachricht”];
$Fehler[“sicherheit”] = (!isset($_POST[“vorschau”]) && md5($_POST[“zip”]) != $_POST[“zip2”]) ? ‘Die Sicherheitsabfrage ist falsch!
’ : ‘’;
}

// Auswahlliste “Webseite Bewertung”
$bewertung = isset($_POST[“bewertung”]) ? $_POST[“bewertung”] : 0;
$bewertungsauswahl = “\n \n Ich gebe keine Sterne”;
for ($value = 1; $value <= $STERNE_ANZAHL; $value++) {
$bewertungsauswahl .= “\n <option value=’” . $value . “’” .
((isset($_POST[“bewertung”]) ? $_POST[“bewertung”] : “”) == $value ?
" selected=‘selected’" : “”) . “>” . str_repeat($STERN_NUMMER . ’ ', $value) . “”;
}
$bewertungsauswahl .= "\n \n ";

// Sicherheitsabfrage - Zufallszahlen generieren
$Z0 = array(mt_rand(1, 9), mt_rand(1, 9));
$Z1 = max($Z0); $Z2 = min($Z0);
$Spam = $Z1 . " + &#" . (48 + $Z2) . “;”;
$Schutz = md5($Z1 + $Z2);

// Formular erstellen
$Formular = $javascript . ’

zum Gästebuch

Dein Name

Dein Feedback ' . (smiley()) . '
' . $nachricht . '

' . ( $FORMFELD_EMAIL == "ja" ? '

E-Mail-Adresse (wird nicht angezeigt)

' : '' ) . ( $FORMFELD_HOMEPAGE == "ja" ? '

Ihre Homepage: (Optional)

' : '' ) . '

Wie hat es dir gefallen?' . $bewertungsauswahl . '
(Sterne von 1 bis ' . $STERNE_ANZAHL . ')

' . ($_SERVER["REQUEST_METHOD"] != "POST" ? '' : '

Sicherheitsabfrage: ✲ ' . $Fehler["sicherheit"] . '  ' . $Spam . ' =

') . '


Beachte, dass dein Feedback erst nach einer Prüfung frei geschaltet wird.



’ . ($_SERVER[“REQUEST_METHOD”] == “POST” ? ‘’ : ‘’) . ’

';

// Vorschau
if (isset($_POST[“vorschau”]) &&
strlen($_POST[“name”]) >= 1 &&
strlen($_POST[“nachricht”]) >= 1) {
print ‘

Vorschau

’ .
$name . ’ ’ .
(bewertung($bewertung, $STERN_NUMMER, $STERNE_ANZAHL)) . ‘
’ .

’ . code($nachricht, true) . ‘
’ .
($FORMFELD_EMAIL == “ja” && $email != “” ? '
E-Mail: ’ . $email . '
Deine Email wird im Gästebuch nicht angezeigt
’ : ‘’) .
($FORMFELD_HOMEPAGE == “ja” && $homepage != “” ? '
Homepage: ’ . $homepage . ‘’ : ‘’) .


’;
}

// Formular abgesendet
if (isset($_POST[“submit”])) {

// Sind keine Benutzer-Eingabefehler vorhanden …
if (implode("", $Fehler) == “”) {
// … in die Datenbank eintragen.
$insert = $db->prepare(“INSERT INTO " . $TABLE_PREFIX . "_gaestebuch (anzeige, name, nachricht, email, homepage, bewertung, datum) VALUES ( :anzeige, :name, :nachricht, :email, :homepage, :bewertung, '” . date(“Y-m-d H:i:s”) . “’)”);
if ($insert->execute([’:anzeige’ => $ANZEIGESPERRE,
‘:name’ => $_POST[“name”],
‘:nachricht’ => $_POST[“nachricht”],
‘:email’ => $email,
‘:homepage’ => $homepage,
‘:bewertung’ => $_POST[“bewertung”]])) {

$id = $db->lastInsertId();

print '<p>Vielen Dank <i>' . htmlspecialchars($_POST["name"], ENT_QUOTES | ENT_HTML5, 'UTF-8') . 
 '</i>,<br>Dein Feedback wurden in das Gästebuch eingetragen.</p>
  <p><a href="gaestebuch_de.php">Das Gästebuch anzeigen</a></p>';

// E-Mail an den Admin versenden
if ($GB_INFO == "ja") {
 mb_internal_encoding("UTF-8");
 $Betreff = mb_encode_mimeheader("Neues Feedback erhalten", "UTF-8", "Q");

 $Kopfzeile = "MIME-Version: 1.0;\nFrom: " .
  mb_encode_mimeheader($_POST["name"], "UTF-8", "Q") .
  "<[email protected]>" . "\nContent-Type: text/plain; Charset=UTF-8;\n";

 @mail($EMAIL, $Betreff,
            "Datum: " . date("d.m.Y H:i") .
            " Uhr\nName: " . strip_tags($_POST["name"]) .
            "\nNachricht:\n" . strip_tags($_POST["nachricht"]) .
            "\n\nE-Mail:\n" . strip_tags($email) .
            "\nHomepage:\n" . strip_tags($homepage) .
           "\n\nBearbeiten: " . $PFAD . "assets/gaestebuch/gb_admin.php?id=" . $id, $Kopfzeile);
}

}
}
else {
// Formular und Benutzer-Eingabefehler ausgeben
print $Formular;
}
}
else {
// Formular ausgeben
print $Formular;
}
}
?>[/code]

Thank you for any help
Adrian


I would do an API personally. Then you call the API from the form and update the element that you designate.

I can spin up an example if needed.

hi astonecipher

i am an aboslutly beginner, I know well about CSS and html, but I don’t know how you meant this with the api.
It’s a script from the internet and I wanted tu put he //vorschau part into the itself. right up the two submitbuttons. but when I do this the buttons deasapear.

Maybe its better to let it like this, especially when it is needed to completly modifie the script.
If you have an easy solution, I would be happy.

Thanks you astonecipher

You need and element within the form and then using javascript/ jquery, populate that element with the new data.

Thank you astonecipher

I have little ideas to do this, but I will learn more about programming.

Thanks a lot

Adrian

We can simplify things a bit. Had to think through your code, since I don’t read the language.

You are checking if the eintragen is there, before you check if the page is submitted. If you output that html into a variable, you can utilize it where you want, rather than having it appear where you actually process it. Does that make sense?

thanks astonecipher, trying to help me

for the moment not really, I think I have to less experiences yet to understand it.
hmmmm I will go this throug in a calm moment, right now I was sitting 12 hours in front of th computer I need a lake-swimming-pause.

cheers adrian

Sponsor our Newsletter | Privacy Policy | Terms of Service