简体   繁体   中英

Submit button with php variable

<form method="post">
<input type="submit" name="'.$pTest.'" value="submit" id="submit"/>
</form>

<?php
if(isset($_POST[''.$pTest.'']))
{echo 'something'
;}
?>

This doesn't work if I use variable as the name of the submit button. Please some help!

像这样尝试

<input type="submit" name="<?php echo $pTest; ?>" value="submit" id="submit"/>

Your variable is doing nothing. Just echo your <input> name and catch it whith php:

<form method="post">
   <input type="submit" name="<?php echo $pTest ?>" value="submit" id="submit"/>
</form>

<?php

    if (isset($_POST[$pTest])) {

        echo 'something'

    }

?>

Add value to the variable first..

<?php  $pTest = 'sks'; ?>
<form method="post">
<input type="submit" method="post" name="<?php echo $pTest; ?>" value="submit" id="submit"/>
</form>

<?php
if(isset($_POST[$pTest]))
{
    echo '<script>alert("something");</script>';
}
?>

Just replace your quotes with double quotes :

if(isset($_POST["'.$pTest.'"]))
{
    echo 'something'
;}

Or name your input with a PHP variable :

<input type="submit" name="<?php echo $pTest; ?>" value="submit" id="submit"/>

anybody who solve this question? please I need help!

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM