I want to see all field input and textarea but I don't know how to
show it together in the same code.
and in case I want to skip something for example I want to write
directly input name without make him check the type or I don't want him to show me the readonly so how can I do it ?
<form method="post" action="" id="submit_form">
<input type="text" name="TITLE" value="" size="40" maxlength="100" class="text" />
<textarea name="DESCRIPTION" rows="4" cols="36" class="textarea"></textarea>
<input type="text" name="DESCRIPTION_limit" size="4" class="limit_field" readonly="readonly" value="250" />
<textarea name="ARTICLE" id="ARTICLE" rows="6" cols="50" class="textarea"></textarea>
<input type="text" name="META_KEYWORDS" value="" size="40" maxlength="2000" class="text" />
preg_match_all('/<(input)[\s](type)="?([^>"]*)"?[\s](name)="?([^>"]*)"?[\s]/', file_get_contents($url), $matches);
echo"<pre>";
print_r($matches);
I tested this code with the line "$string". Type and Name attributes can be in any order in the input tag, and it searches until it reads a ">" character.
$string = '<input type="text" name="TITLE" value="" size="40" maxlength="100" class="text" />';
preg_match_all('/<input[^>]*?(?:(type)="([^"]*)")|(?:(name)="([^"]*)")/', $string, $matches);
if($matches[1][0] == "type" && $matches[3][1] == "name"){
$type = $matches[2][0];
$name = $matches[4][1];
}
elseif($matches[1][0] == "name" && $matches[3][1] == "type"){
$name = $matches[2][0];
$type = $matches[4][1];
}
else{
throw new Exception('no input tags with type and name attributes were found!');
}
echo $type;
echo $name;
Related
I am trying to create a program that prints off an array of five user-inputted elements. Each input box should take in a value from the user, store it in an array, and print off that array value. However, the values reset and become null when you enter text into the next input box. You can see what I mean by looking at the site.
https://people.emich.edu/ghaines1/cosc231/stringReverse.php
I eventually want to print off the values of the strings in reverse as well. I'm sure that's quite easy but I haven't looked into it yet, as I need this first part to work first.
So ideally, the PHP portion should print off:
$input[0]
$input[1]
$input[2]
$input[3]
$input[4]
assuming that it has retained those values. Again, my issue is that I cannot print more than one value because they reset and become null when I enter a value into the next text box. Here's the code:
<form action="stringReverse.php" method = "post">
<input name="st1" type="text" size="50" placeholder="Enter phrase"><br><br>
</form>
<form action="stringReverse.php" method = "post">
<input name="st2" type="text" size="50" placeholder="Enter phrase"><br><br>
</form>
<form action="stringReverse.php" method = "post">
<input name="st3" type="text" size="50" placeholder="Enter phrase"><br><br>
</form>
<form action="stringReverse.php" method = "post">
<input name="st4" type="text" size="50" placeholder="Enter phrase"><br><br>
</form>
<form action="stringReverse.php" method = "post">
<input name="st5" type="text" size="50" placeholder="Enter phrase"><br><br>
</form>
<?php
if ($_SERVER["REQUEST_METHOD"]=="POST") {
$input = array (0, 0, 0, 0, 0);
if (is_null($_POST["st1"]) == false) {
$input[0] = $_POST["st1"];
echo $input[0] . "<br>";
}
if (is_null($_POST["st2"]) == false) {
$input[1] = $_POST["st2"];
echo $input[1] . "<br>";
}
if (is_null($_POST["st3"]) == false) {
$input[2] = $_POST["st3"];
echo $input[2] . "<br>";
}
if (is_null($_POST["st4"]) == false) {
$input[3] = $_POST["st4"];
echo $input[3] . "<br>";
}
if (is_null($_POST["st5"]) == false) {
$input[4] = $_POST["st5"];
echo $input[4] . "<br>";
}
}
?>
its because you are defining a form for each input
change html to:
<form action="stringReverse.php" method = "post">
<input name="st1" type="text" size="50" placeholder="Enter phrase"><br><br>
<input name="st2" type="text" size="50" placeholder="Enter phrase"><br><br>
<input name="st3" type="text" size="50" placeholder="Enter phrase"><br><br>
<input name="st4" type="text" size="50" placeholder="Enter phrase"><br><br>
<input name="st5" type="text" size="50" placeholder="Enter phrase"><br><br>
</form>
The landing page has form but it is not submitting and not redirecting to the next page.After submitting the form, it stays on the same page.
It was alright and was working before but I cant figure out where is the problem.
Code in formPage.php is below:
<form action="insert.php" enctype="multipart/form-data" class="contact_form" method="post" name="htmlform" >
<input class="frm-input" name="name" type="text" size="30" maxlength="50" placeholder="Enter Name" required="required" />
<input class="frm-input" name="email" type="text" size="30" maxlength="80" placeholder="Enter Email" required="required"/>
<input class="frm-input" name="jobtype" type="text" size="30" maxlength="30" placeholder="Job Type" required="required"/>
<input class="frm-input" name="ent_type" type="text" size="30" maxlength="80" placeholder="Entity Type" required="required"/>
<input class="frm-input" name="tas_out" type="text" size="30" maxlength="80" placeholder="Task Outline" required="required"/>
<input class="frm-input" name="l_st" type="text" size="30" maxlength="80" placeholder="Logo style of interest (optional)" />
<textarea required="required" class="frm-input frm-txtarea" name="message" placeholder="Task Description!!" maxlength="1000" cols="25" rows="6" ></textarea>
<input style="float: left;" type="file" name="image" size="66"/>
<input type="submit" class="btn btn-success btn-lg" name="submitt" value="submit" style="float: right" />
</form>
In this file I am trying to get the form information and storing them in database.But this page is not loading after the form submission.
Code in insert.php is below:
<?php
/*
$name = "";
$text = "";
$post = "";
*/
//echo $name;
if (isset($_POST['submitt']))
{
$name = $_POST["name"];
$mail = $_POST["email"];
$j_type = $_POST["jobtype"];
$e_type = $_POST["ent_type"];
$task = $_POST["tas_out"];
$l_st = $_POST["l_st"];
$task_des = $_POST["message"];
$image_name=$_FILES['image']['name'];
$image_type=$_FILES['image']['type'];
$image_size=$_FILES['image']['size'];
$image_temp=$_FILES['image']['tmp_name'];
//$date = date(m-d-y);
echo $name;
echo $mail;
echo $j_type;
echo $e_type;
echo $task;
echo $l_st;
echo $task_des;
if ($image_type=='image/jpeg' || $image_type=='image/png' || $image_type=='image/gif') {
move_uploaded_file($image_temp, "img/$image_name");
}
$connection=mysqli_connect("localhost", "root", "","com");
$query="insert into details (name, mail, j_type, e_type, task_outline, l_style, task_desc, image) values('".$name."','".$mail."','".$j_type."','".$e_type."','".$task."','".$l_st."','".$task_des."','".$image_name."')";
if(mysqli_query($connection,$query)){
//include('test.php');
echo '<h2>Data submitted successfully!!</h2>';
header("refresh:1; url=login.php");
//echo 'Back';
}else{
echo "Data not Submitted!";
# code...
}
}
echo "Data not Submitted!";
?>
echo "Data not Submitted!"; // put this line inside the last bracket
Sorry it was my fault,there was a typo mistake in the form action.Everything else is fine.
I have a title/entry form for submitting a blog post. On submit, it checks for the same title in the db (which you're not allowed to do), then returns an error to tell you to change your title. I want it to keep both fields filled after the POST, because duh, a user shouldn't have to rewrite the entire entry. However, it only keeps the TITLE. session_start exists in the header.php. Please ignore any SQL injection vulnerable sections.
<?php
require("connect.php");
require("header.php");
if(isset($_POST['post'])){
$title = $_POST['blogtitle'];
$entry = $_POST['blogentry'];
$author = $_SESSION['username'];
$newBlogPostQuery = "SELECT * FROM contents WHERE title='$title'";
$newBlogPostResult = mysqli_query($conn, $newBlogPostQuery) or die("Error:".mysqli_error($conn));
$newBlogPostRow = mysqli_fetch_array($newBlogPostResult, MYSQLI_ASSOC);
if(mysqli_num_rows($newBlogPostResult) ==1){
$blogPostExists = TRUE;
}
else{
$blogQuery = mysqli_query($conn, "INSERT INTO contents (timestamp, title, entry, authorName) VALUES (now(), '$title', '$entry', '$author')");
if($blogQuery){
header("Location: index.php");
}
}
}
?>
<div class="flex-enable flex-center blog-body">
<?php if(isset($blogPostExists)&&$blogPostExists){
echo '<div class="exception" style="margin: 0;"><span class="small-white-subtitle">Please use a different title.</div>';
}
?>
<form class="flex-enable flex-column" method="POST">
<label for="blogtitle"><span class="blog-insert-title">Title</span></label>
<input class="blog-input-text small-white-title" id="blogtitle" type="text" name="blogtitle" placeholder="Your title" value="<?php echo isset($_POST['blogtitle']) ? $_POST['blogtitle']:''; ?>">
<label for="blogentry"><span class="blog-insert-title">Blog post</span></label>
<textarea class="blog-input-text blog-insert-entry" id="blogentry" type="text" rows="20" name="blogentry" placeholder="Write something amazing here..." value="<?php echo isset($_POST['blogentry']) ? $_POST['blogentry']:''; ?>"></textarea>
<input class="form-button small-white-title" type="submit" name="post" value="Post">
</form>
</div>
Textarea has no value attribute, the content is between <textarea> and </textarea>.
<textarea class="blog-input-text blog-insert-entry" id="blogentry" type="text" rows="20" name="blogentry" placeholder="Write something amazing here..."><?php echo isset($_POST['blogentry']) ? htmlentities($_POST['blogentry']) : ''; ?></textarea>
You shoul put the value beetween textarea tags
<textarea class="blog-input-text blog-insert-entry" id="blogentry" type="text" rows="20" name="blogentry" placeholder="Write something amazing here..." ><?php echo isset($_POST['blogentry']) ? $_POST['blogentry']:''; ?></textarea>
You need to put value between textarea start and end tag Your Value
in your case, it will be
<textarea class="blog-input-text blog-insert-entry" id="blogentry" type="text" rows="20" name="blogentry" placeholder="Write something amazing here..."><?php echo isset($_POST['blogentry']) ? $_POST['blogentry']:''; ?></textarea>
Textarea has no value attribute
<form class="flex-enable flex-column" method="POST">
<label for="blogtitle"><span class="blog-insert-title">Title</span></label>
<input class="blog-input-text small-white-title" id="blogtitle" type="text" name="blogtitle" placeholder="Your title" value="<?php if(isset($_POST['post'])){ echo $_POST['blogtitle']; } ?>">
<label for="blogentry"><span class="blog-insert-title">Blog post</span></label>
<textarea class="blog-input-text blog-insert-entry" id="blogentry" type="text" rows="20" name="blogentry" placeholder="Write something amazing here..." value="<?php if(isset($_POST['post'])){ echo $_POST['blogentry']; } ?>"></textarea>
<input class="form-button small-white-title" type="submit" name="post" value="Post">
This is my code. I'm trying to print the comments on my site. The query and everything works since I tried it in an empty project but here it doesn't echo. The comments update in the database but they just don't show. What am I missing?
<h1>Leave a comment below!</h1>
<?php
$find_comments = mysql_query("SELECT * FROM comments");
if ($find_comments) {
while ($row = mysql_fetch_assoc($find_comments)) {
$comment_name = $row['name'];
$comment = $row['comment'];
echo "<p>'$comment_name' - '$comment'</p>";
}
}
if(isset($_GET['error'])) {
echo "<p>100 per limit";
}
?>
<form action="post_comments.php" method="post">
<p>Your Name: </p>
<input type="text" name="name" size="40" maxlength="30" placeholder="Enter name..." </input><br><p>
<p>Your Email: </p>
<input type="text" name="email" size="40" maxlength="30" placeholder="Enter email..." </input><br><p>
<p>Your comment: </p>
<textarea type="text" name="comment" cols="50" rows="10" placeholder="Enter comment..."></textarea><br><p>
<input type="submit" name="submit" value="Submit comment!" ></input>
</form>
Your variable name is in single quote, it must me concat or place in double quote..
For Ex
echo "<p>$comment_name-$comment</p>";
or
echo "<p>".$comment_name."-".$comment</p>";
Try this it will work :
Use
"<p>".$comment_name." - ".$comment."</p>";
instead of
"<p>'$comment_name' - '$comment'</p>";
echo "<p>".$comment_name."-".$comment."</p>";
if(isset($_POST['submit'])){
$domain=$_POST['domain'];
$fname=$_POST['fname'];
$sname=$_POST['sname'];
$tel=$_POST['tel'];
if($domain==""){
$error="<h4>Enter Domain </h4>";
}elseif($fname == ""){
$error="<h4>Enter Firstname </h4>";
}elseif($sname == "")
{
$error="<h4 >Enter Surname</h4>";
}elseif($tel=="")
{
$error="<h4 >Enter telephono no</h4>";
}
else {
$sql11=mysql_query("INSERT INTO domain VALUES('','$domain','$fname','$sname','$tel','$mobile','$email','$company','$address','$city','$country','$pcode','$tele',
'$fax','$qus','$ans')");
echo $sql;
$db->query($sql);
}
}
<div><?php echo $error; ?></div>
<form action="" method="post" name="classic_form" id="classic_form">
<div><h4>Personal details:</h4></div><div style="margin-left: 109px;">
<div>Domain</div>
<input type="text" name="domain" id="domain" value="" />
<div>First name: </div>
<input type="text" name="fname" id="fname" value="" />
<div>Surname:</div>
<input type="text" name="sname" id="sname" value="" />
<div>Telephone:</div>
<input type="text" name="tel" id="tel" value="" />
<div>Mobile:</div>
</form>
In my registration page, i used php validation. After the user submit the form if it shows validation errors it also resets all the fields. How can i resolve this problem? Without reset the fields i have to show the php validation errors. I also used in each input value. But it shows
"Notice: Undefined index: domain in D:\xampp\htdocs\deena\domainreg.php on line 82" . Please help me to resolve this problem
<input type="text" name="domain" id="domain" value="<?php echo isset($domain) ? $domain : ''; ?>" />
You have to pass all your values to php, and send back to html to feed your fields.
Its not 'resetting your fields' .. Your form is being submitted, hence the page is being reset and fields are therefore loading empty. Place the $_POST[] values in the field values upon page load:
<input type="text" name="domain" id="domain" value="<?php echo $domain ?>" />
<div>First name: </div>
<input type="text" name="fname" id="fname" value="<?php echo $fname?>" />
<div>Surname:</div>
<input type="text" name="sname" id="sname" value="<?php echo $sname?>" />
<div>Telephone:</div>
<input type="text" name="tel" id="tel" value="<?php echo $tel?>" />
Simple. Just add the variables to the input values:
<input type="text" name="domain" id="domain" value="<?php echo $domain; ?>" />
You should also protect the outputted value, against cross site scripting:
<input type="text" name="domain" id="domain" value="<?php echo htmlspecialchars($domain); ?>" />
In the value field:
<input type="text" name="domain" id="domain"
value="<?php if(isset($_POST['domain'])){echo $_POST['domain'];} ?>">
Didn't test it. But i think it should work.
In input tag add the php value as like value="" So that it will echo if the variable is posted or it will show the empty one