I'm trying to create a page that can allow users to customize there own specific pages, these pages will only have a few customization options such as text, color and layout of blocks. I haven't started a configuration page but i have began creating a template that the user will modify to suit their needs.
I would like to somehow get the information given by the user on the configuration page and then display it into parts of the other page. At the moment i don't know the best way to get that information and display in tags on the other page such as these tags.
<p><i class="fa fa-certificate fa-fw w3-margin-right w3-large" style="color: #582d37"></i>
<?php $GLOBALS['event1'] ?>
</p>
<p><i class="fa fa-globe fa-fw w3-margin-right w3-large " style="color: #582d37"></i>
<script>
document.write(venue1)
</script>
</p>
<p><i class="fa fa-calendar fa-fw w3-margin-right w3-large" style="color: #582d37"></i>
<script>
document.write(date1)
</script>
</p><br>
This is a snippet of code of a few ways I've tried to display the information sadly i haven't had any luck in getting the information and displaying it at the same time.
I was thinking about trying to get information from the PHP configuration form and then turn it into a java script variable and display it into the page.
I would like your views on how to do this and whether there is a better way and how to do that.
Zahir,
First, you have to store the information...
assuming you have this information already stored and have written the code that fetches the user information from the database:
You will need to echo out the values like so:
<p><i class="fa fa-certificate fa-fw w3-margin-right w3-large" style="color: #582d37"></i><?php echo $cert; ?></p>
IF you have yet to write the code for storing the information:
On the page where user fills out the form, have the form go to some page (could be the same page)--this page is specified in form tag's ACTION attribute.
All form data will be in $_POST; prior to making the call to the database for storing the form data, you must sanitize/validate it! (otherwise, your application will be vulnerable to attacks such as SQL Injection.
And then follow the step above.
Just some pointers to get you going... if you get more stuck write back.
Hope this helps,
-Rush
Related
I have this code on page 1. All a tags have the same link. If the user clicks on one link, the next page 2 is loaded. I want to display the price of that id specific to that link to show on page 2.
example: If the user clicks a link with id="saloon_price", the price on page 2 should appear Saloon: £50.
If the user clicks the link with id="mpv_price", the price on page 2 should appear MPV: £70.
Please help me to achieve this on page 2.
I am very new to coding. And using Javascript. Kindly help me with a simpler solution. Thanks
<a id="saloon_price" href="/quotes/details"> Saloon: £50</a>
<a id="estate_price" href="/quotes/details">Estate: £60</a>
<a id="mpv_price" href="/quotes/details">MPV: £70</a>
In the web, we pass values mainly using the URL, and read them again in the loaded page.
<a id="saloon_price" href="/quotes/details?label=Saloon&value=£50"> Saloon: £50</a>
<a id="estate_price" href="/quotes/details?label=Estate&value=£60">Estate: £60</a>
<a id="mpv_price" href="/quotes/details?label=MPV&value=£70">MPV: £70</a>
And read this post for more details:
How to get the value from the GET parameters?
You will propably need to use PHP or other server-side languages. You can do this easily with forms. But you will need to run this on some kind of server.
This will echo (type to document) the value of value attribute on the button...
index.php:
<form action="/quotes/details.php" method="post">
<button type="submit" name="price" value="£50" id="saloon_price"> Saloon: £50 </button>
...other buttons...
</form>
/quotes/details.php:
...
<?php
$price = $_POST["price"];
echo "MPV: " . $price;
?>
...
You can use method="get" and $_GET["price"] if you want to see these values in url.
i created an ajax favorite button where when a user clicks the heart button the information gets sent to the server without reload and the heart shape becomes filled with red using javascript(exactly like instagram heart button ). now i am having a problem that when the page reloads the heart filling is removed and how will each indiviual message be filled and not only the first instance ?
here is my code:
my html code:
<a href="" class="msg-icon" onclick="toggle()" >
<input type="hidden" name="fav" value="<?php echo $row['msgid']; ?>" style="" >
<i class="far fa-heart" id="favBtn" style="" ></i>
</a>
my javascript code:
function toggle(){
var btn= document.getElementById("favBtn");
if(btn.classList.contains("far")){
btn.classList.remove("far");
btn.classList.add("fas");
}else{
btn.classList.remove("fas");
btn.classList.add("far");
}
}
how can i make it that the heart filling is only removed when the user clicks on the button again for each message?
I see you are using PHP to load the id of the message on page load. I'm guessing you want something similar when setting the initial CSS-classes on "favBtn". The following snippet checks a field on the same $row with php and chooses chat class to show initially based on that.
<i class="<?php if($row['isFavorite'] {echo "fas";} else {echo "far";}) fa-heart" id="favBtn"></i>
Another alternative would be to load the data with an AJAX call, but that would delay the load of the status and probably not what you are looking for in this case.
Good luck!
If those unreadable CSS class names come from an external library, consider putting them into variables with more recognizable names, and using the variables instead of the external names directly.
For example:
var heartOutline = 'far'
var heartFilled = 'fas'
function toggle(){
var btn= document.getElementById("favBtn")
if(btn.classList.contains(heartOutline)){
btn.classList.remove(heartOutline)
btn.classList.add(heartFilled)
}else{
btn.classList.remove(heartFilled)
btn.classList.add(heartOutline)
}
}
// they got rid of semicolons in JS because they wanted to emulate Python
I'm getting used to not using semicolons in JS.
I've got a table of data with clickable rows which will lead to another page based on the row that was selected. To get the row, I am using a form and post the form to another page to pass the variable to php. Now, the problem is once I refresh the page my info is gone...
How can I avoid that?
<?php
$id = $_SESSION["uid"];
$sql = "select * from std_cources join courses where std_cources.std_id = '$id' and courses.course_id = std_cources.course_id";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
echo '
<div class="col-md-4">
<span class="fa-stack fa-4x">
<i class="fa fa-circle fa-stack-2x text-primary"></i>
<i class="fa fa-shopping-cart fa-stack-1x fa-inverse"></i>
</span>
</br>
<p style="color:white;">'.$row["course_name"].'</p>
Check forthe exams
<form name="myform" id="'. $row["course_id"].'" action="checkMarks.php" method="post">
<input type= "text" value ="'. $row["course_id"].' " name="test" style="visibility: hidden;"></input>
</form>
</br>
</div>';
}
}
?>
<script >
function functionTest(form_id) {
document.getElementById(form_id).submit();
}
</script>
I am retrieving names of few courses from database and put them in a table. Then I can click on each one of them and the form submission will be triggered and sends info to the next page and in the next page I get the given info and retrieve info from database again. However, on the second page, if I refresh the page I get
When you refresh a page that has received data from an earlier POST request, the refreshed page won't have that data unless another POST request is made. This can be done in the window object's DOMContentLoaded or load event.
Or, you can make the initial request for the data via a GET request. This will send whatever data you are sending to the server as part of your request as a query string appended to the URL. If you refresh the page, that query string will persist. This will only work if the data you are attempting to get comes from the server-side processing of the current page and not some other URL entirely.
Lastly, POST requests are for requests that change the state of the server (insert, update and delete type of operations). GET should be used for read operations.
Without your code, there's really not much more to offer.
EDIT:
Now that you have posted your code, I would suggest spending some time and cleaning up the HTML string that is sent back from your .php file. There is no such tag as </input> and you should remove the inline HTML event attributes (onclick, etc.). Here's why. Don't use javascript:... either (for many of the same reasons as in the link.
Lastly, I would suggest you change this from a form submission to an AJAX GET request, which will allow you to stay on the same page and keep the currently loaded data.
I am facing a situation that I don't know how to proceed I will try to be clear about what I want to do: here it goes I have 2 files one called index.php (where it's almost all of it HTML code) other indexphp.php where I'm handling PHP code, connecting to DB etc.
here's a print screen of my index.php, this is supposed to be a dashboard that you access after logging in in the application (where I am nesting my HTML code)
dashboard
I am using this
if (!isset($_SESSION['nivel_user'])){
header('Location: /php/logout.php');
} else {
$tu = $_SESSION['nivel_user'];
$userid = $_SESSION['idformador'];
$username = $_SESSION['user'];
}
Session variables in both index.php and indexphp.php and I want it to show different queries according to my login (I have different types of access levels) the results of my queries are supposed to be shown in that dashboard instead of those numbers you see at the top of that print screen, right now there are static values and I want them to be dynamic according to my queries.
I tried something like this but it doesn't work. (Note: Those queries need to be updated on page load since after logging in I automatically access the dashboard)
$(document ).ready(function(){
$('#query1').load('indexphp.php'){
<div class="row tile_count">
<div class="col-md-2 col-sm-4 col-xs-6 tile_stats_count">
<span class="count_top"><i class="fa fa-user"></i> </span>
<div class="count" id="query1">2</div>
<span class="count_bottom"><i class="green">100% </i> </span>
</div>
I am trying to add items from category page. But it is taking me to next product page rather then adding such product into the cart. But same functionality is working ok in product page.
To find the solution i have added to check what array i am getting. After adding it such functionality of add to cart in category page was working. I am a bit confuse what to do with that. Kindly help or advice. Following is the code for Add-to-Cart button in category.tpl file.
<button type="button" onclick="cart.add('<?php echo $product['product_id']; ?>', '<?php echo $product['minimum']; ?>');"><span class="hidden-xs hidden-sm hidden-md"><?php echo $button_cart; ?></span> <i class="fa fa-shopping-cart"></i></button>
Ok, even though I know nothing about opencart i quickly checked the demo.
There seem to be some category items that work to be added as expected:
POST http://demo.opencart.com/index.php?route=checkout/cart/add
200 OK
{"success":"Success: You have added <a href=\"http:\/\/demo.opencart.com\/index.php?route=product\/product
&product_id=41\">iMac<\/a> to your <a href=\"http:\/\/demo.opencart.com\/index.php?route=checkout
\/cart\">shopping cart<\/a>!","total":"2 item(s) - $244.00"}
Other ones return some kind of form error:
POST http://demo.opencart.com/index.php?route=checkout/cart/add
{"error":{"option":{"218":"Radio required!","223":"Checkbox required!","208":"Text required!","217":"Select
required!","209":"Textarea required!","222":"File required!","219":"Date required!","221":"Time required
!","220":"Date & Time required!"}},"redirect":"http:\/\/demo.opencart.com\/index.php?route=product
\/product&product_id=42"}
And instead of showing a decent error message, a redirect url is sent along. Seems that that is the one you then are redirected to. Seems like intended behaviour of the code to hide that an error has happened.
Maybe that helps you to narrow down the bug. Good luck.