homepage Welcome to WebmasterWorld Guest from 54.197.211.197
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
How to take actions from multiple submit buttons
multiple submit buttons
saideep2007

5+ Year Member



 
Msg#: 3859768 posted 12:37 pm on Feb 28, 2009 (gmt 0)

Hi I'had a problem with Submit buttons.

My clients wants a form which should have two fields

-----------------------------------------------------

Name
Message

Preview(Submit) Cancel(Reset)
-----------------------------------------------------

after filling he should get a preview of that

Like this e.g

-----------------------------------------------------

Name : India
Message : India rocks

Send(submit) Edit(submit) Delete(submit)
-----------------------------------------------------
I had modified all data but i had struck on this
when i had submitted send,edit,delete the page is redirecting

I had used <?php echo $PHP_SELF ?> for this.
I want all the action in the same page

--------------------------------------------------------------------
<?php
session_start();
include "../includes/dbConnection.php";

?>
<html>
<head>
</head>
<body>
<p>Manage Photos >> Add Invitations </p>
<form name="form" action="" method="POST" enctype="multipart/form-data" >
<table border="1" align="center">
<tr>
<td colspan="2" align="center">Add Invitation</td>
</tr>
<tr>
<td>Name : </td><td><input type="text" name="name" value="<?php echo $_POST['name'] ?>"></td></tr>
<tr><td>Invitation message :</td><td><textarea name="message"><?php echo $_POST['message'] ?></textarea></td>
</tr>

<tr><td colspan="2">&nbsp;</td></tr>
<tr><td colspan="2" align="center">

<input type="submit" name="submit" value="Preview">&nbsp;&nbsp;
<input type="reset" name="reset" value="Cancel"></td></tr>
</table>

<br><br><br>
<?php
if($_POST['submit'])
{
$insert = mysql_query("insert into invitations
(inv_id,name,message)
values('','$_POST[name]','$_POST[message]')")or die("Unable to Insert :".mysql_error());
$insertid = mysql_insert_id();

$_SESSION['ins'] = $insertid;

$select = mysql_query("select * from invitations where inv_id='$insertid' ");
echo "select * from invitations where inv_id='$insertid' ";
$r = mysql_fetch_array($select);
?>

<?php
if(isset($_POST['send']))
{
$to = "saideep@example.com";

$subject = "Invitation from Eye-raters";

$body= "Name :";

$body.= stripslashes($_POST['ed_name']);

$body .= "\nMessage:";

$body .= stripslashes($_POST['ed_message']);

$from = "support@example.com";

$headers = "From:$from";

mail($to,$subject,$body,$headers);

//echo "<script language=javascript>window.location=\"index.php\";alert(\"Mailed Succesfully\");</script>";
echo "<center>Mailed succesfully<center>";
}

if(isset($_POST['edit']))
{
$update = mysql_query("update invitations set
name='$_POST[ed_name]',
message='$_POST[ed_message]' where inv_id='$insertid' ")or die("Unable to Update :".mysql_error());
echo "<center>update invitations set
name='$_POST[ed_name]',
message='$_POST[ed_message]' where inv_id='$insertid'<center>";

}

if(isset($_POST['cancel']))
{

$delete = mysql_query("delete from invitations where inv_id='$insertid' ")or die("Unable to delete :".mysql_error());
echo "<center>Deleted succesfully<center>";

}

?>
<?php

/*switch ($_POST['sub']) {


case 'Send Invitation':
$to = "saideep@example.com";

$subject = "Invitation from Eye-raters";

$body= "Name :";

$body.= stripslashes($_POST['ed_name']);

$body .= "\nMessage:";

$body .= stripslashes($_POST['ed_message']);

$from = "support@example.com";

$headers = "From:$from";

mail($to,$subject,$body,$headers);

//echo "<script language=javascript>window.location=\"index.php\";alert(\"Mailed Succesfully\");</script>";
echo "<center>Mailed succesfully<center>";
break;

case 'Edit':
$update = mysql_query("update invitations set
name='$_POST[ed_name]',
message='$_POST[ed_message]' where inv_id='$insertid' ")or die("Unable to Update :".mysql_error());
break;


case 'Cancel':
$delete = mysql_query("delete from invitations where inv_id='$insertid' ")or die("Unable to delete :".mysql_error());
echo "<center>Deleted succesfully<center>";
break;
}
*/
?>

<!-- <form name="theForm" method="POST" enctype="multipart/form-data" > -->

<table border="1" align="center">
</tr>
<tr><td>Name : </td><td><input type="text" name="ed_name" value="<?php echo $r['name'] ?>"></td></tr>
<tr><td>Invitation message :</td><td><textarea name="ed_message"><?php echo $r['message'] ?></textarea></td></tr>

<tr>
<td colspan=3 align=center>
<input type="submit" name="send" value="Send Invitation">
&nbsp;&nbsp;
<input type="submit" name="edit" value="Edit">
<input type="submit" name="cancel" value="Cancel"></td>

</tr>

<!--
<tr>
<td colspan=3 align=center>
<input type="submit" name="sub" value="Send Invitation" onClick="document.theForm.action='send.php'">
&nbsp;&nbsp;
<input type="submit" name="sub" value="Edit" onClick="document.theForm.action='<?php echo $PHP_SELF ?>'">
<input type="submit" name="sub" value="Cancel" onClick="document.theForm.action='cancel.php'"></td>

</tr>
-->
</table>
</form>

<?php
}
?>
</body>
</html>

--------------------------------------------------------------------
Solution by you is appreciated

Regards
saideep

[edited by: eelixduppy at 8:33 pm (utc) on Feb. 28, 2009]
[edit reason] exemplified [/edit]

 

ag_47

5+ Year Member



 
Msg#: 3859768 posted 7:36 pm on Feb 28, 2009 (gmt 0)

I didn't look through all your code, but if you have multiple submit buttons, just give them separate names and check which one is set

if(isset($_POST['sub_finish']))
..
elseif(isset($_POST['sub_edit']))
..

saideep2007

5+ Year Member



 
Msg#: 3859768 posted 4:53 am on Mar 2, 2009 (gmt 0)

Thanks ag_47 for reply but.I already tried out.

i have changed the form submit buttons name like this

<tr>
<td colspan=3 align=center>
<input type="submit" name="send" value="Send Invitation">
&nbsp;&nbsp;
<input type="submit" name="edit" value="Edit">
<input type="submit" name="cancel" value="Cancel"></td>

</tr>

I tried

Switch case
and your's solution

My problem is after submitting the page shouldn't redirect

at first submit button Its inserting values in DB

Send button ---->for submitting this values to mail
Edit button ---->To edit the values
Cancel button--->To delete the record

After click any button.I must able to stay in the same page

Kindly reply me

Waiting for some better reply's

Thanks

coopster

WebmasterWorld Administrator coopster us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 3859768 posted 2:48 pm on Mar 2, 2009 (gmt 0)

I don't see any php header() [php.net] functions in your code so it must be your JavaScript redirects causing you issues. Don't use them if you do not want to redirect.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved