Yuriy T. Yuriy T. - 2 years ago 74
HTML Question

PHP multiple input buttons with same textarea

Could someone help me with such issue (I'm quite new at php, thus small help needed)...

I have a text area, where I can enter one or several project Nr's, and I want to have two buttons, which are working based on SQL query : first one will show results on a page, second one exports the data in Excel.

Part where data is being displayed on a web page directly is already working for me. But how can I make so, that based on the second input button (Export to Excel) it will trigger different part of code, but using same values from text area?

Currently my problem is that when I'm pressing second button it also triggers part of the code, where I'm showing data on a web page and I need to ignore that while exporting to excel.

Currently part of my HTML looks like :

<form action="main" method="post">
<textarea name="project1" cols="30" rows="5" type="submit" placeholder="Enter Project Number('s)"/></textarea>
<input value=" Submit " type="submit"/> <!-- Shows on web page -->
<input name="excel" type="submit" value=" Export to Excel " /> <!-- Exports to Excel -->

Answer Source


         echo $_POST['project1'] . "<br />\n";
    if(isset($_POST['excel'])) {
        echo "put your excel export script here";


<form method="post">
    <textarea name="project1" cols="30" rows="5" placeholder="Enter Project Number('s)"/></textarea>
    <input name="displayPage" type="submit"  value=" Submit " /> 
    <input name="excel" type="submit" value=" Export to Excel " /> 

1) As Fred -ii has already pointed out, textarea doesn't have a type.

2) If you want to have more than one submit button in the form, you should give each of them an unique name

3) Once you have named them, you can use if(isset($_POST['nameOfButton1'])), if(isset($_POST['nameOfButton2']))to perform different functions on the post to script.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download