Here is my scenario :
I have a html form on my main page where user can enter the data and and submitting the form using post method.
<form id="main" name="main" action="#text" method="post" >
//codes goes here
<input id="generate" type="submit" name="script" value="create output" />
</form>
And the PHP code to process above form is
<?php
echo '<form action="#text" method="post">';
echo '<textarea onclick="this.select()" name="output_textarea" id="output_textarea" cols="100" rows="25" readonly>';
//above form inputs will echo in this textarea
<-------PHP codes for download here---->
<-------PHP codes for email here---->
<input type="submit" id="download" value="Download" name="download"></input>
<input type="submit" id="send" value="send" name="send"></input>
echo '</textarea>';
echo '</form>';
?>
I am echoing the form output to a textarea and I need to have a download button a email button
to save\\send the textarea. Here is issue I am facing is both the submit buttons on the second page executing download php function, not email.
So, How can I assign two separate functions for two submit functions ? download and email ?
I am not using separate php page here instead of that using php code on the same page where I add html.
Buttons are only added to the $_POST when and if they are pressed, and as you can only press one button at a time,
you can just do this or something like it:-
if ( isset( $_POST['download'] ) ) {
do_dowload_stuff();
}
if ( isset( $_POST['email'] ) ) {
do_email_stuff();
}
Change your code to this:
if(isset($_POST['download'])){
// download code here
echo "Download ".$_POST['output_textarea'];
} elseif(isset($_POST['send'])){
// email code here
echo "Email ".$_POST['output_textarea'];
}
echo '<form action="#text" method="post">';
echo '<textarea onclick="this.select()" name="output_textarea" id="output_textarea" cols="100" rows="25" readonly></textarea>';
echo '<input type="submit" id="download" value="Download" name="download"/>';
echo '<input type="submit" id="send" value="send" name="send"/>';
echo '</form>';
?>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.