how to style a php form using css - php

i have made a form using php this is my code
<?php
echo "<div class='error_msg'>";
echo validation_errors();
echo "</div>";
echo form_open('user_authentication/new_user_registration');
echo form_label('Create Username : ');
echo"<br/>";
echo form_input('username');
echo "<div class='error_msg'>";
if (isset($message_display)) {
echo $message_display;
}
echo "</div>";
echo"<br/>";
echo form_label('Email : ');
echo"<br/>";
$data = array(
'type' => 'email',
'name' => 'email_value'
);
echo form_input($data);
echo"<br/>";
echo"<br/>";
echo form_label('Password : ');
echo"<br/>";
echo form_password('password');
echo"<br/>";
echo"<br/>";
echo form_submit('submit', 'Sign Up');
echo form_close();
?>
the form is supposed register new users
how can i style this form using css given that there is no html in the code.

The echo(); function you are using essentially prints HTML, this HTML can be styled by including a style sheet (Google CSS basics and you will quickly find out how to do this).
I would advise running this script and using the web inspector of your chosen browser to look at the HTML code you have created using your PHP code. Again, if your not familiar with the web inspector Google how to open it on your chosen browser.
Hope this clarifies things a bit :)

Related

Getting Value from clicked div's ID - php mysql issue

I am currently beginning in php mysqli connections and such, and I'm working on a real estate website design prototype.
As of now I've managed to create a search form which displays every single house available for purchase listed in the mysql database.
Now my task is that when the user clicks one of the homes it activates another .php form which shows a more detailed page.
I'm trying to figure out the proper way to do this.
I'm guessing when the user clicks the div he wants, the php form should get a unique value from said div to query the database for that specific property but I'm at a loss here.
This is the Code for the listed available homes:
<?php
echo "<div id='parent'>";
echo "<section class='responsive HomeBox filterDiv' id='";
echo $resultados['tipo']."";
echo "'>";
echo "<div class='HomeBoxImg'>";
echo "<img class='img-thumbnail img-responsive' alt='Forest'
src='img/propiedades/";
echo $resultados['nombre']."";
?>
/1.jpg' onerror="this.src='img/default.jpg'">
<?php
echo "</div>";
echo "<div class='HomeBoxInfo'>";
echo "<h1>";
echo $resultados['direccion']."";
echo "<h2>";
echo $resultados['estructura']."";
echo "- ";
echo $resultados['tipo']."";
echo "</h2>";
echo "</h1>";
echo "<hr style='width:100%;'>";
echo "<div class='homeboxdetailboxes'>";
echo "<img src='img/icons/bed.png'' alt='Dormitorios'>";
echo "<h4>Dormitorios</h4>";
echo "<h5>";
echo $resultados['dormitorios']."";
echo "</h5>";
echo "</div>";
echo "<div class='homeboxdetailboxes'>";
echo "<img src='img/icons/rooms.png'' alt='Ambientes'>";
echo "<h4>Ambientes</h4>";
echo "<h5>";
echo $resultados['ambientes']."";
echo "</h5>";
echo "</div>";
echo "<div class='homeboxdetailboxes'>";
echo "<img src='img/icons/toilet.png'' alt='Baños'>";
echo "<h4>Baños</h4>";
echo "<h5>";
echo $resultados['baños']."";
echo "</h5>";
echo "</div>";
echo "<div class='homeboxdetailboxes'>";
echo "<img src='img/icons/price.png'' alt='Precio'>";
echo "<h4>Precio</h4>";
echo "<h5>";
echo $resultados['precio']."";
echo "</h5>";
echo "</div>";
echo "</div>";
echo "</section>";
echo "</div>";
?>
So what I'm missing would be the php form for displaying a whole new page based on an id or something provided by the user clicking on of these items.
You can use Javascript/JQuery here, like you can add following
echo '<div id="parent" class="number_<?php echo $resultados['nombre']; ?>">';
then to get specific elements id you can use:
var unique_id = document.getElementById('#parent').className.split('_')[1] //Javascript
var unique_id = $('#parent').attr('class').split('_')[1]; //Jquery
than you can use Ajax request or you can use javascript to change url of current page like:
window.location.href = 'https://www.some_url/'+unique_id;
or you can even wrap each estate item inside , and inside this form put hidden input element like:
<input type="hidden" name="unique_number" value="<?php echo $resultados['nombre']; ?>">
and hook on click event on Javascript or JQuery to submit the form.

Dynamic div change with using jQuery not working on my site

I tried many type of codes but neither worked. Last one that I tried is this : Change content of div when clicking on link/button
I have 2 buttons that need to execute script. One is to get dynamic content on page that is not working. Second is to logout of site and that one is working.
Here is part of my main page code :
<?php
echo '<p></p>';
echo '<p></p>';
echo '<div style="width:300px;float:left;">';
echo '<button type="buton" id="loyaltybut" onclick="loyalty()" style="background:#8C8C8C;width:300px;margin-bottom:1px;margin-top:7px;" href="#">But1</button>';
echo '<button type="buton" id="logoutbut" onclick="logout()" style="background:#8C8C8C;width:300px;margin:1px auto;">But2</button>';
#Loyalty report - script
echo '<script type="text/javascript">';
echo 'function loyalty() {';
echo '$("#loyaltybut").click(function(){';
echo '$("#data").load("localhost/data #article1");';
echo '}';
echo '}';
echo '</script>';
#Logout - script
echo '<script>';
echo 'function logout() {';
echo 'window.location.replace("localhost/logout/");';
echo '}';
echo '</script>';
echo '</div>';
echo '<div id="data" style="width:750px;float:right;">';
echo '</div>';?>
My data script :
<?php
echo '<div id="article1">';
echo '<b>ARTICLE 1</b> This is my first article';
echo '</div>';
?>
What can I do to make it work ?
Thanks in advance
To Work with Jquery you have to import jquery.js
<script src="http://www.mneye.com/scripts/jquery172.js" type="text/javascript"></script>

Dynamic link in IF/ELSE statement

I apologize for any misuse of terminology...I'm a noob...
I have a dynamically created page that contains a dynamic link. I added an IF/ELSE statement to display a different word based on the number of items in the variable $rowsphoto.
The different words display correctly, but the URL that is generated contains all of the PHP instead of generating the correct URL.
This is the original code, which works fine:
<?php if($portfolioid != 0) { ?>
<div class="extrafield">Additional works in Portfolio:</div>
This is the code I have after adding the IF/ELSE statement:
<?php if($portfolioid != 0) { ?>
<div class="extrafield">
<?php
if ($rowsphoto <= 4){
echo "Additional works in <a href='index.php?option=com_jartists&view=portfolio&aid=<?php echo $artistid;?>&pid=<?php echo $portfolioid; ?>&album=<?php echo $albumid;?>&id=<?php echo $photoidd; ?>&Itemid=105' class='portfoliocol'>Edition:</a>";
} else {
echo "Additional works in <a href='index.php?option=com_jartists&view=portfolio&aid=<?php echo $artistid;?>&pid=<?php echo $portfolioid; ?>&album=<?php echo $albumid;?>&id=<?php echo $photoidd; ?>&Itemid=105' class='portfoliocol'>Portfolio:</a>";
}
?>
</div>
I ran the code through a couple syntax checks and they all came back with no errors. What am I doing wrong? Is this even possible?
You'd be better off using it correctly like this:
<?php if($portfolioid != 0): ?>
<div class="extrafield">
<?php if($rowsphoto <= 4): ?>
Additional works in <a href='index.php?option=com_jartists&view=portfolio&aid=<?php echo $artistid; ?>&pid=<?php echo $portfolioid; ?>&album=<?php echo $albumid; ?>&id=<?php echo $photoidd; ?>&Itemid=105' class='portfoliocol'>Edition:</a>
<?php else: ?>
Additional works in <a href='index.php?option=com_jartists&view=portfolio&aid=<?php echo $artistid; ?>&pid=<?php echo $portfolioid; ?>&album=<?php echo $albumid; ?>&id=<?php echo $photoidd; ?>&Itemid=105' class='portfoliocol'>Portfolio:</a>
<?php endif; ?>
</div>
<?php endif; ?>
You're mixing html and php very badly. You should be separating them to keep your code clean and concise.
Your issue with it displaying the php instead of the correct variables is because (as #scrowler said):
You can't use PHP tags inside PHP, you just need to escape the string
bounds and use the . concatenation operator instead of trying to open
new PHP tags, e.g. echo "String here" . $varname; as opposed to echo
"String here"
While Darren's answer is correct, alternatively you can just stay inside of php
<?php
if($portfolioid != 0) {
echo '<div class="extrafield">';
if ($rowsphoto <= 4){
echo "Additional works in <a href='index.php?option=com_jartists&view=portfolio&aid=$artistid&pid=$portfolioid&album=$albumid&id=$photoidd&Itemid=105' class='portfoliocol'>Edition:</a>";
} else {
echo "Additional works in <a href='index.php?option=com_jartists&view=portfolio&aid=$artistid&pid=$portfolioid&album=$albumid&id=$photoidd&Itemid=105' class='portfoliocol'>Portfolio:</a>";
}
echo '</div>';
}
?>

Create an html mailto link from a database fetch

I'm having difficulty creating a mailto link from a user's inputted email address that's stored in a database (this is used for a comments section). I was hoping to create a new line with the email address printed with a mailto hyperlink. Instead, it doesn't print the email address, but instead turns all text below that line into a mailto hyperlink. See attached pictures for clarification.
echo "<h3><u>Latest Comments:</u></h3>";
while($fetch=mysql_fetch_array($query)) {
echo "<hr />";
echo "<p>".$fetch['comment']."<p>";
echo "<header><h3>By: ".$fetch['comment_by']."</h3><br>";
echo "".$fetch['email']."</br>";
$sqldate = $fetch['datetime'];
$date=strtotime($sqldate);
echo "<span class='date'>On: " .date("m/d/Y, g:i A", $date)."</span></header></p>";
Notice, it fetches the correct email address, but doesn't create the hyperlink correctly using html. Also note this is all contained inside php tags.
link to photo showing problem
You're missing a quote:
echo "<a href='mailto:".$fetch['email']."'>".$fetch['email']."</a></br>";
-----^
Nowadays it is not acceptable to have this mess between PHP and HTML what usually ends with "missing a quote".
Your View should be something like
<h3><u>Latest Comments:</u></h3>
<?php foreach($records as $record) : ?>
<hr />
<p><?php echo $record['comment'] ?></p>
<header>
<h3>By: <?php echo $record['comment_by'] ?></h3>
<?php echo $record['email'] ?><br />
<span class="date">On: <?php echo date("m/d/Y, g:i A", strtotime($record['datetime'])) ?></span>
</header>
<?php endforeach ?>
Help yourself and read Alternative syntax for control structures

Wordpress Mobile Detect Plugin and if echo issues

I'm using WP Mobile Detect to see if site visitors are on a mobile device. The Plugin is installed and I'm good on that front.
Now, I'm trying to setup an if / else php statement to display a tel: link to mobile browsers and a non link phone number to everyone else. The code below breaks my theme.
<?php
if (function_exists('wpmd_is_phone')) {
echo "<li><a class="phone' href="tel:<?php echo ot_get_option('phonenumbercontent') ?>"><span class="phone"><?php echo ot_get_option('phonenumbercontent') ?></span></a></li>";
} else {
echo "<li><span class="phone"><?php echo ot_get_option('phonenumbercontent') ?></span></li>";
}
?>
Your code is not correct, for example (not properly concatenated)
echo "<li><span class="phone"><?php echo ot_get_option('phonenumbercontent') ?></span></li>";
You may try this
<?php
if (function_exists('wpmd_is_phone') && wpmd_is_phone()) {
echo "<li><a class='phone' href='tel:" . ot_get_option('phonenumbercontent') . "'><span class='phone'>" . ot_get_option('phonenumbercontent') ."'</span></a></li>";
} else {
echo "<li><span class='phone'>" . ot_get_option('phonenumbercontent') . "</span></li>";
}
?>
Also, the plugin doc says, you can use
[phone]Put content here that you only want displayed on Phones NOT Tablets or Desktops[/phone]
[notphone]Put content here that you only want displayed on Tablets OR Desktops NOT Phones[/notphone]

Categories