How can I center align a form thatI created?
$form = <<<END
<form method='post' action=''>
Adresa IP host : <input type='text' name='host'><br><br>
<input type='submit' name='submit' value='Connect'>
</form>
END;
echo $form;
$t = new TELNET();
if (!empty($_POST)){
$host = $_POST['host'];
echo("CONNECT:".$t->Connect($host, $name, $pass)."<br>");
echo("LOGIN:".(int)$t->LogIn());
echo("<br>Status Interfete:<br>");
$interfaces_status = ($t->GetOutputOf("show interface status"));
foreach ($interfaces_status as $value) {
echo "$value <br>";
I want the form to be on the center of the page.
In css:
form {
width: 800px;
margin: auto;
}
You need to done this using css. Please put form in one div and apply css according to div class.
<div class="frmCntr">
<form method='post' action=''>
Adresa IP host : <input type='text' name='host'><br><br>
<input type='submit' name='submit' value='Connect'>
</form>
</div>
and then add css in your css file like this:
.frmCntr{
width:80%; margin:auto;
}
or
form {
width:80%; margin:auto;
}
You can use margin:auto.
<form method='post' action='' style='margin:auto'>
If you not set a width for your form, you have to do it to get margin working in this case.
<form method='post' action='' style='margin:auto; width:400px'>
Related
I need you help. I have a form, and 2 inputs inside.
I have also those php code.
The idea is change css elements, by 2 colors the user insert, when my url is "URL?MyColors=true",
The function MyColors(), will run.
And then, the css apply by the inputs values.
I also want when client is submit, the url with get Get parameter "Mycolors=true",
so that why the submit button is with the next "formaction":
"".
It's work as well, but only for current page, and "URL2?MyColors=true".
When I'm refreshing the page, the 2 colors not apply anymore.
I don't know what the reason.
Who can help me?
<form action="" method="post" id="myform">
myColor1: <input name="myColor1" type="text" />
myColor2: <input name="myColor2" type="text" />
<input formaction="index.php?MyColors=true" type="submit" name="submit">
<button class="refresh" onclick="refreshPage()">Refresh</button>
</form>
<?php
if(isset($_GET['MyColors'])){
MyColors();
}
function MyColors() {
$_SESSION["myColors"] = "&MyColors=true";
if (isset($_POST['submit'])) {
$myColor1 = $_POST['myColor1'];
$myColor2 = $_POST['myColor2'];
}
else {
$myColor1 = $_SESSION['myColor1'];
$myColor2 = $_SESSION['myColor2'];
}
$_SESSION['myColor1'] = $_POST['myColor1'];
$_SESSION['myColor2'] = $_POST['myColor2'];
echo "<style>.bgimg-1{background: {$myColor1}!important;}
.last{color:{$myColor1}!important;-webkit-text-stroke-color:{$myColor2}!important;}
.first{color:{$myColor2}!important;-webkit-text-stroke-color:{$myColor1}!important;}
.addToCart{background:{$myColor1}!important;color:{$myColor2}!important;}
.addToCart i, a.addToCart a , a.addToCart span {color:{$myColor2}!important;}
.moreInfo{color: {$myColor1}!important;background: {$myColor2}!important;}
a.moreInfo i{color: {$myColor1}!important;}
button[type='button'].view_data {color: {$myColor1}!important;background: {$myColor2}!important;}
p.rotate {color: {$myColor1}!important; }
body {background: {$myColor2}!important;}
.categoriesTitle {color: {$myColor1}!important;}
.overlay {background: {$myColor1}!important;}
a.liAfter {color: {$myColor2}!important;}
.categoryTitles {color: {$myColor2}!important;background: {$myColor1}!important;}
.catWrapperImageCatPage::after {background: {$myColor2}!important;}
p.cat_title {color: {$myColor1}!important; }
</style>";
}
?>
your code should be...
<form action="index.php?MyColors=true" method="post" id="myform">
<label for="mycol1">myColor1:</label>
<input name="myColor1" id="mycol1" type="text">
<label for="mycol2">myColor2:</label>
<input name="myColor2" id="mycol2" type="text">
<input type="submit" name="col-submit" value="Submit_Color">
<button class="refresh" onclick="refreshPage()">Refresh</button>
</form>
<?php
if(isset($_POST["col-submit"])){
session_start();
----------
bla bla...
----------
?>
I'm trying to use an a tag to submit a form but the PHP doesn't seem to react:
<html>
<head>
</head>
<body>
<?php
if(isset($_POST['submit']))
echo 'dog';
else
echo 'cat';
$currentPage = 'test';
echo <<<eod
<form method='post' action='$currentPage.php' id='sign_in' style='margin: 0; padding: 0;'>
Username: <input type='text' name='username' style='width: 90px;'>
Password: <input type='text' name='password' style='width: 90px; border-right: 1px solid #bbb'>
<a id='sign_in_submit' name='submit'>Sign in</a>
</form>
eod;
?>
<script>
var form = document.getElementById('sign_in');
document.getElementById("sign_in_submit").addEventListener("click", function () {
form.submit();
});
</script>
</body>
</html>
tried three methods of submission via JS but none of them seem to work
Your submit a tag would not be included in the post data, so check for the existence of one of the input tags, say $_POST['username']
try in javascript this:
document.sign_in.submit();
and make a submit button like this
<input type="submit" id='sign_in_submit' value="Sign in" name='submit'
I have just tested your code. You are checking if submit field/button is sent over the form, but you do not have anything named submit in your form. You have got username and password, so changing your if(isset($_POST['submit'])) to if(isset($_POST['username'])) or if(isset($_POST)) will fix your issue.
I've got a simple <form> in myFunction, as you can see here:
<?php
function myFunction()
{
echo "
<form method='post'>
<fieldset>
<legend>Something</legend>
<input type='text'>
<input type='submit' value='send' name='postform'>
</fieldset>
</form>
";
if (isset($_POST['postform']))
{
echo "I'm working!";
}
}
?>
When I call this function, I can see the form but, when I submit it (by clicking the submit button), it disappears. How can I solve this problem?
Here is the full code:
<?php
echo "
<form method='post'>
<button name='first'>First step</button>
</form>
</div>
";
if (isset($_POST['first']))
{
myFunction();
}
?>
<?php
function myFunction()
{
echo "
<form method='post'>
<fieldset>
<legend>Something</legend>
<input type='text'>
<input type='submit' value='send' name='postform'>
</fieldset>
</form>
";
if (isset($_POST['postform']))
{
echo "I'm working!";
}
}
?>
The issue is that $_POST superglobal is purged on new request, just like when you're navigating through pages, which is quite natural.
So, if one comes to a page with, let's say, $_POST = ['first' => ''], and then he submits a post form (or any form) ['postform' => 'send'], the resulting $_POST would be ['postform' => 'send'].
So, in your case the easiest solution would be either to follow Shailesh's answer or submit the first form with method='get' and, of course, then you'll have to change $_POST['first'] to $_GET['first'].
But a better solution would be to pass some 'step' parameter in request on each step, so you'll have <input type="hidden" name="step" value="1">. And then, depending on a step variable, do some stuff.
Also check out $_SESSION.
Cheers!
It disappears because you don't get to call the function myFunction() itself. The second form does not include the field "first".
If you want it to work "as is", include this in myFunction() code:
function myFunction()
{
echo "
<form method='post'>
<fieldset>
<legend>Something</legend>
<input type='text'>
<input type='hidden' value='send' name='first'>
<input type='submit' value='send' name='postform'>
</fieldset>
</form>
";
if (isset($_POST['postform']))
{
echo "I'm working!";
}
}
?>
The only change is
<input type='hidden' value='send' name='first'>
which makes the form visible again. Anyway, you should rethink this whole code.
if (isset($_POST['first']))
{
myFunction();
}
Replace with:
if (isset($_POST['first']) || isset($_POST['postform']) )
{
myFunction();
}
Move your postform form processing out of the myFunction function definition and call myFunction function from there. Here's the complete code,
<html>
<head>
<title>Page Title</title>
</head>
<body>
<?php
echo "
<form method='post'>
<button name='first'>First step</button>
</form>
";
if (isset($_POST['first'])){
myFunction();
}
?>
<?php
function myFunction(){
echo "
<form method='post'>
<fieldset>
<legend>Something</legend>
<input type='text'>
<input type='submit' value='send' name='postform'>
</fieldset>
</form>
";
}
if (isset($_POST['postform'])){
myFunction();
echo "I'm working!";
}
?>
</body>
</html>
write the same as two different documents.
<html>
<body>
<form method="post" action="submit.php">
<fieldset>
<legend>Something</legend>
<input type="text" name="input">
<input type='submit' value='send' name="postform">
</fieldset>
</form>
now write the following in submit.php
<?php
$input=$_POST['input'];
if ($input!="")
{
echo "I'm working!";
}
?>
<?php
if(isset($_POST['submit']))
{
$name = $_POST['name'];
echo "User Has submitted the form and entered this name : <b> $name </b>";
echo "<br>You can use the following form again to enter a new name.";
}
?>
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<input type="text" name="name"><br>
<input type="submit" name="submit" value="Submit Form"><br>
</form>
Change this place on this code:
<?php
echo "
<form method='post'>
<button name='first'>First step</button>
</form>
</div>
";
if (isset($_POST['first']) or isset($_POST['postform']))
{
myFunction();
}
?>
<div class = 'buttons'>
<button type="submit" class="regular" name="save">
<img src="elephant.png" alt=""/>
Memory
</button>
</div>
This is the code for a submit button
however when i try validate the form using php, the button does not seem to be submitting
<?php if( isset($_POST['save']) && $_POST['save'])
{
$submit = $_POST['save'];
echo "lol";
}
else
{
echo "lola";
}
Submit buttons only work in forms. Try to wrap the whole thing in a form tag and try again.
Your submit button doesn't have any value to send when posting the form. The <button> element does not send its element's content as its submit value. You still have to add a value attribute to the element in order for it to have a submitted value. Since you don't, it's sending an empty string, which is causing your conditional statement to fail:
if( isset($_POST['save']) && $_POST['save'])
Since $_POST['save'] is empty, that second part returns false and thus it goes to your else block.
Here is the code that you want:
<form name="myForm" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<div class="buttons">
<button type="submit" class="regular" name="save" value="Save">
<img src="elephant.png" alt="Elephant" />
Memory
</button>
</div>
</form>
As written already your code lacks the wrapping. While submit button as a button might work without the form, then catching the _POST data surely doesnt.
Also, your solution for image-button could be better, maybe something like this:
<style type="text/css">
input[type="submit"] {background: url('elephant.png') right no-repeat; padding: 10px; padding-left: 30px; font-size: 14px; font-weight: bold;} /* or call this .regular */
</style>
<?
if ($_POST['save']) { // the trigger
echo '<h1>Cooking with fire now!</h1>';
}
?>
<form method="POST" action="">
<div class="buttons">
<input type="submit" name="save" value="Memory" class="regular" />
</div>
</form>
Note that class = "buttons" with the spaces, is incorrect syntax!
You should include your code within <form method="post" action="path/to/your/php/processing/file"> and </form> tags
Replace your button code with <input type="submit" class="regular" name="save" />
Remove isset($_POST['save']) && part from condition of if as you don't have set value for your button.
I am trying to display my login inside an iframe which loads in the middle of the start page with gray backgroud, however i have a problem dealing with the target of the iframe, things should work as follows:
1- if user logged in successfully home page should load in the parent window
2- if error, error message should be displayed in the iframe itself.
my code:
<div id="cover5" onclick="javascript:cover5();">
<iframe name="warning" src="SignIn.php" id="warning" onclick="javascript:cover5();">
</iframe>
</div>
SignIn.php
<html>
<head>
<script type='text/javascript'>
function valid(){
if(document.getElementById('username').value.toString().length>=1 || document.getElementById('password').value.toString().length>=1){
return true;
}
else{
alert("The Combination of username and password are Incorrect !");
return false;
}
}
</script>
<script type='text/javascript'>
function ChangeTarget() {
document.getElementById("login").prop("target", "_parent")
}
</script>
<script type='text/javascript'>
function ChangeText(text) {
document.getElementById("label1").innerHTML= text;
}
</script>
<title></title>
</head>
<body>
<form name="login" id='login' target='_self' method='post' accept-charset='UTF-8'>
<fieldset>
<legend>SignIn</legend>
<input type='hidden' name='submitted' id='submitted' value='1'/>
<label for='username' >Email:</label>
<input type='text' name='email' id='username' maxlength="50" /> <br />
<label for='password' >Password:</label>
<input type='password' name='password' id='password' maxlength="50" /> <br />
<br /> <label id="label1" style="color: red"></label> <br />
<input type='submit' name='Submit' value='Login'/> <br />
<a href='resetPassword1.php'> Forgot/Reset Password? Click Here</a>
</fieldset>
</form>
however, the target is not changed by method ChangeTarget() which is called inisde php code, so the problem now is that everything load inside the iframe or everything inside the parent window. anyone knows how to solve the problem?
server side script:
mysql_select_db("mydb",$check);
$email = $_POST['email']; //username that will be submit from a form
$password = $_POST['password']; //password that will be submit from a form
// if(mysql_num_rows($temp_privileges_id)== 1) //if the id found that means that the user is already assigned to a conference
// {
echo '<script type="text/javascript">',
'ChangeTarget();',
'</script>';
header('Location: main.php'); // transefer to home page with variable username
}
There is no method prop. Either set the value of the target attribute directly
document.getElementById("login").target = "_parent";
or use setAttribute
document.getElementById("login").setAttribute("target", "_parent");
.prop() is a jQuery function. If you're going to do it in jQuery, do this:
$("#login").prop("target", "_parent");
If you're not going to do it in jQuery, do it like this in straight JavaScript:
document.getElementById("login").target = "_parent";