My question is rather simple. But I am seriously stack as I have never done moving commentary box and nor applying it before.
Here is the code of a comment box I got from a free source:
<form method='post'>
<div class="name">NAME: <input type='text' name='name' id='name' /><br /></div>
Comment:<br />
<textarea name='comment' id='comment'></textarea><br />
<input type='hidden' name='articleid' id='articleid' value='<? echo $_GET["id"]; ?>' />
<input type='submit' value='Submit' />
</form>
And now I am trying to position it so it fits nicely on my page. I managed to move it on the page by putting the whole piece of code in a div, but when it comes to Name and comment fields even I am not sure what to do. Would be great to see some insights.
I would recommend using Bootstrap to make a clean design of your form.
Add Bootstrap to your Head of your HTML page:
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<!-- Latest compiled and minified JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
Then you can modify your form code to use Bootstrap containers, form-groups and form-control classes to structure and style your code. See here for more details. form-group group label's and input fields together removing the need to create custom css or use html breaks to change the structure of the page. form-control adds Bootstrap styling to the input fields.
I created an example from your code sample above using Bootstrap:
<div class="container">
<div class="row">
<div class="col-md-12">
<h1>Example Form</h1>
<form>
<div class="form-group">
<label for="nameInput">Name</label> <input class="form-control" id="nameInput" placeholder="Name" type="text">
</div>
<div class="form-group">
<label for="commentInput">Comment</label>
<textarea class="form-control" id="commentInput"></textarea>
</div>
<input id='articleid' name='articleid' type='hidden' value='<? echo $_GET["id"]; ?>'>
<button class="btn btn-primary" type="submit">Submit</button>
</form>
</div>
</div>
See code pen to view the form - http://codepen.io/jamesg1/pen/ALAZKg
Related
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 5 years ago.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Improve this question
I am a complete beginner and am trying to make a form for a project at university. I am just learning php and I am trying to test whether or not I can take the values from my php form and output it before I move on to linking it to my database. This is my full code for my login page, which btw I used bootstrap for some of the frame work. So I have tried to use the POST method and echo out first name and last name to see if it works, and it just wont echo out when I press the submit button. This is really frustrating me. Don't worry about the style, I just want to get the functionality out of the way first, and yes the page is called index.php .
<!doctype html>
<html lang='en'>
<head>
<title>Create Employee Account</title>
<!-- Required meta tags -->
<meta charset='utf-8'>
<meta name='viewport' content='width=device-width, initial-scale=1, shrink-to-fit=no'>
<!-- Bootstrap CSS -->
<link rel='stylesheet' href='https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/css/bootstrap.min.css' >
<link rel='stylesheet' href='no_dashboard_css_template.css'>
<link rel='stylesheet' href= ''>
</head>
<body>
<?php
include 'dbconnect.php';
if(isset($POST['submit']))
{
$firstName=$_POST['firstname'];
$lastName=$_POST['lastname'];
$email=$_POST['email'];
$password1=$_POST['password1'];
$password2=$_POST['password2'];
}
echo $firstName;
echo $lastName;
?>
<!-- NAVIGATION BAR -->
<nav class='navbar navbar-expand-lg navbar-light bg-light'>
<img id='logo' src='logo.png'>
<button class='navbar-toggler' type='button' data-toggle='collapse' data-target='#navbarSupportedContent' aria-controls='navbarSupportedContent' aria-expanded='false' aria-label='Toggle navigation'>
<span class='navbar-toggler-icon'></span>
</button>
<div class='collapse navbar-collapse' id='navbarSupportedContent'>
<ul class='navbar-nav mr-auto'>
<li class='nav-item active'>
<a class='nav-link' href='#'>Home/Login<span class='sr-only'>(current)</span></a>
</li>
</ul>
</div>
</nav>
<!-- Main CONTAINER part of the page WHERE MOST PAGE CONTENT WILL GO -->
<div class='container-fluid'>
<div class='row'>
<!-- EMPLOYEE SIGN UP AREA -->
<div class='col-lg-4'>
<h3>Potential Employee Sign Up</h3>
<!-- EMPLOYEE SIGN UP FORM -->
<form action='index.php' method='POST' >
<!-- Title (Mr Mrs etc. -->
<label class='mr-sm-2' for='inlineFormCustomSelectPref'>Title</label>
<select name='title' class='custom-select mb-2 mr-sm-2 mb-sm-0' id='inlineFormCustomSelectPref'>
<option selected>Choose...</option>
<option value='1'>Mr</option>
<option value='2'>Ms</option>
<option value='3'>Mrs</option>
</select>
<br>
<!-- NAMES -->
<div class='row'>
<!-- First Name -->
<div class='col'>
<input type='text' class='form-control' name='firstname' placeholder='First name'>
</div>
<!-- Last Name -->
<div class='col'>
<input type='text' class='form-control' name='lastname' placeholder='Last name'>
</div>
</div>
<!-- Email and Password-->
<div class='form-group'>
<label for='exampleInputEmail1'>Email address</label>
<input type='text' class='form-control' id='exampleInputEmail1' name='email' placeholder='Enter email'>
</div>
<div class='form-group'>
<label for='exampleInputPassword1'>Password:</label>
<input type='password' class='form-control' name='password1' id='exampleInputPassword1' placeholder='Password'>
<label for='exampleInputPassword1'>Enter your Password again:</label>
<input type='password' class='form-control' name='password2' id='exampleInputPassword1' placeholder='Password'>
</div>
<!-- Terms and Conditions-->
<div class='form-check'>
<label class='form-check-label'>
<input type='checkbox' class='form-check-input'>
I have agreed and read the Terms and conditions
</label>
</div>
<!-- Education -->
<!-- University -->
<div class='form-group'>
<label for='exampleFormControlInput1'>University</label>
<input type='text' class='form-control' name='uni' id='exampleFormControlInput1' placeholder='Please Type your University'>
</div>
<!-- Degree Type -->
<label class='mr-sm-2' for='inlineFormCustomSelectPref'>Degree Type</label>
<select class='custom-select mb-2 mr-sm-2 mb-sm-0' name='degtype' id='inlineFormCustomSelectPref'>
<option selected>Choose...</option>
<option value='1'>BEng</option>
<option value='2'>MEng</option>
<option value='3'>MSc</option>
</select>
<br>
<!-- End Button to submit -->
<button type='submit' class='btn btn-primary' name='submit' >Sign Up!</button>
</form>
</div>
</div>
</div>
<!-- EMPLOYEE SIGN UP AREA END -->
<!-- Optional JavaScript -->
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
<script src='https://code.jquery.com/jquery-3.2.1.slim.min.js' ></script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.3/umd/popper.min.js' ></script>
<script src='https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/js/bootstrap.min.js' ></script>
</body>
</html>
Your mistake is on this line
if(isset($POST['submit']))
Use it
if(isset($ـPOST['submit']))
first of all sorry for my bad English. I have hit a point in my project that i can't finde a solution on, so I will ask for help.
First let me explain a little about what the project is:
The system is a big upload system for a customer. each file there are selected need a Title.
As you can see I have many "Chose File" that because there need to be a max number of files pr categories (this can be change invidually) and the Title (the box beside the orange upload) are Required if you have chose a file.
My problem:
Click upload on each category are ignoring so wanna make one button to push there activate the upload for all those files. that easy enough, but here it's come: at the Host this system run on the max "upload size" is 90MB so when I have multiple files at the same time, its hit really quick the max.
This is how the HTML looks:
<form method='POST' accept-charset='UTF-8' enctype='multipart/form-data' >
<div class="inputs">
<label for="uMP1">Vælg Fil</label>
<input type="text" name='titles[]'>
<!-- Thumbnail -->
<div class="thumbnail" id="MP1"></div>
<!-- File -->
<input id="uMP1" name='files[]' type="file">
</div>
<div class="inputs">
<label for="uMP2">Vælg Fil</label>
<input type="text" name='titles[]'>
<!-- Thumbnail -->
<div class="thumbnail" id="MP2"></div>
<!-- File -->
<input id="uMP2" name='files[]' type="file">
</div>
<div class="inputs">
<label for="uMP3">Vælg Fil</label>
<input type="text" name='titles[]'>
<!-- Thumbnail -->
<div class="thumbnail" id="MP3"></div>
<!-- File -->
<input id="uMP3" name='files[]' type="file">
</div>
<input type="Submit" name='Upload' value="Upload">
</form>
Is there any there can help me make this script or know a plugin there can do this?
PS: Do not have access to the php.ini
Premise that I have never used PHP, but ASPNET Core 2.1
I also had a similar problem and the solution is to give different names for each input file.
For example:
<div class="inputs">
<label for="uMP1">Vælg Fil</label>
<input type="text" name='titles[]'>
<!-- Thumbnail -->
<div class="thumbnail" id="MP1"></div>
<!-- File -->
<input id="uMP1" name='files1' type="file">
</div>
<div class="inputs">
<label for="uMP2">Vælg Fil</label>
<input type="text" name='titles[]'>
<!-- Thumbnail -->
<div class="thumbnail" id="MP2"></div>
<!-- File -->
<input id="uMP2" name='files2' type="file">
</div>
I have an html with submit button.
Submit sends you to php.
php code has this:
header("location:./setupOk.html");
$html = file_get_html('setupOk.html');
$ret = $html->find('div[id=valueOk]');
echo $ret[0]->innertext = "foo";
and this is some of my html setupOk.html code:
<form action="http://54.186.92.18/Pixel-Matrix/keys.php" method="post">
<div class="logo">
<link rel="stylesheet" type="text/css" href="styles.css">
<label id="logo"</label>
<!--<label for="name">Type:</label>-->
</div>
<div class="right">
<h1>Enter License Information</h1>
<div id="valueOk">
<input type="text" id="valOk" name="Key" readonly="readonly" />
</div>
</div>
<div class="button">
<button id="validateB" type="submit">Validate Now ></button>
</div>
</form>
After executing button on first html, it goes to php and reloads my html website with setupOk but no text is innered to anywhere. Any solution?
EDIT:
my goal is to have a general html (with label and images) then from php, put text to that html and automatically load this html on user's browser
EDIT2:
MY FIRST HTML ISN'T THE SAME THAN 2ND HTML. FIRST ONE SENDS POST PETITION TO PHP THEN DEPENDING ON THE INFO SENT TO PHP, PHP WILL FILL TEXT TO THE 2ND HTML AND LOAD THIS LAST HTML ON USER'S BROWSER
Avoiding DOMParser and loading/redirecting to HTML page -- you can do it more simple way like (it has to be a PHP file):
<?php
$innerText = "";
if (!empty($_POST['Key'])) {
$innerText = "foo";
}
?>
<div class="logo">
<link rel="stylesheet" type="text/css" href="styles.css">
<label id="logo"</label>
<!--<label for="name">Type:</label>-->
</div>
<div class="right">
<h1>Enter License Information</h1>
<div id="valueOk">
<input type="text" id="valOk" name="Key" readonly="readonly" value="<?php echo $innerText;?>"/>
</div>
</div>
<div class="button">
<button id="validateB" type="submit">Validate Now ></button>
</div>
If you think this is not what you want - please elaborate your need a bit.
UPDATE
setupOk.php
<form action="http://54.186.92.18/Pixel-Matrix/keys.php" method="post">
<div class="logo">
<link rel="stylesheet" type="text/css" href="styles.css">
<label id="logo"</label>
<!--<label for="name">Type:</label>-->
</div>
<div class="right">
<h1>Enter License Information</h1>
<div id="valueOk">
<input type="text" id="valOk" name="Key" readonly="readonly" />
</div>
</div>
<div class="button">
<button id="validateB" type="submit">Validate Now ></button>
</div>
</form>
keys.php [where you are submitting the form]
require_once('simple_html_dom.php');
$processedResult = "";
if (!empty($_POST['Key'])) {
$processedResult = "foo";
}
$html = file_get_html('setupOk.php');
$html->find('input[id=valOk]', 0)->value = $processedResult;
echo $html;
I have tested it and it's working.
So, I'm having an issue where my $_POST variable does not work whenever I have JQuery included on the page.
If I comment out the JQuery link it works fine. I have asked a similar question before, but did not get a full answer and have used a workaround which does not work with this page.
My full code is as followed:
<?php
if(isset($_POST['home-register-submit']))
{
echo '<script>alert("Works!");</script>';
}
?>
<div id='home-register'>
<div id='home-register-title'><h4>Aanmelden</h4></div>
<hr>
<form method="POST">
<label>Voornaam:</label> <div id='home-register-input'><input type="text" name='home-register-fname'></div><br />
<label>Achternaam:</label> <div id='home-register-input'><input type='text' name='home-register-lname'></div><br />
<label>Leeftijd:</label> <div id='home-register-input'><input type='' name='home-register-age'></div><br />
<label>Telefoon:</label> <div id='home-register-input'><input type='tel' name='home-register-phone'></div><br />
<label>Email:</label> <div id='home-register-input'><input type='email' name='home-register-email'></div><br />
<button class="btn btn-default btn-sm" type='submit' name='home-register-submit'>Versturen</button>
</form>
</div>
<!-- jQuery -->
<script src="js/jquery.js"></script>
Fixed it by excluding a file called clean-blog.min.js which apparently blocked my page from using $_POST.
I'm currently in the process of creating a website with various widgets that I want to be able to add/remove on the fly.
I'm using jQuery to achieve this(planning to at least).
The simplest widget is the login widget. Which looks like this:
<div id="widget1">
<div class="close"></div>
<div id="widget1_title"></div>
<div id="widget1_content">
<form method='post' action='index.php'>
<div id="widget1_username">
Username<input type='text' maxlength='16' name='user' value='' />
</div>
<div id="widget1_password">
Password<input type='password' maxlength='16' name='pass' value='' />
</div>
<div id="widget1_submit">
<input type='submit' value='LOGIN' />
</div>
</div>
</div>
This is stored in a file called login_widget.html. Since a login-widget is something that should be preloaded on the site(without the user having to bring it up) I have my index.php file looking like this:
<body>
<div id="container">
<div id="content">
<div id="sidebar">
<div id="login-sidebar"></div>
</div>
<div id="header">
<div></div>
<div></div>
<div id="header-logo"></div>
</div>
<div id="main-content">
<div id="widget1">
<div class="close"></div>
<div id="widget1_title"></div>
<div id="widget1_content">
<form method='post' action='index.php'>
<div id="widget1_username">
Username<input type='text' maxlength='16' name='user' value='' />
</div>
<div id="widget1_password">
Password<input type='password' maxlength='16' name='pass' value='' />
</div>
<div id="widget1_submit">
<input type='submit' value='LOGIN' />
</div>
</div>
</div>
</div>
<div id="footer">
</div>
</div>
</div>
</body>
(Originally it's in a <?php include_once('login_widget.html'); ?> ).
I then have a button set up that I press to load in the code from the file.
Here's the jQuery code:
$(document).ready(function(){
$(".close").click(function(){
$(this).parent().remove();
});
$("#login-sidebar").click(function(){
$.ajax({
url: 'login_widget.html'
}).done(function(data) {
$('#main-content').append(data);
});
});
});
And now to the problem. This works in that it posts the html-code and it shows on the site, but the problem is that the "close button" doesn't work anymore. So I can't remove the new created html-elements using the class named "close".
I'm very new to jQuery, but I figure this is one way of doing it, but I'm missing something?
Thanks in advance!
Either build your widgets as modules that bind their own events when they are created to remove themselves, or use event delegation. Event delegation would be the simplest given the very basic code that you are using thus far.
$("#main-content").on("click",".close",function(){
$(this).parent().remove();
})