Jump to content

new window - reference form entries in original without submitting


Recommended Posts

I want to create a form to be used by a user entering details to be put into a new listing on the site.  On the form I would like there to be a preview button that will open a new window that will display a preview of the listing using the details they have entered in the form.  This button will not submit the form, there will be a seperate submit button for the user to come back to use in the original window if they are happy with the display in the new window.

So what I need to do is be able to get the values entered into the form in the original window.  Is there away of referencing thm, somthing similar to this I am guessing:

parent.document.formname.inputname.value();

Can anybody help with the correct syntax?
[quote author=taith link=topic=119231.msg488096#msg488096 date=1166529269]
You would either need to use a) javascript or b) ajax
[/quote]

Why?  If it's having two separate buttons, why not just submit it to itself with a condition?  Imagine this...

I have a page that has two html buttons on it, one called Submit and the other called Preview

[code]<?php
if (isset($_POST['Preview'])){
  /*
  Capture all the post variables here and use them to create the preview page
  at the same time, you echo the form again with the values of the form automatically
  filled out using the $_POST variables just captured.
  */
}
else if (isset($_POST['Submit'])){
  /*
  This time the actual form has been submitted so lets process it.
  */
}
?>[/code]

Regards
Huggie
[quote author=taith link=topic=119231.msg488113#msg488113 date=1166533044]
lol... but ajax is the greatest thing since sliced bread ;-) and not that hard to set up... lol
[/quote]

Which is where the problem comes in, overuse and not necessarily fit for purpose.  I remember the launch of Macromedia Flash :)

Huggie
I know how to do it as suggested with two buttons with different names and checking which one has been submitted, but what I want to do is not submit the form, I want to click on the preview button and it be opened into a new seperate window.  The window with the form in it will stay as is ready for submitting, so I do need to be able to refer back to the original window.
OK, I think you've missed my point.  By clicking preview, it does technically submit the form, but it only does what's in that condition, so in essence, it's not actually been submitted.  Nothing's been done with the data.

Regards
Huggie
ok, I think I'll take a back seat on this one.  If I get a chance later on I'll post an example of what I mean, which will submit the form, open a new window with the preview in, and display the original form in the original window with the values still in as they were before you pressed the preview button.

Regards
Huggie
I suppose I can check to see if the preview button was pressed and if so open a new window and send the submitted values to the new window to display the preview, whilst redisplaying the form and populating the fields using the submitted values.

If it was the submit button pressed, I can just go on to process the details as required.
Here's an example of what I meant... You can save this as [b]crform.php[/b] and run it as a test if you like.

[code]<?php
// Required for the session data
session_start();

// Is the form to actually be processed
if (isset($_POST['Submit'])){
  echo "This has been processed, possibly emailed to someone, or saved to a database...<br>\n";
  echo $_POST['data'];
}

// Are we just previewing (in a new window)
else if (isset($_POST['Preview'])){
  echo "This has NOT yet been processed, All we've done is re-echo the form and open a new window...<br>\n";
  $_SESSION['data'] = $_POST['data'];
  // Here's where we open the new window
  echo "<SCRIPT LANGUAGE=\"javascript\">\n<!--\nwindow.open('crform.php?action=preview')\n-->\n</SCRIPT>";
  echo "<form method=\"post\">\n";
  echo "<input type=\"text\" name=\"data\" value=\"".$_POST['data']."\">\n";
  echo "<input type=\"submit\" name=\"Submit\" value=\"Submit\">\n";
  echo "<input type=\"submit\" name=\"Preview\" value=\"Preview\">\n";
  echo "</form>\n";
}

// This is used for the preview window
else if ($_GET['action'] == "preview"){
  echo "This is your preview...<br>\n";
  echo $_SESSION['data'];
}

// Nothing's been done, just show the form
else {
  echo "<form method=\"post\">\n";
  echo "<input type=\"text\" name=\"data\">\n";
  echo "<input type=\"submit\" name=\"Submit\" value=\"Submit\">\n";
  echo "<input type=\"submit\" name=\"Preview\" value=\"Preview\">\n";
  echo "</form>\n";
}
?>[/code]

Regards
Huggie
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.