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
Hello i want to check if the textarea isnt empty and i still can´t get the echo that i want even when the textarea isnt empty and input is set
here is my code:
<form method="post" action="">
<input type="text" name="jmeno"/>
<textarea name="textarea" id="textarea" rows="5" cols="40"></textarea>
<input type="submit" name="submit"/>
</form>
<?php
if(isset($_POST['jmeno']) AND !empty($_POST['textarea'])){
echo "dokončeno";
}
?>
How about this:
if (!is_null($_POST['jmeno']) && strlen(trim($_POST['jmeno'])) > 0) {
echo "dokončeno";
}
As far as I understand you want your code to check if the submit button is pressed and the textarea isn't empty. I would say the code is:
if(isset($_POST['jmeno'])){
if(strlen($_POST['textarea']) > 0){
echo "dokončeno";
}
}
OR simply:
if(isset($_POST['jmeno']) && strlen($_POST['textarea']) > 0){
echo "dokončeno";
}
if (isset($_POST['jmeno']) && strlen(trim($_POST['textarea']))>0)
{
echo "dokončeno";
}
Related
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
first textfield should be disabled and when i clicked on check box, textfield should be active.
echo'<input type="checkbox" name="checkbox"/>';
echo'<textarea name="explain" id="explain"
cols="" rows="" style="width:300 ;height:300"></textarea>
if(isset($_POST['checkbox']))
{
???
}
I think you should use this:
<form>
<input type="checkbox" name="checkbox" onchange="toggleDisabled(this.checked)"/>
<textarea name="explain" id="explain"></textarea>
</form>
<script>
function toggleDisabled(checked) {
document.getElementById('explain').disabled = checked ? false : true;
}
</script>
Full code is here
Your question a little unclear. I've interpreted this as you needing JavaScript to set the textarea to disabled and active on a checkbox value without going to the server.
Using Javascript you can add an event listener on the checkbox and check the checked property, then set the textarea to disabled or not.
document.getElementById("checkbox").addEventListener("click", checkbox_textarea);
function checkbox_textarea() {
if( this.checked == true ) {
document.getElementById("textarea").disabled = false;
return false;
}
document.getElementById("textarea").disabled = true;
}
<input id=checkbox type=checkbox name=chk /> Enable text area <br />
<textarea id=textarea name=txt cols=50 rows=20 disabled></textarea>
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 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
i have an if statement as follows
if($_POST['remember']=="on")
i want to know if this is the correct syntax for checking if the checkbox is checked or unchecked?
This code will help you
<input type="checkbox" name="checkbx" <?php if(isset($_POST['remember'])=="on") echo "checked";?> />
OR
<?php if(isset($_POST['remember'])=="on") {?>
<input type="checkbox" name="checkbx" checked="checked" />
<?php }else {?>
<input type="checkbox" name="checkbx" />
<?php }?>
simple check of isset
if(isset($_POST['remember']) && $_POST['remember']=="on")
{
// checkbox remember is checked
}
else
{
// checkbox remember is not checked
}
Use
if (isset($_POST['remember'])) {
// checked
} else {
not checked
}
<input type="checkbox" name="remember" value="YES" />
$remember= ($_POST['remember'] == 'YES')?'YES':'NO';
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 got a problem where , if i want to edit the data the submit button is disabled . by the way , the data already exist but we want to edit some field e.g : id_no etc (use autocomple script)
this is the function to validate the data .
function validate()
{
if((\$('txt_no_kp').value != '')
&& (\$('txt_nama').value != '')
&& (\$('txt_alamat').value != ''))
{
\$('btn_basic').disabled = false;
}
else
{
\$('btn_basic').disabled = true;
}
}
this is the form php
<td colspan="2">
<strong>Name</strong>
<div id="div_nama">
<input name="txt_nama" type="text" id="txt_nama" onchange="validate()" size="40" />
</div>
</td>
<td colspan="2">
<strong>Alamat</strong><br />
<div id="div_alamat">
<textarea name="txt_alamat" id="txt_alamat" cols="40" rows="3" onchange="validate()"></textarea>
</div>
</td>
here the button coding :
<input type="submit" name="btn_basic" id="btn_basic" value="Simpan" />
Please try below code :
function validate()
{
if(($('#txt_no_kp').value != '')
&& ($('#txt_nama').value != '')
&& ($('#txt_alamat').value != ''))
{
$('#btn_basic').prop('disabled',false);
}
else
{
$('#btn_basic').prop('disabled',true);
}
}
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 9 years ago.
Improve this question
I'm trying already for two hours to understand what am I doing wrong and I can't figure it out:
My HTML code:
<form action="php/images.php" method="post" enctype="multipart/form-data">
<input type="file" name="image" value="on" id="file">
<input type="submit" name="submit" value="Submit">
</form>
My PHP:
if ( isset($_POST['image'])
&& $_POST['image']=="on")
{
imageUpload();
}
When I removed the if in the PHP file and immediately entered the inner function imageUpload() I've been able to upload the image, why is the variable name I pass using post isn't working?!
Your upload data will be in $_FILES array:
<?php print_r($_FILES['image']); ?>
So something like this:
<?php
if($_SERVER['REQUEST_METHOD'] === 'POST'){
if(isset($_FILES['image']) && $_FILES['image']['error'] == 0){
imageUpload();
}
}
?>
browse button lets you make an array and can be obtain via $_FILES['image'];.Similarly $_FILES also gives an array(size etc).Try var_dump($_FILES); to get the values.