WordPress Search Error: ?s= in URL - php

So I'm doing a few stuff for this humanitarian association and they asked me to add a search button on their navbar.
So far I came up with two solutions but none of them work. They both add "?s=" into the URL, thus redirecting to an empty URL.
Example: if you type "programme" in the search field, the URL will be: http://pisad.org/?s=programme. This is an empty URL and it should ultimately redirect to http://pisad.org/nos-programmes-inedits/ instead.
The first solution tried: search on navigation menu plugin:
https://wordpress.org/plugins/search-box-on-navigation-menu/
The second solution tried: adding this code to the navbar
<form class="navbar-form navbar-right search-form searchform" id="searchform" role="search" method="GET" action="<?php echo esc_url( home_url( '/' )); ?>" id="searchform">
<div class="form-group">
<input type="text" class="form-control" placeholder="Rechercher" name="s" id="s">
</div>
<button type="submit" class="btn btn-default">Rechercher</button>
</form>
Any idea why it's like that?

Related

Wordpress: Custom search result page throws 404

I have followed the link here in codex and created the following
This is my searchform.php
<form action="/search" method="get" role="search" id="searchform">
<div class="input-group">
<input type="text" name="s" id="search" class="form-control search-bar" placeholder="Search Healthkart Blog" value="<?php the_search_query(); ?>">
<div class="input-group-append button-icon">
<button class="btn" type="button" id="searchBtn">
<img src="<?php echo get_stylesheet_directory_uri(); ?>/assets/images/search-icon.png" alt="search" class="search-icon-white">
<img src="<?php echo get_stylesheet_directory_uri(); ?>/assets/images/search-icon-grey.png" alt="search" class="search-icon-grey">
</button>
</div>
</div>
</form>
I have included it in header.php as
get_search_form();
And the JS for submitting the form in this way
$("#searchBtn").click(function(){
$("#searchform").submit();
})
I have also created a custom search result page called search.php and it contains the normal search page code. Then I have created a page in wordpress pages called search (URL as /search) and assigned the custom search result template to it.
The issue is when I submit the form, it gets redirected to /search/?s=test123 and returns a 404 page. But if I hit the urls /search/test123, it works.
How do I make the search form submit to the URL /search/test123 ?
How do I make the search form submit to the URL /search/test123 ?
You can add :
$("#searchform").on('submit', function(e) {
e.preventDefault();
window.location = $("#searchform").attr('action') +'/'+ $("#searchform #search").val();
});
But with this solution, browser without JavaScript won't work.
To fix it, you can add the following to the search template:
if (isset($_GET['s']) && !empty($_GET['s'])) {
wp_redirect(get_permalink() . $_GET['s'], 301);
die();
}

Codeigniter : Pass data from view to controller using anchor tag

I am working on a project where I need to pass an ID to controller when someone clicks on the link, and open response in new tab.
I googled for solution on this, but couldn't find proper result. I also tried by sending data through URL in anchor tag, but then it gave an error of config.php file, so I reversed the code.
Currently I am using form tag to pass data. Can ye do this using PHP, or will we have to take help of jquery?
Here's View code:
<form class="form-horizontal" method="post" action='<?php echo base_url() . "home/edit_policy"; ?>'>
<div class="form-group">
<input type="hidden" class="form-control" id="polid" name="polid" value="<?php echo $ajax_view_pol_response[0]->polid; ?>">
<div class="col-sm-offset-3 col-sm-3">
<button class="btn btn-primary" id="editpolsubmit">Edit this Policy</button>
</div>
</div>
</font>
This code is from Controller:
public function edit_policy() {
$polid = $this->input->post('polid');
}
I want to transfer the "polid" from view to controller function using anchor tag.
All positive suggestions are appreciated.

Search page does not show the search results in WordPress

I have a searchform.php file which contains the following code:
<form role="search" method="get" id="searchform" action="<?php echo home_url( '/' ); ?>">
<div><label class="screen-reader-text" for="s">Search for</label>
<input type="text" value="" name="s" id="s" />
<input type="submit" id="searchsumit" value="Search" />
</div>
Also in my index.php I've inserted this code:
<div class="search">
<?php get_search_form(); ?>
</div>
Now When I search for something I get no results. Therefore I added a search.php file to show the results in it but I still don't get the results. What kind of changes should be made? Or what piece of code is lacking?
Note that I want to show the results in a separate page which must be search.php in Wordpress.
You need to add search.php file inside the theme and in that you will need to add the view for the search result page and the result can be obtained by looping for e.g
while(have_posts() ) : the_post();
//here is your data
endwhile;

CodeIgniter URL repetition

I just started CodeIgnitor, that's the first time I use MVC structure though, and I have a problem that I've never seen before... It's mainly in the "form" part, but also in the database display.Also I use Xampp.
I've got a form to create an item to insert in the database, but whenever i click the submit button, things gets wrong in the url section.
My base URL is : localhost/CodeIgniter-3.1.1/ (CodeIgniter-3.1.1 is the directory that contain every php folder).
So the form page URL is : localhost/CodeIgniter-3.1.1/index.php/news/create
And when i submit, it is : localhost/CodeIgniter-3.1.1/index.php/news/localhost/CodeIgniter-3.1.1/index.php/news/create
It just repeat the entire URL after the controller (news).
I don't think it has to be with config.php, my base URL seems good, I just don't know.
Make your base url http://localhost/Codeigniter-3.1.1/index.php/ then in your <form> tag set the url like this <form method="post" action="<?= base_url('news/create') ?>">
In /application/config/config.php set $config['base_url'] like this
$config['base_url'] = http://localhost/Codeigniter-3.1.1/
In your view do either one of the following to create the <form> tag
<form method="post" action="<?= base_url('news/create'); ?>">
of if you have loaded the "Form Helper" (documented here) use this line in the view
<?php echo form_open('news/create'); ?>
It's handle by the framework, as so:
<h2><?php echo $title; ?></h2>
<?php echo validation_errors(); ?>
<?php echo form_open('news/create'); ?>
<label for="title">Title</label>
<input type="input" name="title" /><br />
<label for="text">Text</label>
<textarea name="text"></textarea><br />
<input type="submit" name="submit" value="Create news item" />
</form>
Also, the problem occure when I put a link to a view, like :
<a href="<?php echo 'news/'.$news_item['slug']; ?>">
Instead of building the right URL it copy itself along the bar.

Trying to use $_GET with query strings

Something isn't working right when I submit a URL into the input field. I get a broken image thumbnail for a split second and then a
Forbidden: You don't have permission to access /tests/test.php on this server. Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.
Here is what the url looks like after I click submit:
.../test.php?gif=http%3A%2F%2Fi.imgur.com%2F8j1RD.jpg
And here is what it looked like in the input field:
Is it because I need URI encoding or something like that?
EDIT:
Here is my html markup:
<form method="get" action="form.php">
<center>
<div class="row">
<div class="col-lg-12" id="gif-btn">
<img class="img-responsive" src="<?=urldecode($gif)?>"/>
</div>
</div>
<br/>
<input type="text" name="gif" class="form-control" placeholder="Gif link here..." id="txt"/>
<br/>
<input type="submit" class="btn btn-danger" value="Load" id="gif-btn" onclick="getGif();"/>
</center>
</form>
And PHP form:
<?php
$gif = $_GET['gif'];
?>
Yes. URL decode the string that you get from your $_GET and you should get your link back
Try this
echo urldecode($_GET["gif"])

Categories