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 -->
Related
I have an HTML input and button:
<form action="validate.php" method="post">
<!-- THE CODE INSERT -->
<div id="code">
<form>
<label></label>
<input id="input" name="InputText" type="text"/>
</form>
</div>
<!-- THE BUTTON ITSELF -->
<input type="button" id="button" name="myButton"><b>Search Archive</b>
</form>
in my validate.php file I have this switch statement:
<?php
switch ($_POST["InputText"])
{
case "someval":
http_header("someaddress.com");
die();
break;
}
?>
the problem is that when I click the button it doesn't do anything. I did this with JS and it worked but it should be noted that I'm really new to web development so if anyone can explain to me what I did wrong and specifically why that would be great. Thanks!
You have a form inside of a form, that won't work. Also, you need to include an <input type="submit" value="submit" /> before you close your form. This is what submits the information from the form to your action="file.php".
A form would typically look like this:
file.html
<form action="validate.php" method="POST">
<input type="text" name="username" placeholder="Enter your username" />
<input type="submit" name="submit" value="Submit" />
</form>
Then you'd do something like this:
validate.php
<?php
echo "Your username is" . $_POST['username'];
The $_POST['username'] is the data gathered from the name="username" input from the HTML. If you write die($_POST); you'll get all the data that is sent through the form.
When you are using type='button' you have to perform the submit by yourself.
So, you can do that using javascript or change to type='submit'.
Example:
<input type="button" id="button" name="myButton"><b>Search Archive</b>
To
<input type="submit" id="button" name="myButton" value="Search Archive" />
you can try this
<form action="/validate.php" method="post">
<!-- THE CODE INSERT -->
<div id="code">
<label></label>
<input id="input" name="InputText" type="text"/>
</div>
<!-- THE BUTTON ITSELF -->
<button type="submit" id="button" name="myButton">Search Archive</button>
</form>
in the div id ="code" you used form tag that's why its not work...delete it will work and button type must be submit
So i have the following code for the aside which allows the user to search for other user(NOTE: i have left out the aside-tag here in order to make the code more readable):
<form action="index.php" method="POST">
<input id="search" type="text" placeholder="Search for Friends" name="search_name">
<input class="submit" type="submit" name="search-submit" value="Search">
</form>
After than i get the data from the database and display them in a variable whicht is called $output:
<?php
echo #$output;
?>
Ok so now when the user clicks on a name it should load the chatwindow in the aside instead of the search results. So the $output should be replaced with the chat window which has the following code:
<?php
if (isset($_POST['chat-submit'])) {
echo '<form method="POST" action="index.php" class="form-back">
<input class="back" type="submit" name="back" value="←Back">
</form>
<form>
<div class="chatwith"><h1><?php echo $username; echo ":"; ?></div>
<?php echo $finalstatus; ?>
<form action="index.php" method="POST" class="message-form">
<input class="message" type="text" placeholder="message" name="message">
<input class="submit" type="submit" name="message-submit" value="Send">
</form>';
}
?>
ok so both codes are working fine but when i click on one of the $outputs (and activate "chat-submit") than the old form from the search box is still there. How can i remove the old form so that only the chatwindows will be shown. Is there some kind "refresh only the aside"? If you have any questions please ask me.
If you set $refresh to 0 you dont need the if. Because it is always 0. Do like this:
<?php
if(isset($_POST['chat-submit'])) {
echo '//here goes the chat-form but this is too long for this comment. But its the same as above'; }
else {
echo $output;
}
?>
So it does work now this is the right solution from #Dieter Kräutl:
<?php
if(isset($_POST['chat-submit'])) {
echo '<form method="POST" action="index.php" class="form-back">
<input class="back" type="submit" name="back" value="←Back">
</form>
<form>
<div class="chatwith"><h1><?php echo $username; echo ":"; ?></div>
<?php echo $finalstatus; ?>
<form action="index.php" method="POST" class="message-form">
<input class="message" type="text" placeholder="message" name="message">
<input class="submit" type="submit" name="message-submit" value="Send">
</form>'; }
else {
echo $output;
}
?>
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>
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>
<?php
echo $_POST['textvalue'];
echo $_post['radiovalue'];
?>
<div id="hidethis">
<form method="POST" action="">
<label>Tekst Value</label>
<input type="text" name="textvalue">
<label>Radio Value</label>
<input type="radio" name="radiovalue" value="autogivevalue">
<input type="submit" id="submit" name="submit" value="submit">
</div>
http://jsfiddle.net/Bjk89/2/ here is it with the jQuery.
What i try to do is to hide the <div id="hidethis"> when it's clicking submit.
I know i can make another page where i can recieve the values without the <form> section, but i want to put both in one page, make the <div id="hidethis"> hidden after submit.
So i'll be able to get echo $_POST['textvalue']; and echo $_post['radiovalue']; as results
RESULT MUST BE LIKE
A Text // This is the value you input into Tekst Value
autogivevalue // This is the value from the radio button
----- INVISIBLE -----
<form is hidden because we set it in jQuery so>
</form>
Try this. No need to use jQuery here.
<?php
if($_POST) {
echo $_POST['textvalue'];
echo $_post['radiovalue'];
} else {
?>
<form method="POST" action="">
<label>Tekst Value</label>
<input type="text" name="textvalue">
<label>Radio Value</label>
<input type="radio" name="radiovalue" value="autogivevalue">
<input type="submit" id="submit" name="submit" value="submit">
</form>
<?php
}
?>
Try adding '#' in your jquery code. Your version does not have # next to submit. Also your form is missing a closing tag here and in your JSFiddle code.
Try this:
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script>
$(document).ready(function () {
$('#submit').click(function () {
$('form').submit();
$('#hidethis').hide();
});
});
</script>
<form method='post' id="hidethis" name='form'>
<input type="text" name="textvalue">
<input type="radio" name="radiovalue" value="1">
<input type="button" id="submit" name="submit" value="submit">
</form>