Jump to content

Preview Button for a page I already in use.


sprintlife

Recommended Posts

Hey guys,

 

I've been playing with this for hours and getting no where.  I am turning to you guys to see if you can help.

 

form.php

echo "<h1>Form Entry...</h1>"; 
if($form->num_errors > 0){
   echo "<p class=\"error\">There were <b>".$form->num_errors."</b> error(s) found.";;
   echo $form->error("mytxtarea");
   echo "</p>";
}
<form method=\"post\" action=\"process.php\">
<p><script>Init('mytxtarea',75,15,'".$form->value("mytxtarea")."');</script></p><br />
<input type=\"hidden\" name=\"subaddentry\" value=\"1\">
<center><input name=\"send\" type=\"submit\" id=\"Send\" value=\"Submit\" onclick=\"this.disabled=true;this.value='Sending...';this  .form.submit();\"  /><input name=\"preview\" type=\"submit\" id=\"preview\" value=\"Preview\" onclick=\"this.disabled=true;this.value='Sending...';this  .form.submit();\"  />

 

Process.php

if(isset($_POST['subaddentry'])){
         $this->procAddentry();
      }

function procAddentry(){
      global $session, $form;
  
      $retval = $session->addentry($_POST['mytxtarea']);

      /* Account edit successful */
      if($retval == 0){
         $_SESSION['addentry'] = true;
         header("Location: ".$session->referrer);

 }
      /* Error found with form */
      else if($retval == 1){
         $_SESSION['value_array'] = $_POST;
         $_SESSION['error_array'] = $form->getErrorArray();
         header("Location: ".$session->referrer);
      }
      /* Registration attempt failed */
      else if($retval == 2){
         $_SESSION['addentry'] = false;
         header("Location: ".$session->referrer);
      }
   }

 

session.php

function addentry($mytxtarea){
   global $form;  //The database and form object
      
      //Place checks here for error.  I removed them to cut down on the code to look at

   if($form->num_errors > 0){
         return 1;  //Errors with form
      } else {
	$q = "INSERT INTO entry VALUES ('$mytxtarea')";
	 if($database->query($q)){
            return 0;
         }else{
            return 2;
         }
  }
   }

 

My question is simple how do add a preview before it's sent to the database?  I have it where it shows multi errors on the page, but how do I add this in this type of setup I have going on?

 

I would like it to show the preview on the same page (form.php).  Like this....

<h1>Preview...</h1>
Content that was in mytxtarea...
<h1>Form Entry...</h1>

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.