So, i'm new here as well new to html, i'm reading some sites(for some hours now) and as far as i can tell my code should work, but it dosen't...
I just want to click a button and recieve it's name as echo. But when I click noting happen.
Any good soul to help out? :P
<head>
<title>Index</title>
</head>
<body>
<div>
<input type="submit" name="insert" value="insert" >
<input type="submit" name="select" value="select" >
</div>
<?php
if (isset( $_GET['insert'])) {
echo "insert";
}
if ( isset( $_GET['select'] ) ) {
echo "select";
}
?>
</body>
submit button works with form because only form can be submit so u can try with :
<form method="get" name="frm">
<input type="submit" name="select" value="select" >
</form>
please insert your div into a form like
<head>
<title>Index</title>
</head>
<body>
<form method="get" action="">
<div>
<input type="submit" name="insert" value="insert" >
<input type="submit" name="select" value="select" >
</div>
</form>
<?php
if (isset( $_GET['insert'])) {
echo "insert";
}
if ( isset( $_GET['select'] ) ) {
echo "select";
}
?>
</body>
Just add form tags like this
<form>
<input type="submit" name="insert" value="insert" >
<input type="submit" name="select" value="select" >
</form>
you can write the form tag or use below code on top right of the page
if(isset($_POST['insert'])){
...
}
if(isset($_POST['select'])){
...
}
Check This
<html>
<head>
<title>Index</title>
</head>
<body>
<div>
<form method="GET" action="#">
<input type="submit" name="insert" value="insert" >
<input type="submit" name="select" value="select" >
</from>
</div>
</body>
</html>
<?php
if (isset( $_GET['insert'])) {
echo "insert";
}
if ( isset( $_GET['select'] ) ) {
echo "select";
}
?>
Please first Define method in form.
<form method="GET" action="#">
<input type="submit" name="insert" value="insert" >
<input type="submit" name="select" value="select" >
</form>
Related
I have a site where I make a payment, a bill is created through it, but the problem is that I can not use $ _POST twice in one, and this example:
<? if (isset($_POST['submit'])) { ?>
<form action="" method="POST" >
<input name="invoice" value="" type="text" />
<input name="pay" value="Pay Now" type="submit" />
</form>
<? } if (isset($_POST['pay'])) {
// MY QUERY HERE
// HEADERS HERE
} else { ?>
<form action="" method="POST" >
<input name="info" value="" type="text" />
<input name="submit" value="Submit" type="submit" />
</form>
<? } ?>
Try this.
Kindly check the code for comment.
<?
if (isset($_POST['submit'])) {
$info = $_POST['info'];
// use echo to display second form
echo '
<form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>" method="POST" >
<!-- // Note the action value, it's for post back. This allow you to post back to the current page -->
<!-- This is to keep the record passed from the first form -->
<input name="info" value="'. $info .'" type="hidden" />
<input name="invoice" value="" type="text" />
<input name="pay" value="Pay Now" type="submit" />
</form>';
} else if (isset($_POST['pay'])) {
// MY QUERY HERE
} else {
// Note the action value, it's for post back. This allow you to post back to the current page
<form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>" method="POST" >
<input name="info" value="" type="text" />
<input name="submit" value="Submit" type="submit" />
</form>
}
?>
Not the prettiest way to do this but to achieve your result try this...
<?php if (isset($_POST['submit'])) { ?>
<form action="" method="POST" >
<input name="invoice" value="" type="text" />
<input name="pay" value="Pay Now" type="submit" />
</form>
<?php } elseif (isset($_POST['pay'])) {
// Perform query here
} else { ?>
<form action="" method="POST" >
<input name="info" value="" type="text" />
<input name="submit" value="Submit" type="submit" />
</form>
<?php } ?>
is possible to show the 2nd form? after clicked the 1st form submit button? and is there a way to hide the second form?
example
<?php
if(isset($_POST['submit']))
{ #show form 2
}
?>
<form action="" method="post" name="form1">
<input type="submit" name="submit">
</form>
if theres a way to hide form 2
<form action="" method="post" name="form2">
<input type="submit" name="submit">
</form>
thanks in advance fellow web developers
Yes. Move the condition down.
<form action="" method="post" name="form1">
<input type="submit" name="submit">
</form>
<?php if (isset($_POST['submit'])) { ?>
<form action="" method="post" name="form2">
<input type="submit" name="submit">
</form>
<?php } ?>
But note that, you have the same name in both the form's submit button, so it is better to disable the previous form's submit:
<form action="" method="post" name="form1">
<input type="submit" name="submit"<?php if (isset($_POST['submit'])) { echo ' disabled="disabled"'; } ?>>
</form>
<?php if (isset($_POST['submit'])) { ?>
<form action="" method="post" name="form2">
<input type="submit" name="submit">
</form>
<?php } ?>
Hi i need help because this is not working:
I just wanted to open websites with buttons but in a search box.....
<html>
<body>
<form>
<input type=button onClick=window.open("action.php","demo","width=550,height=300,left=150,top=200,toolbar=0,status=0,"); value="Öffne">
</form>
<form method="post" action="action.php">Suche: <input name="suche" type="text"><br>
<input type="submit" value="OK">
</form>
</body>
</html>
<php
$user = $_POST['suche'];
$seite = 'www.google.de/#q=';
$ziel=$seite.$user;
<form>
<input type=button onclick="location.href='https://www.google.de/#q=<?php echo $seite; ?>'" value='Website'>
<input type=button onClick="self.close();" value="Close this window">
</form>
You have more quotes missing on html tag attr and also php closing tags try
<html>
<body>
<form>
<input type="button" onClick='window.open("action.php","demo","width=550,height=300,left=150,top=200,toolbar=0,status=0,");' value="Öffne">
</form>
<form method="post" action="action.php">Suche: <input name="suche" type="text"><br>
<input type="submit" value="OK">
</form>
</body>
</html>
<?php
$user = $_POST['suche'];
$seite = 'www.google.de/#q=';
$ziel=$seite.$user;
?>
<form>
<input type="button" onclick="location.href='https://www.google.de/#q=<?php echo $seite; ?>'" value='Website'>
<input type="button" onClick="self.close();" value="Close this window">
</form>
Now I have a last question, I want to put both files index.html and action.php in one file. So if I go on Index.html i just have to enter my value for 'suche' and klick on submit button ('ok') to save the value of 'name' into '$input' and then klick on one of the buttons google,proxer,.... to search on that websites.
(maybe if it is possible I can merge the submit btton ('OK') and the buttons (google,proxer,...) to make it cleaner)
For example the link for google + $input would be: $seite_google.$input;
My code now looks like:
For index.php:
<?php
$input = $_POST['suche'];
$seite_google = 'https://www.google.de/#q=';
$seite_myanimelist = 'http://myanimelist.net/anime.php?q=';
$seite_anisearch = 'http://de.anisearch.com/anime/index/?char=all&text=';
$seite_proxer = 'http://proxer.me/search?name=';
?>
<form>
<input type="button" onclick="location.href='<?php echo $seite_google.$input; ?>'" value='Google Suche'>
<input type="button" onclick="location.href='<?php echo $seite_myanimelist.$input; ?>'" value='MyAnimeList'>
<input type="button" onclick="location.href='<?php echo $seite_anisearch.$input; ?>&q=true'" value='AniSearch'>
<input type="button" onclick="location.href='<?php echo $seite_proxer.$input; ?>&sprache=alle&typ=all&genre=&nogenre=&sort=name&length=&length-limit=down#search'" value='Proxer'>
</form>
<html>
<body>
<form method="post" action="">Suche: <input name="suche" type="text"><br>
<input type="submit" value="OK" name="submit">
</form>
</body>
</html>
I want a button to show up if an if statement in php is true. To my knowledge you can't use html in php, so how do i do it?
This is the code:
<!-- begin of form -->
<form method="post" action="something.php">
<input type="text" name="something" required="required" />
<input type="submit" name="submit" value="Submit">
</form>
<?php
if(isset($_POST["submit"]))
{
$something = $_POST["something"];
if($something == "blabla")
{echo"yes blabla";}
//this is where i would like to have a button
<form method="link" action="someurl.com">
<input type="submit" value="Go">
</form>
// end button
} ?>
<!-- end of form -->
Tried to do it this way. leave a gap in the php code, and catch the last accolade from the if isset construction in a separate php part, but now it takes the if always for true.
<!-- begin of form -->
<form method="post" action="something.php">
<input type="text" name="something" required="required" />
<input type="submit" name="submit" value="Submit">
</form>
<?php
if(isset($_POST["submit"]))
{
$something = $_POST["something"];
if($something == "blabla")
{echo"yes blabla";}
?>
//this is where i would like to have a button
<form method="link" action="someurl.com">
<input type="submit" value="Go">
</form>
// end button
<?php } ?>
<!-- end of form -->
Any help would be really appreciated, thanks is advance!
i've searched thouroughly, but couldn't find a similar question.
Please redirect me if there are similar qustions with answers.
PS sorry for my bad english, but i'm a dutchman..
<!-- begin of form -->
<form method="post" action="something.php">
<input type="text" name="something" required="required" />
<input type="submit" name="submit" value="Submit">
</form>
<?php
if(isset($_POST["submit"]))
{
$something = $_POST["something"];
if($something == "blabla")
{echo"yes blabla";
?>
//this is where i would like to have a button
<form method="link" action="someurl.com">
<input type="submit" value="Go">
</form>
// end button
<?php } ?>
<!-- end of form -->
You can output it by making a whole html block php-dependent:
$test = 1;
if ($test) { ?>
<button>Good</button>
<?php }
else { ?>
<button>Bad</button>
<?php }
Will output the button when the condition is 1. There's another method, however not normally recommended as it makes your code messier:
$test = 1;
if ($test)
echo "<button>Good</button>";
else
echo "<button>Bad</button>";
You can switch between HTML and PHP any time you want by opening <?php and closing ?>
<?php
if(isset($_POST["submit"]))
{
$something = $_POST["something"];
if($something == "blabla")
{
echo "yes blabla";
?>
<form method="link" action="someurl.com">
<input type="submit" value="Go">
</form>
<?php
}
}
?>
Indentation and alternative control statements can be prettier
<!-- begin of form -->
<form method="post" action="something.php">
<input type="text" name="something" required="required" />
<input type="submit" name="submit" value="Submit">
</form>
<?php
if(isset($_POST["submit"])):
$something = $_POST["something"];
if($something == "blabla"):?>
yes blabla
<?php endif;?>
//this is where i would like to have a button
<form method="link" action="someurl.com">
<input type="submit" value="Go">
</form>
// end button
<?php endif; ?>
<!-- end of form -->
i am a beginner in php and my first task is to build a calculator and I am here to ask how to get a value from a button and just echo it on the same page. I am trying through method post using isset but enable to display any value on the same page.
<form action="" method="POST">
<input type="button" value="0" name="zero">
</form>
<?php
if (isset($_POST["zero"]))
{
echo $_POST["zero"];
}
?>
Only an input[type=submit] will submit the form onclick. It is valid to have multiple submit buttons:
<form action="" method="POST">
<input type="submit" value="0" name="mybutton">
<input type="submit" value="1" name="mybutton">
<input type="submit" value="2" name="mybutton">
</form>
<?php
if (isset($_POST["mybutton"]))
{
echo $_POST["mybutton"];
}
?>
If you want to use input[type=button] then you will need some Javascript to trigger the submit, and a hidden input to transport the value.
<script>
window.onload = function(){
document.getElementsByName("mybutton").onclick = function(){
document.getElementsByName("postvar")[0].value = this.value;
document.forms.myform.submit();
}
};
</script>
<form name="myform" action="" method="POST">
<input type="hidden" name="postvar" value="" />
<input type="button" value="0" name="mybutton">
<input type="button" value="1" name="mybutton">
<input type="button" value="2" name="mybutton">
</form>
<?php
if (isset($_POST["postvar"]))
{
echo $_POST["postvar"];
}
?>
Change
<input type="button" value="0" name="zero">
To
<input type="submit" value="0" name="zero" />
Add an event handler if you want to do it via button click.
Try this
<form action="" method="POST">
<input type="submit" value="0" name="zero">
</form>
<?php
if (isset($_POST["zero"]))
{
echo $_POST["zero"];
}
?>
Use
<input type="submit" value="0" name="zero">
else if you want to use button use javascript
<form action="" method="POST">
<input type="button" value="0" name="zero">
</form>
<script type="text/javascript">
$("input[type='button']").click(function(){
alert(this.value);
});
</script>