This question already has answers here:
How to add default value for html <textarea>? [closed]
(10 answers)
Closed 7 years ago.
I was trying to figure out a bug in my CRUD system with a
I want to propagate the text field with previous text for when a user needs to update the text area.
I'm using this code, setting the value to the text I wanted, but it won't work
<?php
echo "<textarea name='text1' value= '".$row['text1']."' class='materialize-textarea'></textarea>";
echo "<label for='text1'>text notes</label>";
?>
any suggestions?
<?php
echo "<textarea name='text1' class='materialize-textarea'>".$row['text1']."</textarea>";
echo "<label for='text1'>text notes</label>";
?>
Passing values in textarea doesnt work. There is no value attribute in textarea. You need to make it as innerHtml of textarea Try Below,
<?php
echo "<textarea name='text1' class='materialize-textarea'>'".$row['text1']."'</textarea>";
echo "<label for='text1'>text notes</label>";
?>
Related
This question already has answers here:
PHP parse/syntax errors; and how to solve them
(20 answers)
Closed 5 years ago.
I am having a hard time trying to create a form using php that takes information from a multi-dimensional array(database isn't allowed for this assignment) to create the shopping cart feature like on ebay or amazon. The user is only supposed to be able to select one item to purchase, then pass the information to the next form in the process. I am trying to re-create a feature that I did in VB.net, using a nested loop to generate the repetitive controls for the form, in this case radio buttons.
<?php
$itemNumber = 0;
foreach( $items as $item ) {
$itemNumber++;
echo "<tr height=80px>";
//i think the problem is in the nested loop below//
foreach( $item as $key => $value ){
$myThumbnail = generateThumbnail("$itemNumber".".jpg");
echo "<td width = 50%><input type="radio" name="itemName" id="$itemNumber" value="itemName" setChecked("itemName", "itemName") /></td>";
echo "<td width=50%>$myThumbnail</td>";
}
echo "</tr>";
}
?>
I have ran my code through a syntax checker but the checker is very limited. I have tried for going on six days now to find my errors. My instructor for this class hasn't returned any emails. I have searched both stackoverflow and PHPfreaks for possible solutions but all options I found use databases and/or hard code all the controls instead of creating them dynamically so as to make as many as needed no matter how big or small the array is. If more code is needed I will add upon request.
The problem is you are not escaping the quotes in the first echo correctly, try(using \ to escape):
echo "<td width = 50%><input type=\"radio\" name=\"itemName\" id=\"$itemNumber\" value=\"itemName\" setChecked(\"itemName\", \"itemName\") /></td>";
Alternatively you can use concatenation and ' for the string like:
echo '<td width = 50%><input type="radio" name="itemName" id="' . $itemNumber . '" value="itemName" setChecked("itemName", "itemName") /></td>';
This question already has answers here:
Can I use white spaces in the name attribute of an HTML element? [duplicate]
(2 answers)
Closed 7 years ago.
Hi I am trying to make a form sticky. It creates a grid, and the user can then select a value for each row.
$subjectListArray has values of subject names like 'english', 'maths','speaking and listening' and $gradeSetArray carries a selection of grades like a,b,c etc
When I press submit I want the values that were selected to stay selected.
It works fine for subjects with NO SPACES in their names. As soon as I introduce an array value like 'Speaking and listening' its not sticky.
SO the space is causing me a problem.
<form>
<?php
foreach ($subjectListArray as $subject){
echo "<tr><td>$subject</td>";
foreach ($gradeSetArray as $grade){
echo '<td><input type="radio" name="'.$subject.'" value="'.$grade.'" ';
if ( isset($_POST[$subject])and $_POST[$subject]==$grade){
echo 'checked="checked"';
}
echo ' /></td>';
}
echo "</tr>";
}
?>
<input type="submit" name="submitPupilData" value="Input data" />
</form>
Here's a little of the html produced:
<td>
<input type="radio" value="p2iic" name="Speaking and Listening">
</td>
So for some reason my if ( isset($_POST[$subject])and $_POST[$subject]==$grade) isn't working if there's a space
What can I do in order to keep the spaces in the names and keep the from sticky?
Thanks
As per Jakar I printed out the $_POST and I noticed that the spaces were being replaced by _ characters thus Array ( [Health_and_well_being] => p2iic
It's not possible to use spaces in HTML name attributes. For more information checkout Can I use white spaces in the name attribute of an HTML element?
This question already has answers here:
How do you use echo inside html table row?
(5 answers)
Closed 8 years ago.
echo "<input type=\"hidden\" name=\"eventwhat\" value="<?php echo .$value['searchresultwhat'].;?>">";
echo $eventwhat;
this is my code where i have an echo where i echo a variable,this variable changes depending on click.however when do it like this i get the error Parse error: syntax error, unexpected '?' i doubt that the solution for this is \\ because if i try to do it like this
echo "<input type=\"hidden\" name=\"eventwhat\" value=\"<?php echo .$value['searchresultwhat'].;?>\">";
it turns everything to gray and php i think will not be called.any suggestions is appreciated
echo "<input type='hidden' name='eventwhat' value='".$value['searchresultwhat']."'>";
When you start with echo you must not add <?php in it!!
This is the answer
echo "<input type='hidden' name='eventwhat' value='".$value['searchresultwhat']."'>";
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 am trying to make a form in html that would create radio options bases upon the specified array in PHP.
Code:
<form name="form" action="Test.php" method="get">
<?php
//Creates the Array
$radioButtonArray = array("cat", "dog", "sheep", "moose");
//Length of the Array
$count = count($radioButtonArray);
//Runs for each index.
for($x = 0; $x < $count; $x++)
//Creates a radio button with the specified length
echo "<input=\"radio\" name=\"Animal\" value=\"{$radioButtonArray[$x]}\">{$radioButtonArray[$x]} <br>";
?>
</form>
As you can see firstly I open the form tag inside of HTML. Then I create a array with animals names and run a loop through each array index. During each loop it should create a new radio button and then make a new line as directed by the echo.
The issue is that when I run the file the output should be for example:
(RADIO BUTTON HERE) cat
(RADIO BUTTON HERE) dog
(RADIO BUTTON HERE) sheep
(RADIO BUTTON HERE) moose
Instead I get:
cat
dog
sheep
moose
I know that it is reading the echo line so the error would have to be located on that line. I am very new to PHP and decently familiar with HTML so a simple but detailed explanation of what I did wrong or what I should do would be very greatly appreciated. Thank you in advance.
How to Fix:
I did not correctly enter the format for declaring a input.
//Change This
echo "<input=\"radio\" name=\"Animal\" value=\"{$radioButtonArray[$x]}\">{$radioButtonArray[$x]}<br>";
//To This
echo "<input type=\"radio\" name=\"Animal\" value=\"{$radioButtonArray[$x]}\">{$radioButtonArray[$x]}<br>";
There is small error on the echo statement. HTML radio button should read
but your output statement reads instead.
Hence you should change
echo "<input=\"radio\" name=\"Animal\" value=\"{$radioButtonArray[$x]}\">{$radioButtonArray[$x]} <br>";
To
echo "<input type=\"radio\" name=\"Animal\" value=\"{$radioButtonArray[$x]}\">{$radioButtonArray[$x]} <br>";
Try this:
echo "<input type=\"radio\" name=\"Animal\" value=\"{$radioButtonArray[$x]}\">{$radioButtonArray[$x]} <br>";
You are not specifying the input type.
input=\"radio\" should be input type=\"radio\"
It should be input type="radio" not input="radio"
I know for a fact option 1 is right as it works for me.
OPTION 1
echo "<input type='text' name='text1' id='text1' value='".$_SESSION['txt']."'>";
But in a situation where text boxes are a result of an array, if I change the above to the following is it correct? I know the name='text1[]' bit is right however can some one tell me how do I change the value attribute in the option 2?
OPTION 2
echo "<input type='text' name='text1[]' id='text1' value='".$_SESSION['txt[]']."'>";
you can put the array in to session :-
$my_array=array('ct', 'dg', 'se', 'ir');
// put the array in a session variable
$_SESSION['code']=$my_array;
foreach($_SESSION['code'] as $key=>$value)
{
// and print out the values
echo "<input type='text' name='text1[]' id='text1' value='".$_SESSION[$key]."'>";
}