Jump to content

Recommended Posts

I'm trying to be able to preview what is entered in a form before it's submited but i'm getting stuck - the preview button is submitting the form.
[code}if (isset($_POST['Preview']) && ($_POST["MM_insert"] == "form1")) {
header("Location: forum.php");
}

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
$text = $_POST['post'];
$text = nl2br($text);
$p = preg_replace ($search, $replace, $text);

$dt = date('d/M/y');

$tim = strftime('%I:%M:%p'); 
$dat = date('dmy');

$tm = time(); 
if ($edi<=1) {
mysql_select_db($database_elvisdb, $elvisdb);
  $insertSQL = sprintf("INSERT INTO forum (discnum, message, date, time, timenum, user) VALUES ('$dn', '$text', '$dt', '$tim', '$tm', '$logon');"); 

  mysql_select_db($database_elvisdb, $elvisdb);
  $Result1 = mysql_query($insertSQL, $elvisdb) or die(mysql_error());

.....

 

form-

	        <form action="<?php echo $loginFormAction; ?>" method="POST" name="form1" id="form1">
	  <table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
		  <td align="center" bgcolor="#339999"><br />
		  <strong>Enter post</strong><br />
		  <textarea name="post" cols="60" rows="7"><?php echo $edit; ?></textarea><p>
  		  <input name="Preview" type="submit" id="Preview" value="Preview" />  
  		  <input type="submit" name="Submit" value="Submit" /><p>

	  <input type="hidden" name="MM_insert" value="form1">

          </table>
	  </form>

Link to comment
https://forums.phpfreaks.com/topic/78221-preview-and-submit/
Share on other sites

Basically, to accurately have a preview, there are two methods you could follow:

 

1. Submit the form to a preview page, gather the submitted data, output to the screen and have an "Accept" button that submits a hidden form with all the information on it once again (or you could have the submission stored in the session to avoid having to create that second form). With this method, you can also provide a link back to the form to change any values easily enough.

 

2. Preview the submission in a popup that shows their data. Then, when the accept button is pressed, it targets the initial form in the main window and submits it.

 

Both methods have some security issues you'll need to be sure to address, and I would recommend avoiding the second method simply because you very well could restrict user access if they have popup blockers, etc.

Link to comment
https://forums.phpfreaks.com/topic/78221-preview-and-submit/#findComment-395839
Share on other sites

Thanks but I want the user to submit or preview their form, just like when you post a message on here, you can either submit it without previewing it or preview and then submit it. How do i do that?

 

That's what I showed as step #1 above. You need to submit to a handler page where the action taken on the page is a preview rather than an actual submission to the database. How the buttons are handled is most likely a JavaScript issue changing the action of the form when the button is pressed.

Link to comment
https://forums.phpfreaks.com/topic/78221-preview-and-submit/#findComment-395878
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.