|
-
Oct 28th, 2003, 06:25 PM
#1
Thread Starter
Stuck in the 80s
[Resolved] Two Submit Buttons
I have a form where the user inputs some text. I have a Preview button and a Submit button.
I thought I could have them both as submits, and then check in PHP to see if the preview one is there...but they both are.
So how can I have a preview type option (like vBulletin)?
Last edited by The Hobo; Oct 29th, 2003 at 02:22 PM.
-
Oct 28th, 2003, 06:43 PM
#2
Thread Starter
Stuck in the 80s
Eh, I guess I just had to give them the same name:
Code:
<?php
if (isset($_POST['action'])) {
switch ($_POST['action']) {
case 'submitsave':
submitsave(); break;
default:
create_form();
}
} else {
create_form();
}
function create_form($subject = '', $body = '') {
echo '<form action="work.php" method="post">
<input type="hidden" name="action" value="submitsave" />
<b>Subject</b>: <input type="text" name="subject" value="' . $subject . '" /><br />
<b>Body</b>: <textarea name="body">' . $body . '</textarea><br /><br />
<input type="submit" name="submit" value=" Preview " />
<input type="submit" name="submit" value=" Submit " />
</form>';
}
function submitsave() {
if ($_POST['submit'] == ' Preview ') {
preview();
create_form($_POST['subject'], $_POST['body']);
} else {
echo '<b>Save News...</b>';
}
}
function preview() {
echo '<b>Subject</b>: ' . $_POST['subject'] . '<br />';
echo '<b>Body</b>: ' . $_POST['body'] . '<br /><br />';
}
?>
Is this valid HTML/JavaScript?
-
Oct 28th, 2003, 10:22 PM
#3
Frenzied Member
that is how vBulliten does it.
valid html, that is a tough one. as long as you check for which one is pushed then I don't see a problem. I suppose it is valid as you are submitting the same form.
-
Oct 29th, 2003, 05:05 AM
#4
Valid XHTML 1.0 Transitional, but I can't see any JavaScript
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Oct 29th, 2003, 02:22 PM
#5
Thread Starter
Stuck in the 80s
Originally posted by CornedBee
but I can't see any JavaScript
Good point. I tried various ways to accomplish what I wanted, and some involved Javascript. I just forgot that the solution I posted didn't use Javascript.
Thanks, CB.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|