Page 1 of 1

preview to update then publish

Posted: Tue Sep 06, 2005 3:54 pm
by $var
Every thread based site that has any clue how to run for the lay has a preview before posting... much like this BB forum.

How does one send to a preview area, without actually posting to the database, and from there, what makes it go on after it is approved?

Posted: Tue Sep 06, 2005 4:18 pm
by s.dot
I suppose just showing a template with the $_POST'd values.... with them each in their place. Then to submit, they need to insert into the database.

Posted: Tue Sep 06, 2005 4:32 pm
by John Cartwright

Code: Select all

switch ($_POST['submit']) {
   case 'preview' : 
           echo 'This is a preview of '.$_POST['var'];
   break;

   case 'insert' : 
           mysql_query(...); 
   break;
}
Assuming you have 2 submit buttons, 1 with a value of preview and 1 with a value of insert.

To revisit this topic:

Posted: Tue Sep 27, 2005 10:49 am
by $var
I understand, loosely, that $_POST is a global variable
and that once something is set to $POST,
it sort of stores the info in a magic clipboard that knows
what you are talking about when you use $_GET.

However, I don't really understand how it does that...
Where is it saving it to?

If I have the ADD button $sql statement saying INSERT,
What would the PREVIEW button look like, and where does it go?

Code: Select all

if($_POST['bpress']=="add")
	{
		$sql = "INSERT INTO city (Blah) VALUES ('".$_POST["blah']."')";
         }

Posted: Tue Sep 27, 2005 10:53 am
by shiznatix
if they are gonna preview it then you could do many things, you could set their post as a session them when they click yes submit that just use the session, you could put in a hidden field in the preview page and set the post to that hidden field so that it is submitted again, you could have a temp table for posts like that then just copy it from the temp table to the real table.

Posted: Tue Sep 27, 2005 12:29 pm
by $var
i don't understand.
if you are telling the $_POST to INSERT,
then how is it a preview?

my brain isn't making this connection.
say i make a preview page,
where is the information being grabbed from?

when i have made detail pages in the past,
it draws the info from a table.

i don't understand where to get the information from if it hasn't been posted to a database.
i bet that that is what the $_POST is about.
I can imagine on the other side of this block, I will grasp a lot more than preview pages.

Posted: Tue Sep 27, 2005 12:34 pm
by s.dot
When you submit your form, your form data is stored in an associative array called $_POST

this will look like

Code: Select all

Array (
  ['field1'] => value1
  ['field2'] => value2
  ['field3'] => value3
)
You can then use these values by calling out the indivual name of the field. In this example.. $_POST['field2'] would be 'value2' which is what was entered in your form element named 'field2'

You can then do whatever you wish with the data (such as display it) without inserting into a database.

for example:

Code: Select all

$name = $_POST['name']  // name was the name of your form input element
echo "Your name is $name";

Posted: Tue Sep 27, 2005 12:34 pm
by feyd
okay.. default action of the form is to send to the preview page via the preview submit button being first (and if not set in the submission does a preview automatically), the post button has a different value on it than the preview one, thus changing which side of the divider it lands on. There are 3 pages in 1 script with this. That's how this board works (roughly).