Jump to content


Photo

Multiple submit buttons


  • Please log in to reply
4 replies to this topic

#1 mattennant

mattennant
  • Members
  • PipPipPip
  • Advanced Member
  • 42 posts

Posted 16 June 2005 - 01:44 PM

hello
I have a form for DJ's to enter the details of the clubs they DJ at, on completing the form i want to offer the user 2 options

option one - to submit the data and continue to the next step of the form

option two - to submit the data and reset the existing form to enable them to submit details of further clubs.

Is it possible to do this from multiple submit buttons on one page?

any help appreciated

#2 virtual_odin

virtual_odin
  • Members
  • PipPipPip
  • Advanced Member
  • 47 posts
  • LocationLondon, England

Posted 16 June 2005 - 02:05 PM

This is possible

Step 1 set up the form with the two buttons, giving them distinct names like
<form method=post action='page.php'>
// your form fields
<input type='submit' value='Displayname1', name='button'>
<input type='submit' value='Displayname2', name='button'>
</form>

Step 2 in the page which the form calls, 'page.php' in the example, create a branch for which button is pressed like

if ($button == "Displayname1"){// set of commands}

elseif ($button == "Displayname2"){// set of commands}

Hope that helps

EDIT: Oops the earlier code had an error in it now corrected

#3 mattennant

mattennant
  • Members
  • PipPipPip
  • Advanced Member
  • 42 posts

Posted 17 June 2005 - 07:42 AM

Thanks for your help
i kind of understand the principle but the problem is dreamweaver is doing most of my coding. (i'm trying to break this habit) When i try and insert your suggestion, dreamweaver spews out errors. I'll post you the code with the hope you may be able to make some sense of it, apologies though, i know there's a lot of it.
cheers

<?php
session_start(); ?><?php require_once('Connections/mattyboy.php'); ?>
<?php
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue;

switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
$insertSQL = sprintf("INSERT INTO upshotaltclubvenues (email, clubname, clubaddressline1, clubaddressline2, clubtown, nightofthewek, capacity, promoter, promotertelephonenumber, promoteremail, albumplayback, dvdscreens, liveacts, celebritydjs, productpromotion) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
GetSQLValueString($_POST['email'], "text"),
GetSQLValueString($_POST['clubname'], "text"),
GetSQLValueString($_POST['clubaddressline1'], "text"),
GetSQLValueString($_POST['clubaddressline2'], "text"),
GetSQLValueString($_POST['clubtown'], "text"),
GetSQLValueString($_POST['nightoftheweek'], "text"),
GetSQLValueString($_POST['capacity'], "text"),
GetSQLValueString($_POST['promoter'], "text"),
GetSQLValueString($_POST['promotertelephonenumber'], "text"),
GetSQLValueString($_POST['promoteremail'], "text"),
GetSQLValueString(isset($_POST['albumplayback']) ? "true" : "", "defined","'Y'","'N'"),
GetSQLValueString(isset($_POST['dvdscreens']) ? "true" : "", "defined","'Y'","'N'"),
GetSQLValueString(isset($_POST['liveacts']) ? "true" : "", "defined","'Y'","'N'"),
GetSQLValueString(isset($_POST['celebritydjs']) ? "true" : "", "defined","'Y'","'N'"),
GetSQLValueString(isset($_POST['productpromotion']) ? "true" : "", "defined","'Y'","'N'"));

mysql_select_db($database_mattyboy, $mattyboy);
$Result1 = mysql_query($insertSQL, $mattyboy) or die(mysql_error());

$insertGoTo = "reg2_1.php";
if (isset($_SERVER['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));
}

mysql_select_db($database_mattyboy, $mattyboy);
$query_venues = "SELECT * FROM upshotaltclubvenues";
$venues = mysql_query($query_venues, $mattyboy) or die(mysql_error());
$row_venues = mysql_fetch_assoc($venues);
$totalRows_venues = mysql_num_rows($venues);
?>

<form action="<?php echo $editFormAction; ?>" method="POST" name="form1">

#4 virtual_odin

virtual_odin
  • Members
  • PipPipPip
  • Advanced Member
  • 47 posts
  • LocationLondon, England

Posted 17 June 2005 - 12:19 PM

I am not familiar with dreamweaver. I have abandoned these sort of apps because they load the pages and the web site with so much extraneous guff 'just in case' that it is hard to unravel, as you are finding. Trouble is: break one of dreamweaver's little quirks and the page falls over. At least that's what I found with frontpage before seeing the light.

#5 mattennant

mattennant
  • Members
  • PipPipPip
  • Advanced Member
  • 42 posts

Posted 20 June 2005 - 01:46 PM

i think you are right
a new direction is in order
thanks for your help




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users