Adding parameters from a FORM to URL with queried page - php

I have a search page which is queried from index.php
example : http://localhost/sgc/admin/index.php?page=search
then i created a form within this page to search users by names
<form role="form" method="get" action="" class="form-horizontal">
<input type="search" name="name" class="form-control" placeholder="username">
</form>
the problem is when the input is submitted it redirects to the index.php and adding the paramteres to the index page http://localhost/sgc/admin/index.php?name=
required URL format is to be http://localhost/sgc/admin/index.php?page=search&name=
can it be achived using php or i have to use javascript
Thanks, and sorry for my bad english :)

try :
After submision :
your url : ttp://localhost/sgc/admin/index.php?page=search&name=YOUR_STRING

Related

How to post HTML FORM Data to a http link given to you by a client using php

Hi guys im quite newbie on coding but i want to ask How to post HTML FORM Data to a http link given to you by a client thanks.
Try creating a .html file as below:
<html>
<form method="post" action="urclientlink">
<input type="text" name="firstname"/>
<input type="text" name="lastname"/>
<input type="text" name="submitButton" value="Submit Form"/>
</form>
</html>
Please elaborate on your question for a better answer. Thanks!
This is no different from submitting form data to a page on your own site. You simply amend the form's action attribute:
<form action="http://another-server.com/another-page">
You also need to be sure you get the right METHOD: e.g. GET or POST:
<form action="http://another-server.com/another-page" method="GET">
You will need to check with the client to see which page and method they need.

PhP -Passing Parameters in URL in Form

My URL contains parameters for database Query but when i submit my form on that same page these Parameters are gone .hence resulting in an error for database queries.
This is My URL
localhost/forum_original_code/article_details.php?article_id=3
This is the comment form i am trying to submit.
`<h4>Leave a Comment:</h4>
<form class="well form-horizontal" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>" method="post" id="contact_form">
<div class="form-group">
<textarea class="form-control" rows="3" name="comment"></textarea>
</div>
<button type="submit" class="btn btn-primary">Submit</button>
</form>
`
But when i get the posted values the Parameters form URL are gone.
URL After form submission
http://localhost/forum_original_code/article_details.php
Again resulting in data base query error.
Can somebody guide me how to approach this better.
Thanks.
You are using the POST method in your form. If you POST something you will not be able to see those values in the url. You can access these values via the superglobal $_POST['paramName']. For additional information consider to take a look at the PHP manual;
Set action to
action="<?php echo htmlspecialchars($_SERVER["REQUEST_URI"]);?>"
It will return complete URL with query string.
$_SERVER["PHP_SELF"] only gives you till localhost/forum_original_code/article_details.php

How to add $_POST['variable'] to URL of next page?

I have a simple landing page with a search bar and submit button.
I want the URL of the next page to read: mysite.com/after_search.php?search=*the search text here*.
Here is the code from the landing page / index.php page:
<form class="" action="after_search.php?search="<?php echo $_POST['search_title']?> method="post">
<div class="form-group" id="search_wrapper">
<input type="text" id="search_field" class="form-control color-outline" name="search_title" placeholder="Search">
The issue is that $_POST['search_title'] is not set until the next page loads. So, it does not work because $_POST['search_title'] is not defined on this page.
How do I add the contents of the search bar to the URL of the next page?
EDIT 1
It was suggested that I switch to GET instead of POST.
But on the 2nd page, there are many places that use $_POST['...']
Switching all those to $_GET['...'] has allowed it to work.
Thanks, all
You need to use $_GET method to get the values from a URL:
<form class="" action="after_search.php" method="get">
To get the value, use:
$_GET['search']
If you are passing the value through the link:
?search=the search text here
That means you are using $_GET, thus you need to use $_GET instead of $_POST.
You are getting data, so use GET method and you want adding the variable in url GET method do this.
<form class="" action="after_search.php" method="get">
<div class="form-group" id="search_wrapper">
<input type="text" id="search_field" class="form-control color-outline" name="search" placeholder="Search">
If you have this search_title in URL you can use $_GET['search_title']. If not its unavailable then use a default. Something like
action="after_search.php?search=<?php echo isset($_POST['search_title'])? $_POST['search_title']: ''?>"
Here I used an empty string () as default.

How to combine get method parameter and div id name without javascript?

This is simplified code of index.php :
<form action="index.php" method="get">
<input type="text" name="course">
<button>Find</button>
</form>
Suppose, in the text field "ADAM" is put and after pressing Find button url becomes
myweburl/index.php?course=ADAM
But I want to make it
myweburl/index.php?course=ADAM#courseid
NB: Here courseid is a div id name inside index.php. By this way, I will be able to scroll down the result area.
Do you know how to do this?
Why not do it in a more legitimate way
<form action="index.php" method="get">
<input type="text" name="course">
<input type="hidden" name="courseid" value="<?php echo $courseId;?>">
<button>Find</button>
</form>
Then you get a url like this
myweburl/index.php?course=ADAM&courseid=1234
Now you dont have to do any text manipulation in the script that processes the data you just use
$_GET['course']
$_GET['courseid']
Simply add the hashtag to the action attribute.
The browser would know to move it to the end of the url string (after the GET parameters).
<form action="index.php#courseID" method="get">
<input type="text" name="course">
<button>Find</button>
</form>
Would result:
index.php?course=xxxx#bla
Tested on Chrome, if someone find other results please update.

Display form input value as part of a new page url

I'm trying to display user entered value in form A to be part of the url of page B. For example:
Form A:
<form method="post" action="display_annotation_for_pdbid.php" target="_parent">
<fonttdresult><b>Search Database by PDB ID:</b><br/></fonttdresult>
<input type="text" name="pdbid" id="pdbid" placeholder="Enter a PDB ID" style="width:
106px;">
<input type="submit" name="submit" value="Submit">
</form>
So instead of displaying the new page url as display_annotation_for_pdbid, I want it to display something like 'display_annotation?StructureID:1y26' when the user enters 1y26 in form A. Can someone help me with this?
if you use GET method iin your form to post data , variables will automaticlly be placed in URL
Create another file display_annotation_for_pdbid.php which will contain code to redirect to required url. Try below code
display_annotation_for_pdbid.php
<?php
$pdbid = $_POST['pdbid'];
header("Location : display_annotation.php?StructureID=".$pdbid);
?>

Categories