Check if form exists on a page and hide it - php

I am using osclass for a classifieds website. The theme has some widgets of which one is a search form. It is called into a header which exists on all pages. However, I would like to hide the search form only on this one page.
The form looks like this:
<form class="nocsrf navbar-left form-vertical" action="<?php echo osc_base_url(true); ?>" >
<div class="dropdown navbar-form js-menu-search-container">
…
…
</form>
How can I condition the form to show on all pages except on this one only: item-post.php?
I would greatly appreciate some help here.

You could have a style tag just on that page that hides the search form.
Add the following to the page you want to hide the form on:
<style>
.dropdown.navbar-form.js-menu-search-container {
display: none !important;
}
<style>

<style>
.form-hide{
display:none !important;
}
</style>
<?php
function need_hide_condition(){
$pos = strpos( $_SERVER["REQUEST_URI"], "YourUrl"); //likes /test.php
if( $pos!=false ) return true;
else return false;
}
?>
<form class="nocsrf navbar-left form-vertical <?php if( need_hide_condition() ) echo 'form-hide';?>">

Related

Hide a DIV when displayed in a specific DIV

I'm trying to hide a DIV, but only when it is displayed in another div.
I have a Contact Form that I display in two places, in a sidebar and on a contact page. This is my form that is displayed using PHP include.
<div class="contact_details_div">
<h3>Some Text</h3>
Some additional text
</div>
<div class="contact_div">
<form id="contact_form" action="" method="post" target="_self">
MY FORM IS HERE
</form>
</div>
In my sidebar, the form is displayed like this:
echo "<div class=\"contact_form_sidebar\">";
include("inc/contact_form.inc.php");
echo "</div>";
And, my Contact page it's displayed like this:
echo "<div class=\"contact_form_full\">";
include("inc/contact_form.inc.php");
echo "</div>";
I've tried to hide the class 'contact_details_div when it is displayed in the sidebar, but I can't seem to get it done. This is my CSS:
/*CONTACT FORMS*/
/*FULL FORM*/
.contact_form_full {
position: relative;
}
/*SIDEBAR FORM*/
.contact_form_sidebar {
position: relative;
]
.contact_form_sidebar .contact_details_div {
display: none !important;
}
Does anyone see an issue? I can't, but I've been staring at it too long and am probably missing something simple.
Thanks!
Rick
You have square brackets instead of curly on line 9 in css.

Not sure how to hide/show a specific divider based on a PHP variable [duplicate]

This question already has answers here:
Hiding a Div using php
(6 answers)
Closed 1 year ago.
I've been trying to show a display a specific divider if a variable is true. So let me just show you what I've got so far and hopefully someone will be willing to help.
This is the check that should be performed when the A HREF is clicked:
<?php
function enter_username_phase() {
if (isset($_POST['package'])) {
$package = $_POST['package']);
return true;
} else {
return false;
}
}?>
Now this is the one of the buttons which will send the package id:
<a href='#credits?package=1'>
<div class="box">
<font size="4"><b>Price</b></font><br>Amount<br>
</div>
</a>
Here's the method I use to check if the variable is shown along with the div I'd like to display:
<style>
#enter_username {
<?php
if (enter_username_phase()) {
echo 'display:block;';
}
?>
}
</style>
<div class="enter_username">
<center>
<br>
<form name="username" method="post" action="#credits">
<INPUT type="username" name="username" maxlength="16">
<INPUT TYPE = "Submit" Name="Submit" VALUE = "Check username">
</form>
<br><br>
</center>
</div>
And this is the divider's definition in the css file:
.enter_username {
display: none;
}
I'm assuming I'm going wrong either the way I'm displaying having the element displayed or it's not working because there is nothing that triggers this check, perhaps I need to force a refresh or an update of the page I'm really not sure. I'd like to stick to PHP/CSS/HTML methods to have this done. If anyone is willing to help me I'd really appreciate it, thank you very much for your time and happy holidays.
You should create a css class that hides the element:
<style>
.hidden { display: none; }
</style>
Then conditionally add this class to your element:
<div class="enter_username<?php if (enter_username_phase()) { echo " hidden"; } ?>>
There are more graceful ways of implementing this, but I'd caution against changing your styles based on application logic. Also, in your styles, #enter_username refers to an id, not a class. You'd apply the style to .enter_username if you wanted to target a class.
You are using $_POST method there, but you should use $_GET method. Use this code:
<?php
function enter_username_phase() {
if (isset($_GET['package'])) {
$package = $_GET['package']);
return true;
} else {
return false;
}
}?>
Then it will work..

Change CSS for logged in users WordPress | X Theme

I am attempting to change some css to display:none; when the user is logged in.
It's just a "Sign In / Register" link. ( so when the user is logged on they wont see it)
<span class="hide-this-class-when-logged-in">Sign Up / Register</span>
I have copied my _header.php file into my child theme, and replaced
<body <?php body_class(); ?>>
with this
<body<?php echo (is_user_logged_in() ? ' class="logged-in"' : ''); ?>>
thinking that this would provide an additional .class for logged in users, so I could then
.class {display:block}
.class .logged-in {display:none}
but the body got all screwed up,( everything got a float left; ) and I am back to the drawing board.
Any input on this topic, or how to use body_class() with x theme would be really appreciated. thanks.
Use this in your header.php file.
<body <?php body_class(); ?>>
This built in function already tracks user status, as well as a number of other useful states like page template, page id, etc.
Example of output:
<body class="home page page-id-403 page-template page-template-page-home logged-in admin-bar no-customize-support custom-background group-blog">
https://codex.wordpress.org/Function_Reference/body_class
SOLVED!!!
<body
<?php
if ( is_user_logged_in() ) {
body_class('logged-in');
} else {
body_class('logged-out');
}
?>
>
goes in your _header.php file
.logged-in{whatever;}
.logged-out{whatever;}
try this
//create two variables
$user_loggedin_class = "loggedin";
$user_notlogin_class = "notloggin";
// add css like this
<style type="text/css" >
.loggedin{
display: none;
}
.notloggin{
display: display:block;
}
</style>
// your span tag should like this
<span class="<?php echo ( (is_user_logged_in())?$user_loggedin_class:$user_notlogin_class ); ?>">Sign Up / Register</span>

how to change my web site's elements style dynamicly

In index.php file I first check if $_SESSION['user'] is set it would not show the login form and if not, the login form should be shown.
Here is my login form style
<style>
#login_form{visibility:hidden;}
</style>
And my PHP script is:
<?php
if(isset($_SESSION['user']))
dont show the login form;
else
show the login form;
?>
and the question is: how can I change the #login_form style to visible?
Why not adding an inline style (perhaps a class would be even better) when the user is logged in?
<form style="<?php if(isset($_SESSION['user'])) { echo 'visibility: hidden;';}?>">
<!-- Rest of the form -->
</form>
Or even better, print the form only when is logged in (so visitors can't force the browser to display the form):
<?php if(isset($_SESSION['user'])) { ?>
<form>
<!-- Rest of the form -->
</form>
<?php } ?>
Create a CSS class:
.invisible {
visibility: hidden;
}
Then apply it when your user is already logged in:
<form class="<?=isset($_SESSION['user']) ? 'invisible' : ''?>">
You can have it directly in the div that holds the form, like this:
<div style="<?if(isset($_SESSION['user'])){echo 'display:block'}else{echo 'display:none'}?>">
...Form code
</div>

How to hide div serverside by reading cookie

I am using following a tutorial from here: http://www.shopdev.co.uk/blog/cookies-with-jquery-designing-collapsible-layouts/
This is the script I use:
<script type="text/javascript" language="javascript">
$(function() {
// SETUP:
// When the info banner is clicked:
$('#setup').click(function() {
$('#intro').css("display","none");
$.cookie('intro', 'collapsed');
});
// COOKIES
// Info banner state
var intro = $.cookie('intro');
// READ THE COOKIES
if (intro == 'collapsed') {
$('#intro').css("display","none");
};
});
</script>
The script hides the following div as the cookie is read:
<div class="feedback attention" id="intro">
Text goes here
<a id="setup" href="#">Ok I get it, please hide this</a>
</div>
Everything work great but when the page loads the div is shown for a split second. I guess the solution is to present two different pieces of markup serverside according to the cookie info. I have no idea how to go about this.
On page load, you could use php to check the cookie, and then add a hidden class. Something like <div class="<?= $_COOKIE['intro'] == 'collapsed' ? 'hidden':'' ?>">
Edit:
In CSS then, you can add something like .hidden { display: none; } and use jQuery to add or remove that class.
You could just do something like:
<?php
if($_COOKIE['intro'] != 'collapsed') {\
//echo div...
}
if you are using PHP:
<?php if($_COOKIE['intro'] != 'collapsed'){ ?>
<div class="feedback attention" id="intro">
Text goes here
<a id="setup" href="#">Ok I get it, please hide this</a>
</div>
<?php } ?>
To completely remove the div rather than just hide it.
check $_COOKIE array for 'intro'
if ($_COOKIE['intro'] == 'collapsed')
//...
simply, add some kind of "hidden" class to the div, or specify it like style="display: none;"
//edit
actually, by adding the "style" attribute you ensure that the div is not displayed as soon as get parsed, while using "class" property might cause interval while waiting for CSS file.
thus
<div<?= ($_COOKIE['intro'] == 'collapsed') ? ' style="display: none"' : '' ?>> ..</div>
is best here.

Categories