How to show double quote in input tag? - html

How to show double quote in input tag ?
my $test is i test "hello"
and input like this
<input name="test" type="text" value="<?PHP echo $test; ?>">
When test code in input show only i test
How can i do for show i test "hello" in input tag ?

Try to use htmlspecialchars or use htmlentities
<input name="test" type="text" value="<?php echo htmlspecialchars($test); ?>">
<input name="test" type="text" value="<?php echo htmlentities($test); ?>">
Or by using PHP echo you can do it
<?php echo '<input name="test" type="text" value="'.$test.'">'; ?>

use html_entity_decode since you're using php like so:
<input name="test" type="text" value="<?PHP echo html_entity_decode($test); ?>">

Related

html 5 datalist value

how can I get the "id" instead of "name" when i submit the form.
<input type="text" list='name' name='test1'/>
<datalist id="test1">
<?php
if(!empty($data)){
foreach($data as $flag){
echo "<option label ='".$flag['id']."' >".$flag['name']."</option>";
}
}else{
echo "<option> empty </option>";
}
?>
</datalist>
I have tried using value = $flag['id'], but I still get "name" when i submit it.
The id is not sent to the server with a regular submitting of a form. Only the name- and value attributes are.
If you really wanted to get the ids too, you could have a hidden <input> element with an array for value, containing all the relevant ids you want.
Here's an example:
HTML
<form method="post">
<input type="text" name="firstname" id="inp1" />
<input type="text" name="surname" id="inp2" />
<input type="hidden" name="ids[]" value="inp1" />
<input type="hidden" name="ids[]" value="inp2" />
<input type="submit" />
</form>
PHP
foreach($_POST['ids'] as $id)
{
echo '<option label="' . $id . '">' . array_search($id, $_POST) . '</option>';
}

How can i store data from two page in same id in PHP

I have two pages sample4.php and sample5.php where different data is been passed. I need to store both page value in same id currently it stores in different id.
sample4.php
<form action = "sample5.php" method = "GET">
firstname: <input type = "text" name = "firstname" value="<?php echo #$firstname; ?>" />
lastname: <input type = "text" name = "lastname" value="<?php echo #$lastname; ?>" />
nationality: <input type = "text" name = "nationality" value="<?php echo #$nationality; ?>" />
<input type = "submit" value="next" />
</form>
Here i am passing firstname,lastname and nationality to next page sample5.php where extra two fields is added i need to store all value in same id but it actually stores first page value in one id and second page value in other id.Please help me to store both in same. Thanks in Advance
sample5.php
<?php
$conn = mysql_connect("localhost","root","");
$db = mysql_select_db("registration",$conn);
$sql = "INSERT INTO sampletable (firstname,lastname,nationality,mobileno,gender) VALUES ('". #$_GET['firstname']."','". #$_GET['lastname']. "' ,'". #$_GET['nationality']. "','". #$_POST['mobileno']. "','". #$_POST['gender']. "')";
$rep = mysql_query($sql);
?>
<!DOCTYPE html>
<html lang="en">
<head>
</head>
<body>
<form action="sample5.php" method="POST">
<?php if(isset($_GET['id'])) { ?>
<input type="hidden" name="act" value="edit"/>
<input type="hidden" name="id" value="<?php echo $id; ?>">
<?php } else{ ?>
<input type="hidden" name="act" value="add"/>
<?php } ?>
<label> Mobile No </label>
<input type="text" name="mobileno" value="<?php echo #$mobileno; ?>"><br>
<label> Gender</label>
<input type="text" name="gender" value="<?php echo #$gender; ?>"><br>
<input type = "submit" />
</form>
</body>
</html>

Post HTML <form> on load

What is the best way to post a HTML Form on load? This is what I'm currently trying:
<?php
if ($Autopost == "1");
{
<body onLoad="mail.submit()">
<form method="POST" name="mail" class="adjacent" action="./Script/addmaillist.php">
<input type="hidden" name="email" value="<?php echo $email; ?>">
<input type="hidden" name="genre" value="<?php echo $genre; ?>">
</form>
}
?>
I would just like to know if this is a good way, and if there is a better way?
I agree with Kolink that it seems unnecessary to send information to the client and then back to the server, but assuming you need to do that for some reason, you could use Javascript and jQuery to post a form through the $(document).ready() event, which triggers and runs its contents upon page load. So you would have your form with id="mail" and in your script you could have:
$(document).ready(function() {
$("#mail").submit();
}
you don't need any server-side code to submit on-load. also, your code doesn't look quiet right. is that in php?
There are some small syntax errors in your code:
<?php
if ($Autopost == "1")
{ ?>
<body onLoad="mail.submit()">
<form method="POST" name="mail" class="adjacent" action="./Script/addmaillist.php">
<input type="hidden" name="email" value="<?php echo $email; ?>" />
<input type="hidden" name="genre" value="<?php echo $genre; ?>" />
</form>
<?php
}
?>

Joomla 1.5 Database Query example needed

I have made a query, using mysql_* way, that select's some values from a table, where row's id is 1. Then I put all those values in variables so I can echo them in to my form. How can I do the same thing using Joomla's database query way ?
Here is an example of my code that working, using mysql_*:
<?php // DATABASE QUERY
$query="SELECT countdown_module, hometeam_header
FROM jos_gm_nextmatch
WHERE id = 1";
$result=mysql_query($query);
// DATABASE VARIABLES
$countdown_module = mysql_result($result,$i,"countdown_module"); ?>
$hometeam_header = mysql_result($result,$i,"hometeam_header"); ?>
<form action="" method="post" name="form">
<input name="countdown_module" value="<?php echo $countdown_module ?>" type="text" />
<input name="hometeam_header" value="<?php echo $hometeam_header ?>" type="text" />
<input name="submit" type="submit" value="UPDATE" />
</form>
OK I found it!!! Here is an example...
<?php // DATABASE QUERY
$db = JFactory::getDBO();
$query="SELECT countdown_module, hometeam_header
FROM jos_gm_nextmatch
WHERE id = 1";
$db->setQuery($query);
$rows = $db->loadObjectList();
$itemrow = $rows[0];
// DATABASE VARIABLES
$countdown_module = $itemrow->countdown_module;
$hometeam_header = $itemrow->hometeam_header; ?>
<form action="" method="post" name="form">
<input name="countdown_module" value="<?php echo $countdown_module ?>" type="text" />
<input name="hometeam_header" value="<?php echo $hometeam_header ?>" type="text" />
<input name="submit" type="submit" value="UPDATE" />
</form>

Getting results from database into textarea

I have an edit page that fills the content with the original content from the database, I am using inline php this populates the field with the title, and all the other fields work as well. When i try and fill the textarea using the same method it doesn't work.
All the other fields are varchar except the textarea which is text.
The php is in the value of the form.
require_once('includes/db.inc.php');
$stmt = $mysqli->prepare("SELECT
postID,title,content,author,image
FROM posts where postID = ?");
$stmt->bind_param("i",$_GET['postID']);
$stmt->execute();
$stmt->bind_result($postID,$title,$content,$author,$image);
$stmt->fetch();
$stmt->close();
?>
<section id="createPost">
<form method="post" action="editPost.php">
<fieldset>
<legend>Edit Post: <?php echo $title ?></legend>
<input name="postID" type="hidden" value="<?php echo $postID; ?>">
<label for="titleOfPost">Title of Post:</label><br />
<input type="text" name="titleOfPost" size="82" placeholder="Enter title of post" required value="<?php echo $title ?>"><br />
<label for="bodyOfPost">Content of Post:</label><br />
<textarea cols="60" name="postContent" rows="10" placeholder="HTML tags allowed" value="<?php echo $content ?>"></textarea><br />
<label for="authorOfPost">Author:</label><br />
<input type="text" name="authorOfPost" size="82" placeholder="Author name" required value="<?php echo $author ?>"><br />
<label for="imageOfPost">Image:</label><br />
<input type="text" name="imageOfPost" size="82" placeholder="image" value="<?php echo $image ?>"><br />
<input type="submit" name="newPostBtn" value="EditPost" id="newPostBtn"/>
</fieldset>
</form>
</section><!--end createPost-->
Textarea element doesn't a have property value. Use:
<textarea cols="60" name="postContent" rows="10" placeholder="HTML tags allowed"><?php echo $content ?></textarea>
Textareas aren't populated like other input types. The content goes between the tags (like an anchor tag) not within the opening tag (like an image tag).