chiprivers Posted December 19, 2006 Share Posted December 19, 2006 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 Link to comment https://forums.phpfreaks.com/topic/31218-new-window-reference-form-entries-in-original-without-submitting/ Share on other sites More sharing options...
taith Posted December 19, 2006 Share Posted December 19, 2006 you would either need to use a) javascript or b) ajaxand from what i've seen, ajax would be by far easier/faster/better Quote Link to comment https://forums.phpfreaks.com/topic/31218-new-window-reference-form-entries-in-original-without-submitting/#findComment-144369 Share on other sites More sharing options...
HuggieBear Posted December 19, 2006 Share Posted December 19, 2006 [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]<?phpif (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]RegardsHuggie Quote Link to comment https://forums.phpfreaks.com/topic/31218-new-window-reference-form-entries-in-original-without-submitting/#findComment-144373 Share on other sites More sharing options...
taith Posted December 19, 2006 Share Posted December 19, 2006 true... but i was talking about doing it without reloading the page... Quote Link to comment https://forums.phpfreaks.com/topic/31218-new-window-reference-form-entries-in-original-without-submitting/#findComment-144381 Share on other sites More sharing options...
HuggieBear Posted December 19, 2006 Share Posted December 19, 2006 Fair enough, but the overhead of adding AJAX into the equation when (s)he's spawning a new window for the preview anyway, It hardly seems worth it to me.Huggie Quote Link to comment https://forums.phpfreaks.com/topic/31218-new-window-reference-form-entries-in-original-without-submitting/#findComment-144383 Share on other sites More sharing options...
taith Posted December 19, 2006 Share Posted December 19, 2006 lol... but ajax is the greatest thing since sliced bread ;-) and not that hard to set up... lol Quote Link to comment https://forums.phpfreaks.com/topic/31218-new-window-reference-form-entries-in-original-without-submitting/#findComment-144386 Share on other sites More sharing options...
HuggieBear Posted December 19, 2006 Share Posted December 19, 2006 [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 Quote Link to comment https://forums.phpfreaks.com/topic/31218-new-window-reference-form-entries-in-original-without-submitting/#findComment-144387 Share on other sites More sharing options...
chiprivers Posted December 19, 2006 Author Share Posted December 19, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/31218-new-window-reference-form-entries-in-original-without-submitting/#findComment-144389 Share on other sites More sharing options...
HuggieBear Posted December 19, 2006 Share Posted December 19, 2006 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.RegardsHuggie Quote Link to comment https://forums.phpfreaks.com/topic/31218-new-window-reference-form-entries-in-original-without-submitting/#findComment-144392 Share on other sites More sharing options...
chiprivers Posted December 19, 2006 Author Share Posted December 19, 2006 Sorry but I think you have missed my point, I want the preview button to open up a new window and that will not happen if the form is submitted (processing entries or not). Quote Link to comment https://forums.phpfreaks.com/topic/31218-new-window-reference-form-entries-in-original-without-submitting/#findComment-144393 Share on other sites More sharing options...
HuggieBear Posted December 19, 2006 Share Posted December 19, 2006 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.RegardsHuggie Quote Link to comment https://forums.phpfreaks.com/topic/31218-new-window-reference-form-entries-in-original-without-submitting/#findComment-144398 Share on other sites More sharing options...
chiprivers Posted December 19, 2006 Author Share Posted December 19, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/31218-new-window-reference-form-entries-in-original-without-submitting/#findComment-144401 Share on other sites More sharing options...
HuggieBear Posted December 19, 2006 Share Posted December 19, 2006 I'm not sure how that differs from what I suggested!I'll try to come up with some sample code for you later.Huggie Quote Link to comment https://forums.phpfreaks.com/topic/31218-new-window-reference-form-entries-in-original-without-submitting/#findComment-144403 Share on other sites More sharing options...
HuggieBear Posted December 19, 2006 Share Posted December 19, 2006 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 datasession_start();// Is the form to actually be processedif (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 windowelse if ($_GET['action'] == "preview"){ echo "This is your preview...<br>\n"; echo $_SESSION['data'];}// Nothing's been done, just show the formelse { 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]RegardsHuggie Quote Link to comment https://forums.phpfreaks.com/topic/31218-new-window-reference-form-entries-in-original-without-submitting/#findComment-144421 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.