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"])
Related
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.
<form entype="multipart/form-data" method="GET" action="">
<div class="box-body">
<input class="form-control input-lg" name="keyword" type="text" placeholder="Masukkan kata kunci">
</div>
<div class="box-body">
<input value="1" type="checkbox" class="minimal" name="queryexp" />
Gunakan query expansion
</div>
<div class="box-footer">
<button type="submit" class="btn btn-primary" value="Submit">Submit</button>
</div>
</form>
Hi hello I want to ask a simple question. The code above is search.php,
I want to send the form to a different page based on if the checkbox is checked or not. If the checkbox is checked it will be directed to resqueryexp.php, but if not it will be directed to result.php
I have been trying to adding this code but it doesn't work.
<?php
if (isset($_GET['queryexp'])){
header("Location: resqueryexp.php");
}else{
header("Location: result.php");
}?>
Sorry for my bad English and Thanks in advance.
<?php
if ( isset( $_GET['submit'] )) {
if ($_GET['queryexp'] == 1 ){
header("Location: resqueryexp.php");
exit;
}
else
{
header("Location: result.php");
exit;
}
}
?>
<html>
<head><title>test</title>
</head>
<body>
<form enctype="multipart/form-data" method="GET" action="">
<div class="box-body">
<input class="form-control input-lg" name="keyword" type="text" placeholder="Masukkan kata kunci">
</div>
<div class="box-body">
<input value="1" type="checkbox" class="minimal" name="queryexp" />
Gunakan query expansion
</div>
<div class="box-footer">
<button type="submit" name="submit" class="btn btn-primary" value="Submit">Submit</button>
</div>
</form>
This code won't run here at SO, but this is how it may work on your webserver. The important part is to test if the form was submitted. So, in this case, I gave the submit button the name of "submit" and then tested with PHP to see if the form was even submitted. If the form is submitted and if the checkbox is checked, the redirect via header() occurs. Otherwise, if the checkbox is unchecked, then the redirect occurs via header to result.php. You may avoid header issues by making an adjustment to you PHP.ini settings and adding this line "output_buffering = On".
Note: usually a form with the enctype attribute having a value of "multipart/form-data" involves submitting a file and under such circumstances the method attribute should be a POST request instead of a GET; see MDN.
Remember that header() must be called before any actual output is
sent, either by normal HTML tags, blank lines in a file, or from PHP.
It is a very common error to read code with include, or require,
functions, or another file access function, and have spaces or empty
lines that are output before header() is called. The same problem
exists when using a single PHP/HTML file.
<html>
<?php
/* This will give an error. Note the output
* above, which is before the header() call */
header('Location: http://www.example.com/');
exit;
?>
http://php.net/manual/en/function.header.php
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.
So I'm trying to use this http://www.formget.com/how-to-redirect-a-url-php-form/ as an RSVP form.
Ideally, entering the right code on (http://baby.engquist.com/invite/) will lead you to a google form. However, when I enter any code (right or wrong) and press the button, it simply refreshes back to the /invite page.
My code is as follows:
<p style="text-align: center;">
<form action="index.php" id="#form" method="post" name="#form">
<div class="row">
<div class="large-3 columns large-centered">
<div class="row collapse">
<div class="small-10 columns">
<input id="code" name="code" placeholder="Enter the code to RSVP." type="text" >
</div>
<div class="small-2 columns">
<input id='btn' name="submit" type='submit' class="button prefix" value='Go'>
</div>
</div>
</div>
</div>
<?php
include "redirect.php";
?>
</form>
</p>
And the included redirect.php:
<?php
if(isset($_POST['submit'])){
// Fetching variables of the form which travels in URL
$code = $_POST['code'];
if($code ='show620')
{
// To redirect form on a particular page
header("Location:http://google.com/");
} else {
print "Oops that's not the right code. Try again!";
}
?>
Thanks so much for any help!
You should have action attribute pointing to file where you do processing after submitting. In your case its redirect.php
Use :
<form action="redirect.php" > ............
And dont include redirect.php at the bottom of the form.
You need to write ob_start(); on top of your page and die(); after header("Location:http://google.com/"); in redirect.php
The php header redirect only works if it's called from a page that is completely blank. You have to change your form action to "redirect.php" and simply get rid of the code at the bottom of your html.
I'm trying to create a page with a form using ci.
When i submit the form, the controller says that I have no data that's been submitted.
I can't see where my error lies.
Here's the view:
<?php echo validation_errors(); ?>
<?php echo form_open('widgets/search/'.$hardwaremodel.'/'.$objectid.'/'.$name.'/'.$fd); ?>
<div class="form-group">
<label for="search">Last 4 characters of address:</label>
<input type="text" class="form-control" id="searchstring" placeholder="last 4 characters" size="4">
</div>
<button type="submit" class="btn btn-default">Search</button>
<button type="cancel" class="btn btn-default">Cancel</button>
</form>
Once the page renders, the form tag ends up looking like this:
<form action="http://myserver/myciapp/index.php/widgets/search/205406zl/5461/SW-1/SW1net" method="post" accept-charset="utf-8">
The controller:
public function search()
{
$searchstring = $this->input->post(); // form data
var_dump($searchstring);
exit;
}
The results of the var_dump shows:
bool(false)
Thanks
EDIT 1
I haven't posted the entire HTML page that includes the form... but I display some of the fields passed in the URI as headings on the page - just before I create the form. Hope that clarifies...
Would this impact the POST data? Why is that relevant?
Thanks
A few things I'd suggest doing. First is, if you are going to include other variables in the form_open tag, I would add those variables to your controller, and put them in the form_open tag as URI strings. This will allow the form validation to work if you are going to echo out validation errors.
Also, you should be calling a name on the input->post() to get the specific item, (but you don't need to to get all POST data).
Controller:
public function search($hardwaremodel, $objectid, $name, $fd) {
$searchstring = $this->input->post('search_string'); // form data
var_dump($searchstring);
exit;
}
View:
<?php echo form_open('widgets/search/'.$this->uri->segment(3).'/'.$this->uri->segment(4).'/'.$this->uri->segment(5).'/'.$this->uri->segment(6)); ?>
<div class="form-group">
<label for="search">Last 4 characters of address:</label>
<input type="text" class="form-control" id="search string" name="search_string" placeholder="last 4 characters" size="4">
</div>
Form elements are referenced by name attribute which is missiong on input field searchstring.
Add:
name="searchstring"
on your input field.
in this code you have not used name attribute.You use id.
try this one
<input type="text" name="searchstring" value="xyz">