Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
I try to get the value from the select area using form and $_Post. I looked through plenty of older questions and am sure, I followed the instructions. still i get the error: Undefined array key "platz".
<form action="" method="POST">
<select name="platz">
<?php
for ($i=0; $i < $saalinfo[2]; $i++) {
echo "<option value='$i'> Reihe $i </option>";
}
?>
</select>
<select class="" name="reihe">
<?php
for ($i=0; $i < $saalinfo[3]; $i++) {
echo "<option value='$i'> Spalte $i </option>";
}
?>
</select>
<?php echo "($_POST[platz])" ?>
</form>
For clarification Saalinfo 2 and 3 contain integer so that there are different options to choose from based on the given values. Many Thanks in advance.
I also tried
<?php echo "($_POST['platz'])" ?>
When the page loads initially there will be no POST data so you get that error. Instead check that POST array is available first - like so perhaps:
<?php echo !empty( $_POST['platz'] ) ? $_POST['platz'] : ''; ?>
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I have a simple HTML form like this:
<form action="index.php" method="post">
<textarea id="question" name="question"></textarea>
<input type="submit"/>
</form>
And the procedure that I'd like it to be is something like described here:
Type something in the text area and click submit, result displayed:
[... the only text area got blank and be ready for new input ...]
Question 1: Something typed firstly
Type some other thing in the above text area and submit, result displayed:
[... the only text area got blank and be ready for new input ...]
Question 1: Something typed firstly
Question 2: Something typed secondly
And so on...
[... the only text area got blank and be ready for new input ...]
Question 1: Something typed firstly
Question 2: Something typed secondly
...
Question n: Something typed at the n time
Does anyone have an idea or can give me a hint how to do this using only HTML and PHP?
Thank you very much!
You can use hidden inputs if you keep echoing out the id values and the just submitted value. (Also, note how I added a name to the submit)
<form action="index.php" method="post">
<?php
if(isset ($_POST['submit']) {
$oldAnswers = array ();
if(isset($_POST['oldAnswers']) && is_array ( $_POST['oldAnswers'])) {
$oldAnswers = $_POST ['oldAnswers'];
}
if (isset ($_POST ['question']))
$oldAnswers[] = $_POST ['question'];
for($i = 0, $j = 1; $i < count (oldAnswers); $i++, $j++) {
$answer = $oldAnswers [$i];
// display your "previously written" message
echo 'Question ' . $j . ': ' . $answer . "<br>\n";
// echo out hidden inputs
echo '<input name="oldAnswers[]" type="hidden" value="' . $answer . '">';
}
}
?>
<textarea id="question" name="question">< /textarea>
<input name="submit" type="submit">
</form>
See how oldAnswers has [] after it in the name? That'll tell php that it's an array and make it easy to deal with.
If you don't want to put the values in a database you could use a session
session_start();
at the very top of your page and
<?php
if( $_SESSION['counter'] > 0 ) $_SESSION['texts'] = $_SESSION['texts'] . "<br />Question " . $_SESSION['counter'] . ": Something " . $_POST['question'];
$_SESSION['counter']++;
?>
<?php echo $_SESSION['texts']; // put this in a div where you want to see them ?>
This will only clear when the browser is shut.
This is a very crude outline but you could look at tutorials on sessions and how to use them.
You would also need a counter at the bottom of your script to add in the number.
$_SESSION['counter']++;
Using hidden inputs to replace sessions without array or for loop.
<?php
$counter = $counter + (int) $_POST['counter']; // (int) helps sanitise this by forcing type change to integer - any text would be converted to 0
//echo $counter; // for trackng
$texts = $_POST['texts']; // MUST be sanitized and escaped for mysqli
if($counter > 0) $texts = $texts . "<br />Question " . $counter . ": Something " . $_POST['question'];
$counter++;
?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<textarea id="question" name="question"></textarea>
<input type="hidden" name="texts" id="texts" value="<?php echo $texts;?>" />
<input type="hidden" name="counter" id="counter" value="<?php echo $counter; ?>" />
<input type="submit"/>
</form>
<?php echo $texts; // put this in a div where you want to see them ?>
Do not use this code without cleaning up the post variables or you will get hacked to bits by hackers. See other posts on preg_replace() and on php.net
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
<?php /* for loop starts */ ?>
<div>
<input name="cat[]" type="text" />
</div>
<?php /* for loop ends */ ?>
I want to display each value inside the input box if their POST variable is set.
try this bro :
i have a similar query like this.
<?php
$j = 0;
for($i = 1; $i<=8; $i++) {
?>
<tr>
<td style="width:50% !important;">
<input type="text" class="form-control" name="cat[]" value="<?php echo isset( $_POST['cat'][$j] ) ? $_POST['cat'][$j] : ''; ?>" />
</td>
</tr>
<?php $j++; } ?>
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
How do I Get This HTML 5 Form To Give PHP The Input Data Then Display It On The Screen. I want to collect data in a form. Convert it into a php variable and then echo it out in a way that I can read it.
<form>
First name:<br>
<input type="text" name="name">
</form>
<body>
<pre>
<?php
$taco = htmlspecialchars($_POST["name"]) . '!';
$taco = $_POST;
echo $taco;
?>
</pre>
</body
</html>
How about the following:
<?php
if($_POST) { // check if the page is posted not with a $_GET
foreach($_POST as $field => $value) { // Foreach field
$value = strip_tags($value); // Strip html tags (you can add more)
echo 'Field: '.$field.' has value: '.$value.'<br>'; // output
}
}
?>
<form action="" method="post">
First name: <input type="text" name="first_name">
<input type="submit" value="Display">
</form>
Just put it all in one php file. You can add as many fields as you want.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I already have this code for showing the country list:
<label><div>Country</div>
<?php include('includes/countrylist.php'); ?>
</label>
and also have data of the country like this $tourdetail['country'].
So, how to show the value of the country in input box?
Sample code for input box:
<?= form_input(array('name' => 'country', 'value' => $tourdetail['country'])); ?>
In your example i think you are using $tourdetail['country'] inside any function which you wrote in includes/countrylist.php. so re declare the variable like this inside your function.
global $tourdetail;
<?php
//declare a variable before including
$temp="test";
?>
<label><div>Country</div>
<?php include('includes/countrylist.php'); ?>
</label>
includes/countrylist.php
...
global $temp; //if you are using inside any function make it as global
echo $temp;
...
This $temp variable will be accessible inside your countrylist.php
No, You can't bro. You can't put input box into include function. You need to use include and input separately. If you just want country with drop down so you can try like the following.
<?php
include('includes/countrylist.php');
foreach ($tourdetail['country'] as $country) {
echo "<option value='". $country ."'>". $country ."</option>";
}
?>
Yes, I understood that you would like to display the country values in dropdown box.
Please find the below code:
In your include file, you already defined your country list as an array list "$tourdetail['country']".
<select name="country">
<?php
include('includes/countrylist.php');
foreach ($tourdetail['country'] as $country) {
echo "<option value='". $country ."'>". $country ."</option>";
}
?>
</select>
Please see this
<input name="country" type="text" class="text_box" required id="country" value="<?=isset($tourdetail['country']!=''?$tourdetail['country']:'')?>" />
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 years ago.
Improve this question
i got this script below. How do i get the answer from the selected item?
how can i get the option back with the $_POST?
<?php
mysql_select_db("internetsites");
$query1 = "SELECT * FROM internetsites ORDER BY name_site";
$result = mysql_query($query1) or die(mysql_error());
?>
<form name="delete" action="delete.php" method="post">
choose a site you want to delete.
<select>
<?php
while($row = mysql_fetch_array($result))
{
echo "<option value=" . $row['name_site'] . "'>" . $row['name_site'] . "</option>";
}
?>
</select>
<input type="submit" value="delete">
Can someone help me?
You give your select a name atribute, then you take the whole code inside <form method="post" action="delete.php"></form> and then you use $_POST['nameattribute'].
Try this, To Post form elements need input name attribute,
<form name="delete" action="delete.php" method="post">
choose a site you want to delete.
<select name="name_site" id="name_site">
<?php
while($row = mysql_fetch_array($result))
{
echo "<option value='".$row['name_site']."'>" . $row['name_site'] . "</option>";
}
?>
</select>
<input type="submit" name="submit" value="delete">
</form>
in delete.php,
<?php
if(isset($_POST['submit'])){
echo $_POST['name_site'];
}
?>