This question already has answers here:
Can you nest html forms?
(21 answers)
Closed 4 years ago.
My code looks somewhat like this:
<form method="POST">
//something
<form method='GET'>
<input readonly type='text' id='userpwd' value= 'Day' name='count'/>
<input type='submit' id='btn' formaction='admi.php' name='admin' value='Add Details'></form>
<input type="submit" id="btn" formaction="choose.php" name="admin" value="Done"></p>
</form>
I want to get the value of readonly type input in my new php file.How could I achieve this.I tried doing this:
$var=$_GET['count'];
but it is giving following error msg:
Notice: Undefined index: count in C:\xampp\htdocs\tourism\admi.php on line 4
Please somebody help me out..!Kindly give some solution in php only.
<form> element shouldn't be nested:
4.10.3. The form element
Content model:
Flow content, but with no form element descendants.
HTML 5.2 Recommendation
Can't you do both forms seperate (not nested)?
Edit: If you need a readonly field to be sent in your form, you can add a hidden field with the same value :
<input type="hidden" name="count" value="Day" />
<input type="text" name="count" value="Day" readonly />
<?php
if(isset($_GET['txtUserPwd'])) { echo "<div>" . $_GET['txtUserPwd'] . "</div>"; }
else { ?>
<form method="GET">
<input type="text" id="txtUserPwd" name="txtUserPwd" value="Day" readonly />
<input type="submit" id="btnAdmi" name="btnAdmi" value="Add Details">
<input type="button" id="btnChoose" name="btnChoose" value="Done">
</form>
<?php } ?>
This doesn't address your second button. I would do that with JavaScript or jQuery.
Related
I am getting the error: Undefined index: data when running the code below
Here are the key parts of the code including sections that work fine:
I create a form to select dates - this all works fine
<div class="dates">
<form method="POST" action="">
<label for="StartDate">Start Date:</span></label>
<input type="datetime-local" id="StartDate" name="StartDate" value="<?php
if(isset($_POST['StartDate'])){echo $_POST['StartDate'];}?>"/>
<label for="EndDate">End Date:</span></label>
<input type="datetime-local" id="EndDate" name="EndDate" value="<?php if(isset($_POST['EndDate']))
{echo $_POST['EndDate'];}?>"/>
<input type="submit">
</form>
</Body>
</HTML>
</div>
I then run an sql query and add a checkbox to each line of data. I use lead_id as the value. This all displays fine and the value is being assigned correctly:
$result = mysqli_query($link,$query);
while ($row = mysqli_fetch_assoc($result))
{
?>
<form method="POST">
<?php
echo '<tr><td>'.$row['lead_id'].'</td>';
echo '<td>'.$row['status'].'</td>';
echo '<td>'.$row['campaign_id'].'</td>';
echo '<td>'.$row['call_date'].'</td>';
echo '<td>'.$row['user'].'</td>';
echo '<td>'.$row['status_name'].'</td>';
?>
<td><input type="checkbox" value='<?php echo $row['lead_id']?>' name="data[]"/></td></tr>";
</form>
<?php
}
I then have a submit button which is used to trigger an email - that all works aprt from it needs to contain the lead ids from the checked boxes and it doesnt due to this error
?>
<div>
<form method="post">
<input type="submit" name="Button1"
value="Send Email"/>
</form>
</head>
</div>
The error I get is Undefined Index: data
I am using the below code to attempt to output the data on screen as well as var_dump. All come out NULL as clearly for some reason it is not picking up the POST.
if(isset($_POST['data']) && !empty($_POST['data']))
foreach($_POST['data'] as $name) echo $name;
Id be grateful if anyone can see my error.
The issue is:
<form method="POST">
<?php
...
<td><input type="checkbox" value='<?php echo $row['lead_id']?>' name="data[]"/></td></tr>";
</form>
These checkboxes are in a different <form> tag and your submit button is in a different <form> tag which is below these checkboxes:
<div>
<form method="post">
<input type="submit" name="Button1"
value="Send Email"/>
</form>
</head>
</div>
That's why on form submit you are not getting those checkboxes. To resolve this, move checkboxes in the same <form> tag where submit button is.
This question already has answers here:
<button> vs. <input type="button" />. Which to use?
(16 answers)
Difference between <input type='button' /> and <input type='submit' />
(4 answers)
How to call a php script/function on a html button click
(7 answers)
Closed 5 years ago.
For my very simple registration page, I designed a very simple code for registration:
one textfield to enter the desired registration name
and one button to submit it and run the phpscript which connects to sql
But for some reason the button is dead. Clicking on it doesnt do anything.
If i enter a name however and press enter w. keyboard, the code runs fine...
what am i missing?
thank you in advance for your help!!
<form action="#" method="post">
<div class="register">
<input type="text" placeholder="username" name="name" class="field required" />
<input type="button" value="register" />
</div></form>
<?php if(!empty($_POST['name'])): ?>
.
.
.
go on
You need to declare your button as 'submit', instead of 'button'.
Instead of
<input type="button" value="register" />
declare it this way
<input type="submit" value="register" />
A submit type input does exactly what comes to your mind when you read it - it submits the form. You can have multiple buttons within your form, but it is a good practice to keep only one submit button whose job is to send the form information wherever needed.
Please read some of the following HTML guides to get a better understanding on how things need to be done:
https://www.w3schools.com/html/html_forms.asp
https://www.w3schools.com/html/html_form_input_types.asp
You just need to change the button type to submit. See this working example:
<form action="#" method="post">
<div class="register">
<input type="text" placeholder="username" name="name" class="field required" />
<input type="submit" value="register" />
</div></form>
<?php if(!empty($_POST['name'])): ?>
.
.
.
go on
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 am using dynamic form where user add more input text boxes for a certain field he want and the name of each box change with an increment like:
<form method="post" action="somescript.php">
<input type="text" name="textbox" />
<input type="text" name="textbox1" />
<input type="text" name="textbox2" />
<input type="text" name="textbox3" />
.... and so on
</form>
I want to echo these data following a loop:
<?PHP
$k=$_POST['counter']; //counter value coming as post variable
for($i=1$i<=$k;$k++){
echo $_POST['textbox'.$i]; //something like this......?
}
?>
Please reply.
Use array notation instead.
<form method="post" action="somescript.php">
<input type="text" name="textbox[]" />
<input type="text" name="textbox[]" />
<input type="text" name="textbox[]" />
<input type="text" name="textbox][" />
.... and so on
</form>
When the form is submitted, $_POST['textbox'] will then be an array, and you can loop over it:
foreach ($_POST['textbox'] as $textbox) {
echo $textbox;
}
I just came across this issue because I had blocks of data that needed to be created dynamically and
echo $_POST["textbox$i"];
worked without the concatenation in it. Let me know if this is bad practice, it works in my situation though. The array way didn't work for me. Sorry for posting this on a 3 year old question. I'm not sure if that's bad practice. Thanks.
This question already has answers here:
How to read the query string in PHP and HTML?
(3 answers)
Closed 9 years ago.
My URL is /mithun/add.php?bc=3
The "bc" being the attribute name. How can I pass this value so that it shows me the value 3 as input on the screen.
My source code:
<body>
<h1>Add new product</h1>
<form action="add.php" method="post">
Barcode: <input type="text" name="bc" />
<input type="submit" name="submit" value="submit" />
</form>
</body>
Thanks in advance.
Replace text type with this Barcode: <input type="text" name="bc" value ="<?php echo $_GET['bc']?>" />
You can access it also from url portion like
<?php $arr = explode("=",$_SERVER['REQUEST_URI']);
echo $arr[1];
?>
<input type="text" name="bc" value ="<?php echo $arr[1];?>" />
you can first get the value by $_GET['bc'] and then echo in the input type and its always good to see weather the $_GET['bc'] is set or not and escape it you can do this by
<input type="text" name="bc" value ="<?php
if( isset($_GET['bc']) && ctype_digit($_GET['bc']))
echo $_GET['bc'];
else
echo "other default" ; ?> />
and if you want to pass value from url use GET method instead
<body>
<h1>Add new product</h1>
<form action="add.php" method="post">
Barcode: <input type="text" name="bc" value="<?php echo $_GET['bc']; ?>" />
<input type="submit" name="submit" value="submit" />
</form>
</body>