Ravens PHP Scripts: Forums
 

 

View next topic
View previous topic
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> PHP
Author Message
Darrell3831
Worker
Worker



Joined: Feb 18, 2004
Posts: 244

PostPosted: Sun Mar 21, 2004 5:46 pm Reply with quote

How do you set up a form so that it can have two different submissions buttons?

I want to have a submit and a preview button.

This isent right:

Code:
echo "<form method=\"post\" action=\"admin.php\"><input type=\"hidden\" name=\"op\" value=\"insertCourse\"><input type=\"hidden\" name=\"cid\" value=\"$cid\">"

.
.
.
echo "<br><br>"
 ."<input type=\"submit\" name=\"op\" value=\""._PREVIEW."\">&nbsp;&nbsp;"
 ."<input type=\"submit\" name=\"op\" value=\""._COURSE_ADD."\">&nbsp;&nbsp;";


I have never seen the syntax for two submit buttons.

Thanks,
Darrell

_________________
http://www.psy-center.com 
View user's profile Send private message Visit poster's website
Raven
Site Admin/Owner



Joined: Aug 27, 2002
Posts: 17088

PostPosted: Sun Mar 21, 2004 6:24 pm Reply with quote

This, of course, is as much an HTML issue as a PHP issue Smile Actually, your syntax is correct. Your php program will have to test for the value of $op and then respond accordingly. Does that make sense? Here's a quick snippet to demonstrate
Code:
<form method="post">

<input type="submit" name="op" value="Preview">&nbsp;&nbsp;
<input type="submit" name="op" value="Submit">&nbsp;&nbsp;
</form>
<?
if (isset($_POST['op'])) {
   if ($_POST['op']=='Preview') {
      echo 'Do Preview Stuff Here';
   }
   else if ($_POST['op']=='Submit') {
      echo 'Do Submit Stuff Here';
   }
}
?>
 
View user's profile Send private message
Darrell3831







PostPosted: Sun Mar 21, 2004 7:16 pm Reply with quote

Thanks for taking the time to respond. I'm not sure I understand where the isset test goes.

My function was working before I decided I wanted to add the ability to preview the submission.

Here's what I have now.

Code:
/* Add Course */

function addCourse() {
   
   if (is_super()) {
      include("header.php");
      universityMenu();
      OpenTable();
       echo "<center><font class=\"title\"><b>"._COURSE_ADD."</b></font><br><br>"
         ."<font class=\"content\"><i>"._COURSE_ADVICE."</i></font></center><br>";
       CloseTable();
       echo "<BR>";
      OpenTable();
//       echo "<form method=\"post\" action=\"admin.php\"><input type=\"hidden\" name=\"op\" value=\"insertCourse\"><input type=\"hidden\" name=\"cid\" value=\"$cid\">" // original
       echo "<form method=\"post\" action=\"admin.php\"><input type=\"hidden\" name=\"cid\" value=\"$cid\">"  // testing
         ."<font class=\"option\"><b>"._COURSE_ADD."</b></font><br><br>"
         .""._UNIVERSITY_TITLE.": <input type=\"text\" name=\"title\" size=\"50\" value=\"$title\"><br><br>"
         .""._UNIVERSITY_DESCRIPTION.":<br><textarea name=\"description\" cols=\"90\" rows=\"15\">$description</textarea><br>"
          ."<font class=\"content\">"._HTMLALLOWED."<br>";
      displayAllowedHTML();
      echo "<br><br>"
         .""._COURSE_PRICE.": $<input type=\"text\" name=\"price\" size=\"6\" maxsize=\"6\" value=\"$price\"><br><br>"
         .""._UNIVERSITY_STATUS.": <select name=\"status\">";
         if ($status==0) {
            echo "<option value=\"0\"selected>inactive</option>"
            ."<option value=\"1\">active</option>";
         } else {
            echo "<option value=\"0\">inactive</option>"
            ."<option value=\"1\"selected>active</option>";
         }   
      echo "</select><br><br>"
      ."<input type=\"submit\" name=\"op\" value=\""._PREVIEW."\">&nbsp;&nbsp;" // testing
      ."<input type=\"submit\" name=\"op\" value=\""._COURSE_ADD."\">&nbsp;&nbsp;" // testing
//      ."<input type=\"submit\" value=\""._COURSE_ADD."\">" // original
      ."</form>";
       CloseTable();
      displayCopyright();
      include("footer.php");
   } else {
      accessDenied(2);
   }
}


If I take the hidden op value out at the top of the form and then add two new op values at the bottom of the form, where would I put the isset test?

Originally I was branching off the switch statement at the bottom of the course functions.

Code:
//   case "insertCourse":

   case ""._COURSE_ADD."":
   courseInsert($title, $description, $price, $status);
   break;


I don't understand how the program is supposed to flow after the submit buttons.

Sorry,
Darrell
 
Darrell3831







PostPosted: Mon Mar 22, 2004 2:21 pm Reply with quote

Nevermind,

I got it a little bit closer to working. I needed to include the language file in the the case file.

I'll letcha' know if I can't get it...

Thanks,
Darrell
 
Display posts from previous:       
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> PHP

View next topic
View previous topic
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Powered by phpBB © 2001-2007 phpBB Group
All times are GMT - 6 Hours
 
Forums ©