I cannot seem to find an answer to my question on the internet. I can't help but think it is a stupid mistake, however I have gone over my code at least 6 - 7 times and even took a break to look at it with fresh eyes. If someone could look it over for me, that would be super sweet!
<div id="input_alignment" style="font-size:20px">
<?php
if(!($Valid_Profile == true)){ ?>
...Form that has no issues
<?php }
else{ ?>
<form action="Redact_Profiles.php" style="font-size:19px" method="post">
<input type="hidden" value="<?php echo $Valid_Profile ?>" name="Valid_Profile" />
<input type="hidden" value="<?php echo $Username ?>" name="Username" />
<input type="hidden" value="<?php echo $Password ?>" name="Password" />
<br />
<?php echo $Profile_Username . "<br>"; ?>
<input type="submit" style="font-size:9px" value="Edit" name="" /> <?php echo $Profile_Password . "<br>"; ?>
<br />
<br />
......<br />
<input type="submit" style="font-size:9px" value="Edit" name="" /> <?php echo $Profile_First_Name . "<br>"; ?>
<input type="submit" style="font-size:9px" value="Edit" name="" /> <?php echo $Profile_Last_Name . "<br>"; ?>
<?php echo $Profile_EMail . "<br>"; ?>
<br />
<input type="submit" style="font-size:9px" value="Edit" name="" /> <?php echo $Profile_Location . "<br>"; ?>
<input type="submit" style="font-size:9px" value="Edit" name="" /> <?php echo $Profile_Referee_Password . "<br>"; ?>
<input type="submit" style="font-size:9px" value="Edit" name="" />
</form>
<?php }
?>
</div>
The very last two submit buttons don't work. When I take away the php containing the $Profile_Location and $Profile_Referee_Password, the submit buttons work.
Sorry, what I mean by Doesn't work means that the submit button isn't responding. The page doesn't re-load, and it acts like the submit button is disabled. The submit button looks enabled, but it is like it doesn't want to "press".
After 2 days of headache I have figured it out: When a submit button is outside the bounds of the height and width of any "div", it will not function like a button, but more like a picture. So as a good practice, when a button is not functioning properly, check to see if it is literally "outside" of the container you put it in.
This error doesn't present itself in viewing the source page, or in any error checking. However, if it does, I don't know about it. I am using a Mac, Safari 6, and CS5 Dreamweaver, if anyone is interested.
Related
This question already has answers here:
PHP keep checkbox checked after submitting form
(5 answers)
Closed 2 years ago.
I'm still studying php html, any help is appreciated.
I have code like this:
<form method="post">
<input type="checkbox" id="option1" name="option" value="<?php echo "Hello World!"; ?>" />
<label for="option1"> Do you want to print Hello World? </label> <br />
<input type="checkbox" id="option2" name="option" value="<?php echo "Hello Brother" ?>" />
<label for="option2"> Do you want to print Hello Brother?</label> <br />
<input type="checkbox" id="option3" name="option" value="<?php echo "Hello Human" ?>" />
<label for="option3"> Do you want to print Hello Human?</label> <br />
<br />
<br />
<input type="submit" id="Submit" name="Submit" value="Submit"/>
</form>
<?php
if(empty($_POST["option"])){
echo "You need to choose at least one!";
}
else {
echo "Print successful!";
}
?>
I want to have function that if checked, then print the value in different php file. I also have problem that when I checked and submit, the check mark disappeared.
I want it to be like, if checked then true, print the value. if not checked then false, do not print the value. Any idea? Thank you very much!
You have to use action="#" in form tag and mentioned the page name.
Working Demo: http://phpfiddle.org/main/code/brkr-u9st
<input type="checkbox" id="option1" name="option1" value="<?php echo "Hello World!"; ?>" <?php if(isset($_POST['option1'])) echo "checked='checked'"; ?> />
<label for="option1"> Do you want to print Hello World? </label> <br />
<input type="checkbox" id="option2" name="option2" value="<?php echo "Hello Brother" ?>" <?php if(isset($_POST['option2'])) echo "checked='checked'"; ?> />
<label for="option2"> Do you want to print Hello Brother?</label> <br />
<input type="checkbox" id="option3" name="option3" value="<?php echo "Hello Human" ?>" <?php if(isset($_POST['option3'])) echo "checked='checked'"; ?> />
<label for="option3"> Do you want to print Hello Human?</label> <br />
<br />
<br />
<input type="submit" id="Submit" name="Submit" value="Submit"/>
</form>
<?php
if(empty($_POST["option1"]) && empty($_POST["option2"]) && empty($_POST["option3"]) ){
echo "You need to choose at least one!";
}
else {
if(isset($_POST["option1"])){
echo $_POST["option1"];
}
if(isset($_POST["option2"])){
echo $_POST["option2"];
}
if(isset($_POST["option3"])){
echo $_POST["option3"];
}
}
?>
You need to have your form action attribute pointed to a PHP file. Then that file will receive the data via POST and you can do whatever you'd like with it there. The action attribute looks like this
<form method="post" action="\path\to\phpfile.php">
Also, the reason the check mark and other values disappear is because when you submit the form, it is currently executing the PHP file that code is written in. Essentially resetting everything. You can retain the input values by passing the POST input values into the HTML. It would look like this
<form method="post">
<input type="checkbox" id="option1" name="option1" value="<?php echo "Hello World!"; ?>" <?php if(isset($_POST['option1']){ echo 'checked="checked"';} ?>/>
<label for="option1"> Do you want to print Hello World? </label> <br />
<input type="checkbox" id="option2" name="option2" value="<?php echo "Hello Brother" ?>" <?php if(isset($_POST['option2']){ echo 'checked="checked"';} ?> />
<label for="option2"> Do you want to print Hello Brother?</label> <br />
<input type="checkbox" id="option3" name="option3" value="<?php echo "Hello Human" ?>" <?php if(isset($_POST['option3']){ echo 'checked="checked"';} ?> />
<label for="option3"> Do you want to print Hello Human?</label> <br />
<br />
<br />
<input type="submit" id="Submit" name="Submit" value="Submit"/>
</form>
<?php
if(empty($_POST["option"])){
echo "You need to choose at least one!";
}
else {
echo "Print successful!";
}
?>
Make sure your input values don't have the same name.
I am working on a php project, which is in wordpress, I use to send data from one page and use this data in another page, I am using $_POST to get data from that page. But When I try to get the data in function or in if block it becomes empty, but When I use it out side of function or if block, it works, (works means I get output as I want from that page in echo). How do I make that work in function or if block,
First file from which I send data
<form action="http://localhost/w/download.php" target="_blank" method="post">
<input type="hidden" name="cate" value="'.$categories[0]->name.'" /><br />
<input type="hidden" name="url" value="'.get_permalink().'" /><br />
<div align="center">
<input type="image" alt="Download" height="99" src="https://www.google.co.in/logos/doodles/2016/fathers-day-2016-us-5562299671642112-hp.jpg" width="184" />
</div>
</form>
Second file which I used to get data and make it useful for me.
<?php
if(isset($_POST["downloadfile"])) {
$urls=$_POST['url'];
echo $urls;// Does not show the out put and
//doing something
}
?>
<form method="POST">
<input type="submit" value="DOWNLOAD FILE" name="downloadfile"/>
</form>
But when I try to echo $_POST data outside of if block I got that value which I want Like:
Second file
<?php
$urls=$_POST['url'];
echo $urls; // shows me the link
if(isset($_POST["downloadfile"])) {
//doing something
}
?>
<form method="POST">
<input type="submit" value="DOWNLOAD FILE" name="downloadfile"/>
</form>
It shows me that variable $urls is empty. But when I use it out side of if block and echo it shows me output, that what I want.
Can anyone tell me How do I use this in a function or if block in second file, or I am doing some wrong way, So please tell me the right way.
The most important thing is that If any one want to give this question a down vote, please do that But Please Please Comment below Why Did you do that, I am not a genius php developer like you, I just learn from my mistake
Use if(isset($_POST["url"])) { instead of if(isset($_POST["downloadfile"])) {
Shouldn't the submit be in the first form?
Just put this line:
<input type="submit" value="DOWNLOAD FILE" name="downloadfile"/>
Right below
<input type="image" alt="Download" height="99" src="https://www.google.co.in/logos/doodles/2016/fathers-day-2016-us-5562299671642112-hp.jpg" width="184" />
One file should send all the data, and the other file should get (POST) the data. Put
<?php
if(isset($_POST["downloadfile"])) {
$urls=$_POST['url'];
//doing something
}
?>
At the top of the second file
EDIT
Okay, I did a bit of testing.. I think you're missing the php tags.
First file
<form action="http://localhost/w/download.php" target="_blank" method="post">
<input type="hidden" name="cate" value="' <?php $categories[0]->name ?>'" /><br />
<input type="hidden" name="url" value="'<?php get_permalink() ?>'" /><br />
<div align="center">
<input type="image" alt="Download" height="99" src="https://www.google.co.in/logos/doodles/2016/fathers-day-2016-us-5562299671642112-hp.jpg" width="184" />
<input type="submit" value="DOWNLOAD FILE" name="downloadfile"/>
</div>
download.php
<?php
if(isset($_POST["downloadfile"])) {
$urls=$_POST['url'];
}
echo $urls;
?>
When I run this on my own server, I get errors, but I think that is because I don't have get_permalink() defined.
Edit 2
Here is the first file
<form action="http://localhost/w/download.php" target="_blank" method="post">
<input type="hidden" name="cate" value="<?php $categories[0]->name ?>" /><br />
<input type="hidden" name="url" value="<?php get_permalink() ?>" /><br />
<div align="center">
<input type="image" value="submit" name="downloadfile" alt="Download" height="99" width="184" src="https://www.google.co.in/logos/doodles/2016/fathers-day-2016-us-5562299671642112-hp.jpg" />
</div>
And here is the second
<?php
if(isset($_POST['downloadfile_x'])) { //Name of the image, and x coordinate
$urls=$_POST['url'];
}
echo $urls;
?>
This question already has answers here:
Make a link use POST instead of GET
(11 answers)
Closed 7 years ago.
Is there a way to replicate this in <a href="blah.php">?
<form action="http://localhost/php/suburb_added.php" method="post">
<b>Add a New Suburb</b>
<p>Name:
<input type="text" name="suburb" size="30" value="" />
<input type="submit" id="submit" value="Submit" name="submit" />
</p>
</form>
in suburb_added.php... i have this to capture
if (!empty($_POST['suburb']))
To a table form....
<td align="left"><a href="suburb_added.php"><?php echo $row['id'];?></td>
how to create the items below from a table? The goal is when I click the result from <?php echo $row['id'];?>, I should be able to get the value of "id" and process it in suburb_added.php using similar to if (!empty($_POST['suburb']))
<form action="http://localhost/php/suburb_added.php" method="post">
<input type="text" name="suburb" size="30" value="" />
what do you whant i don't understand?? I can help you
<?php
if(!isset($_POST['submit'])){
?>
<form action="" method="post" name="submit">
<b>Add a New Suburb</b>
<p>Name:
<input type="text" name="suburb" size="30" value="" />
<input type="submit" id="submit" value="Submit" name="submit" />
</p>
</form>
<?php
} else {
//paste here your code from http://localhost/php/suburb_added.php
echo "you doing post in this page.";
}
?>
<!--Try using header
like this:-->
if($_POST)
{
header('location:login-form.php');
}
else
{
echo "";
}
Change the PHP script so it uses $_REQUEST instead of $_POST. This variable combines the contents of $_POST and $_GET. Then you can have a link like
<?php echo $row['id'] ?>
I have this code that fetches information in a file and shows the result. That all works as expected. What I'm not able to do is to export the button value in the function when it is pressed so the value of the pressed button will transfer to a variable in my php function. How can I do that?
Here the code:
<h2>Demmarage script torrent</h2>
<form action="search.php" method="POST">
<input type="text" name="input_value">
<input type="submit" name="submit">
<?php
echo "<br>";
if (isset($_POST['submit'])){
$findme = $_POST['input_value'];
$findme1 = str_replace (" ", ".", $findme);
$savedarr = unserialize(file_get_contents('torrent.bin'));
foreach ($savedarr as $val1){
$mystring = $val1['title'];
if((stripos($mystring, $findme) !== false) or (stripos($mystring, $findme1) !== false)) {
echo "Show trouve: ";
echo $mystring;
?>
<button type="submit" value="<?php echo $val1['link']; ?>" name="editId">Telecharger</button>
<?php
echo "<br>";
}
}
}
if (isset($_POST['editId'])){
//Here i want to import the value of the pressed button to do something
echo "download start";
}
?>
you should use a hidden field, like
<input type="hidden" name="link" id="link" value="<?php echo $val1['link'] ?>" />
After the submit you will be able to get the value with
$_POST['link']
Also, this should be in a form,otherwise the submit will post EVERY field ...
like
foreach(...)
{?>
<form action="" method="POST">
<input type="hidden" name="link" id="link" value="<?php echo $val1['link'] ?>" />
<input type="submit" />
</form>
<?php}
The problem is that you are setting the value twice by <button>value1</button> and by <button value="value2">... remember that the value of a submit button is always the text that shows up inside the button.
You should do replace this:
<button type="submit" value="<?php echo $val1['link']; ?>" name="editId">Telecharger</button>
with this:
<form method="POST">
<input type="hidden" value="<?=$val1['link']?>" name="editId" />
<input type="submit" value="Telecharger" />
</form>
I am trying to access the style attribute of a element in order to display a form however, I get this error: Uncaught TypeError: Cannot read property 'style' of undefined. The example below is a simplified example.
cookies.php
echo "[a href='test.php?flavor=butter']Bake Butter Cookies[/a]";
echo "[a href='test.php?flavor=chocolate'] Bake Chocolate Cookies [/a]";
?>
test.php
switch($cookieType){
case "chocolate":
echo "<script type='text/javascript'>";
echo "document.chocolate.style.display='block'; ";
echo "</script>";
break;
case "oatmeal-raisin":
echo "<script type='text/javascript'>";
echo "document.oatmealraisin.style.display='block'; ";
echo "</script>";
break;
case "butter":
echo "<script type='text/javascript'>";
echo "document.butter.style.display='block'; ";
echo "</script>";
break;
}
?>
<div id="chocolate" style="display:none;">
<form action="<?php echo $_SERVER['php_self']?>">
<input type="hidden" name="type" value="chocolate"/>
What is your name: <input type="text" name="your_name"/>
How many chocolate chips on each cookie? <input type="text" name="chips"/>
How many many cookies? <input type="text" name="cookies"/>
<input type="submit" name="BAKE!"/>
<input type="reset"/>
</form>
</div>
<div id="oatmealraisin" style="display:none;">
<input type="hidden" name="type" value="oatmealraisin"/>
<form action="<?php echo $_SERVER['php_self']?>">
What is your name: <input type="text" name="your_name"/>
How many raisins on each cookie? <input type="text" name="raisins"/>
How many many cookies? <input type="text" name="cookies"/>
<input type="submit" name="BAKE!"/>
<input type="reset"/>
</form>
</div>
<div id="butter" style="display:none;">
<form action="<?php echo $_SERVER['php_self']?>">
<input type="hidden" name="type" value="butter"/>
What is your name: <input type="text" name="your_name"/>
How many many cookies? <input type="text" name="cookies"/>
<input type="submit" name="BAKE!"/>
<input type="reset"/>
</form>
I have never had problems accessing the style attribute of a element before so I am not sure what is the problem. The switch statement does work because the javascript console shows the output of the right case. I need another pair of eyes. Any suggestions?
It's not the style attribute that is the problem, you failed to access the elements themselves.
You are trying to access the elements as if they are global variables in the document object, that is only true in IE in quirks mode. You need to use the getElementById method. Replace:
document.chocolate
with:
document.getElementById('chocolate')
and corresponding for each element.