Reputation: 51
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
Upvotes: 1
Views: 71
Reputation: 1454
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 } ?>
Upvotes: 0
Reputation: 2964
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
Upvotes: 3
Reputation: 1033
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
}
Upvotes: 0