Submitting from table row PHP - php

How to make something like this:
<td>
<?php echo $row['id']; ?>
</td>
to act like this:
<form action="test.php" method="post">
<div class="form-group">
<input type="text" class="form-control" name="input" />
</div>
<button type="submit" name="action">Show</button>
</form>
By other words, when I fill the form-control with some value and press "Show", the desired action performs.
I want to make the same action by pressing the link in the table.

Solved
Just : if (isset($_GET['input'])){…….}
Jeff thank you for explanation and suggestions.

Related

Partial empty $_POST after submit input date

I have an HTML form that post datas to a PHP file:
<form method="POST">
<input type="text" name="first_name" />
<input type="date" name="start_date" />
<button type="button">Save</button>
</form>
I submit my form filling up both first_name and start_date, then I print $_POST and I get only first_name in my array.
Is there any weird thing I am missing?
SOLVED:
Stupid not closed div, apologize to you all guys for wasting time, about 1000 HTML rows i didn't see!
Change this
<button type="button">Save</button>
to this
<button type="submit">Save</button>
and use this code in your PHP to verify
print_r($_POST);
I just tested this and it works, save it as test.php...
I don't know what else you have going on as we don't see full code.
<form method="POST" action="">
<input type="text" name="first_name" />
<input type="date" name="start_date" />
<button type="submit">Save</button>
</form>
<?php
print_r($_POST['first_name']);
echo '</br>';
print_r($_POST['start_date']);
?>

Input in HTML not connecting to PHP post method

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

Button give $_GET extra parameter

I have two buttons in my form, one is for answer a question and the other is for copy the question.
<div id="question">
<?php echo($question->content) ?>
</div>
<form action="script.php" method="GET" id="question">
<input type="text" name="question">
<button id="answer" onclick="document.getElementById('question').submit()">Answer the question</button>
<button id="copy" onclick="document.getElementById('question').submit()">Copy the question</button>
</form>
The URL of script.php look now like:
script.php?question=sometext
Now I want that when you click at the copy button the URL looks like this:
script.php?question=sometext&copy
And for the answer button:
script.php?question=sometext&answer
EDIT:
There are much answers where is said: "use <input type> instead of <button>"
The problem is that I can't use a input field as button because the button is outside my form. And I can't put it inside my form
What you can do is to use one hidden field and change it's name according to the pressed button. Something like the following:
<div id="question">
<?php echo($question->content) ?>
</div>
<form action="script.php" method="GET" id="question">
<input type="text" name="question">
<input id="action" type="hidden" name="" value="">
<button id="answer" onclick="document.getElementById('action').setAttribute('name','answer'); document.getElementById('question').submit()">Answer the question</button>
<button id="copy" onclick="document.getElementById('action').setAttribute('name','copy'); document.getElementById('question').submit()">Copy the question</button>
</form>
Although this would give you the result you want at the url, it would be more appropriate to have as the hidden's field name the "action" and to change it's value to "copy" or "answer" through javascript.
Try to make two forms, with a hidden input field with the values. Then you get the extra parametrt in your url when submitting
Change your form to the following
<form action="script.php" method="GET" id="question">
<input id="question" type="text" name="question">
<input id="answer" type="submit" name="answer" value="true">
<input id="copy" type="submit" name="copy" value="true">
</form>
url:
script.php?question=hello&copy=true
Then you can check
if(isset($_GET['answer']) && $_GET['answer']=="true"){
//answer action
}
if(isset($_GET['copy']) && $_GET['copy']=="true"){
//copy action
}

In my form for edit users the field name appears but the phone dont ( phone has a jQuery mask)

I have this basic form for edit users, and Im showing the name and the phone in my inputs.
The name is working fine, but my phone its not appearing.
The only difference, and probably the difference that is ruining everything, is that Im using in my phone input the id="ph" that corresponds to a mask that I am using through jquery like this:
jQuery(function($){
$("#date").mask("99/99/9999 99:99:99");
$("#ph").mask("(99) 9999999");
});
Someone there knows how I can solve this problem? Maybe something like strip_tags() but for jQuery, but I dont find nothing about this!
My Basic form:
<form name="form" action="" method="post" enctype="multipart/form-data">
<label class="line">
<span class="data">Name:</span>
<input type="text" name="name" value="<?php echo $resultReadUserEdit['name'] ; ?>" />
</label>
<label class="line">
<span class="data">Phone number:</span>
<input type="text" id="ph" name="phone" value=" <?php echo $resultReadUserEdit['phone'] ; ?> " />
</label>
<input type="submit" value="Edit user" name="sendForm" class="btn" />
</form>

Can't retrieve values from other page (Stored As Label)

I am new to PHP and I am trying to get information from a form to another page, but the data won't transfer over when I hit submit. What am I doing wrong? Should I be trying to use GET instead of POST? What is the best way to debug something like this?
The path to information.php is definitely correct.
<form action="information.php" method="post" type="post">
<div class="row" style="padding-bottom: 20px;">
<label name="tempID"><?php echo $number; ?></label>
<button class="btn" name="submit" type="submit">More Details</button>
</div>
</form>
This file is in a different page (information.php)
if (isset($_POST["tempID"]))
{
$infoID = $_POST['tempID'];
}
echo $infoID;
<input type="hidden" name="tempID" value="<?php echo $number; ?>" />
Add this next to your original echo, post variables can't be stored in a label. Also remove the name value from the label
You need a submit input instead of a button with the name submit. Change the button's html to:
<input type='submit' value='More Details'>
Change Label in input
<form action="information.php" method="post">
<div class="row" style="padding-bottom: 20px;">
<input name="tempID" value="<?php echo htmlentities($number); ?>"/>
<button class="btn" name="submit" type="submit">More Details</button>
</div>
</form>
labels are only to display information. they are not submitted during form submission.
<form action="information.php" method="post" type="post">
<div class="row" style="padding-bottom: 20px;">
<label>Number:</label>
<input name="tempID" value="<?php echo $number; ?>"/>
<input class="btn" id="submit" name="submit" type="submit" value="More Detail" />
</div>
</form>

Categories