/    Sign up×
Community /Pin to ProfileBookmark

2 submit buttons?

Hi all,

i am developing a php content management system that adds products
to a database.

i have a form to add product images, titles, text and other info to the database and have done this no problem.

what i want to do is have a preview button next to the submit button
which when clicked will open a preview page of the entered information.

how do i pass the entered text to preview.php without processing the form.
i have done this before with javascript somthing like
var myvar = document.myform.field1.value;

is there a way of doing this with php? the sending these variable to the preview.php page?

cheers in advance for any help.

to post a comment
PHP

7 Comments(s)

Copy linkTweet thisAlerts:
@NogDogDec 11.2005 — HTML:
[code=html]
<form>
<!-- form content here, then... -->
<input type='submit' name='preview' value='Preview Page'>
<input type='submit' name='submit' value='Submit Data'>
</form>
[/code]

PHP:
[code=php]
if(isset($_POST['preview']))
{
# do the preview processing here
}
elseif(isset($_POST['submit']))
{
# do the form processing here
}
else
{
# got here without posting the form, display error
}
[/code]
Copy linkTweet thisAlerts:
@andyshepauthorDec 11.2005 — cheers nogdog.

i will be able to sort somthing out with that ... ta
Copy linkTweet thisAlerts:
@ShrineDesignsDec 11.2005 — in most browsers you can do this&lt;input name="s1" type="submit" value="Submit"&gt;
&lt;input name="s1" type="submit" value="Preview"&gt;
[code=php]<?php
if($_POST)
{
if($_POST['s1'] == 'Submit')
{
// ...
}
else
{
// ...
}
}
?>[/code]
Copy linkTweet thisAlerts:
@andyshepauthorDec 12.2005 — Hi again.

Ive got it working fine now..

but one more thing.

if the preview button is pressed i want to open it in a new window ( target='blank' )

if the submit button is pressed i want it to open in the current window. :eek:

is there a way to do this with php? or will i have to use javascript?

Cheers
Copy linkTweet thisAlerts:
@andyshepauthorDec 12.2005 — ok i take it that it cant be done...

plan B....

is there a way of emulating the browser back button?

so that i wont have to pass back the variables to the previous page if i just link to it.

cheers andy
Copy linkTweet thisAlerts:
@ShrineDesignsDec 12.2005 — try this&lt;input name="s1" type="submit" value="Submit"&gt;
&lt;input name="s1" type="submit" value="Preview" onclick="this.form.target='_blank'"&gt;
Copy linkTweet thisAlerts:
@NogDogDec 12.2005 — [code=php]
if(!empty($_SERVER['HTTP_REFERER']))
{
$target = $_SERVER['HTTP_REFERER'];
$label = 'Back to Previous Page';
}
else
{
$target = 'http://www.yourdomain.com/homepage.php';
$label = 'Back to Home Page';
}
# at this point, either make a button:
echo "<form action='$target' method='post'><input type='submit' value='$label'></form>";

# or make a link:
echo "<a href='$target'>$label</a>";
[/code]
×

Success!

Help @andyshep spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.4,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...