How to center allign input forms - html

In my page I am having one drop-down, 3 text boxes and one submit button .As of now it is left alligned . I need to make it center alligned. I am using bootstrap css in my code. I am new to this field . Can someone tell how to do that . I have tried this:
<?php
echo "<form action=page2.php method=GET>";
echo '<td><select class="form-control" name="select-val">
<option value="a1">A1</option>
<option value="a2">A2</option>
<option value="a3">A3</option>
<option value="a4">A4</option>
<option value="a5">A5</option>
<option value="a6">A6</option>
</select></td>';
echo "<br>";
echo "<td>" ." <input align='center' type = text class = form-control name = sel_val
placeholder = 'Enter The Name'>". "</td>";
echo"<br>";
echo"<br>";echo "<td>" ." <input align='center' type = text class = form-control name = start_date
placeholder = 'Start Date(YYYY-MM-DD)'>". "</td>";
echo"<br>";
echo "<td>" ." <input align='center' type = text class = form-control name = end_date
placeholder = 'End Date(YYYY-MM-DD)'>". "</td>";
echo"<br>";
echo "<td>" ."<input align='center' class=btn type=submit value=select". "></td>";
echo "</form>";
?>
Thanks in advance.

First of all, don't use tables for layouts; it's bad practise if you aren't showing any tabular data.
There are a couple of ways of going about this
Method 1) I prefer this one as it makes the most sense but if you want the elements to be in different rows you can't use this method
On all the inputs and elements you want centered add display: inline-block. Then on the container element that encapsulates all of this add text-align: center.
This will center all the elements horizontally and should appear how you want it.
Method 2) You can also add a position: relative to all the elements and then do left: 50%; margin-left: -[half of your element width]. This also works and allows the elements to be on different rows while remaining horizontally centered.

Related

How to make div color appear in front of another?

I want to know what is the wrong with following code; I want to make the inner div color appear as a part of the outer div color. I am using this for a percentage poll bar:
echo '<div style="width:130px; height:20px; background-color:#ecf2f9; overflow:hidden;">';
echo '<div style="width:<?php print $percent1; ?>%; background-color:#ff33cc; position:relative; z-index:3"></div>';
echo '</div>';
or if there will be another solution to get the result i need.
Thanks in advance for your help
In your case it is relatively simple. Just set the hight for the inner div and you are done ;)
A DIV has no default height. That's the problem.
Example:
echo '<div style="width:130px; background-color:#ecf2f9;">';
echo '<div style="width:<?php print $percent1; ?>%; background-color:#ff33cc; height:20px;"></div>';
echo '</div>';
You can see a plain HTML example of your bar here:
https://jsfiddle.net/eaz1vbex/
Beside that, using <?php print $percent1; ?> that way won't work, because echo outputs the content without further parsing by the PHP interpreter. If you want to keep the above style of code, you should change it to the following before continue reading:
echo '<div style="width:130px; background-color:#ecf2f9;">';
echo '<div style="width:' . $percent1 . '%; background-color:#ff33cc; height:20px;"></div>';
echo '</div>';
Alternatively:
echo "<div style='width:130px; background-color:#ecf2f9;'>";
echo "<div style='width:$percent1%; background-color:#ff33cc; height:20px;'></div>";
echo "</div>";
Please read this for better understanding:
http://php.net/manual/en/function.echo.php
Hints:
You should use CSS for all style attributes (except width, which is dynamic). Using the style tag is not recommended because it makes it hard to maintain and redesign later in the product lifecycle. It also bloats up output.
You maybe want to use some sort of template engine or at least the "here document"-syntax, for better maintainability of markup.
Example:
echo <<<END
<div style="width:130px; background-color:#ecf2f9;">
<div style="width:$percent1%; background-color:#ff33cc; height:20px;"></div>
</div>
END;
Example with seperate CSS:
CSS:
.progressBar { width:130px; background-color: #ecf2f9; }
.progressBar .progress { background-color:#FF33cc; height: 20px; }
PHP:
echo <<<END
<div class="progressBar">
<div style="width:$percent1%;" class="progress"></div>
</div>
END;
See: https://jsfiddle.net/fchp5aqa/
it's work : i have set a height : 20px and your $percent1 did not print !! so i change it and fix it. i think it enough to understand what i done!!
echo '<div style="width:130px; height:20px; background-color:red; overflow:hidden;">';
echo '<div style="width:'.$percent1.'%; background-color:blue; position:relative; z-index:3; height:20px;"></div>';
echo '</div>';

Remove font size and family from font tag within div using simple html dom

<div align="justify>
<div align="justify">
<p><font color="#333333" face="Arial" style="font-size:12px">
<div style="text-align: justify;"><font face="Arial, Helvetica, sans-serif" size="4" color="#990000">
bunch more stuff here
</div> <!-- end first div -->
So I have the code above and am pulling the content using Simple HTML DOM based on that first "justify". The first text in actual HTML starts where "bunch more stuff here" is.
How can I remove (or change) the size attribute, specifically that size="4"? Hopefully with out counting font tags since that code is not consistent.
Current simple HTML DOM:
<?php
require_once('simple_html_dom.php');
// get DOM from URL or file
$html = file_get_html('http://www.regnumchristi.org/english/articulos/articulo.phtml?se=363&ca=975&te=735&id=20302#art_der6');
//delete links
foreach($html->find('a') as $e)
$e->outertext = '';
//show title
$e = $html->find('font[style="font-size:28px"]',1);
echo $e->outertext . '';
// show date
$e = $html->find('font[color="#9A9A9A"]',0);
echo '<div style="float: right; margin-top: -40px;">'. $e->outertext . '</div>';
//show day
$e = $html->find('div[align="justify"]',0);
echo strip_tags($e->innertext) . '';
//show rest
$stuff = $html->find('div[align="justify"]',1);
echo $stuff->saveHTML($tag);
echo '' . $stuff->outertext . '</ div>';
?>
You can use jquery for that like
$('font').attr('style','font-size:4px')

Multiple checkbox management

Hello I generate my checkboxes using this way.
$result = mysql_query("SELECT * FROM tbl_tourism_type order by type_name ");
$i=1;
while($row = mysql_fetch_array($result)){
echo '<input type="checkbox" name="type[]" value="'.$row['type_id'].'" id="'.$row['type_name'].'">'.'
<label for="'.$row['type_name'].'" class="fil_lab">'.$row['type_name']. '</label>';
if($i%5==0)
{
$i = 0;
echo '<br><br>';
}
$i++;}
Note that they will most likely generate 50+ checkboxes. Currently they are generated by 5 each then next line and the way they are set up they are inconsistent with one another and are hard on the eyes. Would anyone know how to fix this so that they would be properly structured?Link to screen shot
Use CSS to give the checkbox a width and the label a width. That way they tale up the same amount of space.
echo '<input type="checkbox" name="type[]" value="'.$row['type_id'].'" id="'.$row['type_name'].'" style="width: 20px;" />'.'
<label for="'.$row['type_name'].'" class="fil_lab" style="width: 100px;">'.$row['type_name']. '</label>';

set html dropdown to selected value after refresh

how do i set a dropdown menu to a get variable after refresh. there is an html menu and after a refresh i would like the dropdown to be set to the select variable. for example if i select 3 from the menu then click submit the dropdown should display 3. i used to do this with textboxes where i would set the value to the get variable im just trying to do this same technique with html dropdown menus.
</select>
<?php
$c=$_GET['c'];
$p=$_GET['p'];
$id=$_GET['id'];
if ($c!=NULL){
$sq=mysql_query("SELECT * FROM ps WHERE b='$id' AND c='$c'");
while ($row=mysql_fetch_assoc($sq)) {
$start=$row['start'];
$start=trim($start);
$m=$row['m'];
}
echo "<select type='text' name='pro' id='amount' value= '$p'>";
echo "<option value=''>P</option>";
while ($start<=$m){
echo "<option value='$start'>$start</option>";
$start++;
}
}
?>
</select>
Is this in a form? If so you echo options like this:
echo "<option value='$start'";
if (isset($_POST['pro']) && ($_POST['pro']==$start)) echo " selected='selected'";
echo ">$start</option>\n";
But first you need to submit the form though.
The idea is that you compare the value of a set variable for this select element to current value of $start within the loop, and print 'selected' if they match.
Is this what you meant??
http://www.plus2net.com/php_tutorial/pb-drop.php

Adding a radio button against each record

The following code uses the DB extention provided by PEAR.
I want a radio button against each record so that the user can select only one record from the list and submit. There can be hundreds of records from table.
// Proceed with getting some data...
$res =& $db->query('SELECT * FROM someTable limit 10');
while ($res->fetchInto($row)) {
echo "<tr><td>";
echo $row[0] . "\n</td><td>";
echo $row[1] . "\n </td><td>";
echo $row[2] . "\n</td><td>";
echo $row[5] . "\n</td><td>";
echo $row[6] . "\n</td>";
echo "</tr>";
}
ok so put an <input type="radio" name="same-name-for-each" value="$this_record" /> between each table cell.
each radio button gets the same name
the value of each radio button needs to be different - the id or value of whichever option the selected radio represents.