Welcome to WebmasterWorld Guest from 23.20.137.66

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

How to take actions from multiple submit buttons

multiple submit buttons

     
12:37 pm on Feb 28, 2009 (gmt 0)

5+ Year Member



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]

7:36 pm on Feb 28, 2009 (gmt 0)

5+ Year Member



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']))
..

4:53 am on Mar 2, 2009 (gmt 0)

5+ Year Member



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

2:48 pm on Mar 2, 2009 (gmt 0)

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



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.
 

Featured Threads

Hot Threads This Week

Hot Threads This Month