Jump to content

Multiple submit buttons


Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/2358-multiple-submit-buttons/
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/2358-multiple-submit-buttons/#findComment-7745
Share on other sites

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">

Link to comment
https://forums.phpfreaks.com/topic/2358-multiple-submit-buttons/#findComment-7747
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/2358-multiple-submit-buttons/#findComment-7748
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.