1

I have the following doubt. I want to use php code to create a HTML form which outputs three values. And I want to use that values on a php function, something alike the following:

<?php
     function modcreate(){
        echo "<input type='text' name='dato'>";
        echo "<input type='text' name='nvalor'>";
        echo "<input type='text' name='identif'>";
        echo "<input type='button' onclick=mod($GET['dato'], $GET['nvalor'], 
              $GET['identif']>";
     }
?>

Any suggestions or cleaner ways to do this? Thank you beforehand

3 Answers 3

3

Try this one

<?php
 function modcreate(){
    echo "<input type='text' name='dato'>";
    echo "<input type='text' name='nvalor'>";
    echo "<input type='text' name='identif'>";
    echo "<input type='button' onclick=" . mod($GET['dato'], $GET['nvalor'], 
          $GET['identif'] . ">";
 }
 ?>

You were actually inserting php code inside double quotes which was behaving like a simple string. So close your double quotes before adding php tag

Sign up to request clarification or add additional context in comments.

Comments

0

you dont need to echo html in php

function modcreate(){ 
    ?>   
    <input type='text' name='dato'>
    <input type='text' name='nvalor'>
    <input type='text' name='identif'>
    <input type='button' onclick="mod(<?php (implode(',',[$GET['dato'],$GET['nvalor'],$GET['identif']);?>)">;
    <?php
}

Comments

0

For a better syntax of how to handle html without echo is:

<?php 
function modcreate(){ ?>   
    <input  type='text' name='dato'>
    <input  type='text' name='nvalor'>
    <input  type='text' name='identif'>
    <input  type='button' 
            onclick="mod(
                <?php (implode(',',[$GET['dato'],$GET['nvalor'],$GET['identif']); ?>
            )">
<?php } ?>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.