add query on href using input - php

I have an
<input type=text name=search />
and I wanted to add the value of input to my href
<a href='index.php?search=$search>submit</a>
But I think that won't work on php alone right?
How can I add the value of my input to my href as it clicks?
NOTE: need to appear in the browser url menu this way
index.php?search=anyvalue
as soon as they click it. because I'm using pagination

Straight HTML - no PHP or JavaScript Needed
<form action="index.php" method="get">
<input type="text" name="search" />
<button type="submit">Submit</button>
</form>
Once clicked it will take the user to: index.php?search={value of input}
For pagination to work it would be:
Page 2
Page 3

try this:
<form method="get" action="index.php">
<input name="search" type="text" />
<input type="submit" />
</form>
If that's not what your looking for just elaborate a bit on what you are trying to achieve.

you must open a php tag like this:
<a href='index.php?search=<?php echo $search;?>' >submit</a>
but it work after submitting the form.
use javascript

Related

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.

User input not showing in search form

I have a free form search that I moved from my main content to my header. Once I moved the form into the header the text inside of it stopped showing. The placeholder works but when you begin typing it is completely blank. The search and the functionality work perfectly, I just cannot see what I am typing. Any ideas?
<form class="search" action="/all-results/" method="get">
<fieldset>
<span class="text"><input name="searchProducts" value="All" type="hidden">
<input type="hidden" name="search_selection" value="all">
<input name="byString" id="s" type="text" value="" placeholder="<?php echo __('Search','Avada'); ?>" /></span>
</fieldset>
<form name="input" action="/all-results/" method="get">
<input type="submit" id="search_button" value="Search">
</form>
</form>
Your HTML is invalid. You can not nest a <form> element inside another <form>. Messing up forms and tables are two of the best ways to produces peculiar browser behaviour, so my guess is that this is your problem.
If you correct your HTML (validate it!) and the problem persists, then post a minimal HTML page with CSS so that there is something for us to debug.

Passing value with a button in the form

I am trying to pass a value through clicking a button that is inside a form.
Below is my code:
<form action=deleteProduct.php?skuCode=".$row["skuCode"]." method=get><input type=submit name=delete value=Delete></form>
But from the above code I wanted to get the skuCode=".$row["skuCode"].". Instead the value passed was delete=Delete.
How should I amend my code to get the skuCode in deleteProduct.php.
Try this one :
<form action="deleteProduct.php" method="get">
<input type="hidden" value="<?php echo $row["skuCode"] ?>" name="skuCode">
<input type="submit" value="Delete">
</form>
In the deleteProduct.php page, you can access the value by using $_GET['skuCode']
It seems you may be outputting it all in a single echo. In this case, the solution will require a few extra lines, so it'd probably be best to change it to:
//close off PHP if required
?>
<form action="deleteProduct.php" method="get">
<input type="hidden" value="<?php echo $row['skuCode'] ?>" name="skuCode">
<input type="submit" value="Delete">
</form>
<?php
//resume PHP if need be
Something to that effect should work.
I'm not 100% sure how your $row["skuCode"] part works.. I guess it's PHP? Either way, just insert the value however you need to, but that HTML should do it.
Fiddle:http://jsfiddle.net/rt9yc/
In this jsfiddle, when I click on the delete button with the network tools open in my inspector I see a request for: deleteProduct.php?skuCode=testSKU ("testSKU" being the dummy SKU I was using in the fiddle)

Facebook iframe - how to send form (POST method)?

I have very simple form (the file is called message.php):
<?php
print_r($_POST);
?>
<form method="post" target="_top" action="<?php echo CANVAS_URL;?>message.php">
<input type="text" name="your_name" />
<input type="hidden" name="signed_request" value="<?php echo $_REQUEST['signed_request'];?>" />
<input type="submit" name="send" />
</form>
I found one solution of this issue - put into the form hidden input with the signed_request - I did it but unfortunately I am still facing with this problem -- I cannot retrieve sent POST data.
If I change the method to method="get", everything is working well, but I would need to data from POST.
Could anyone help me, how to solve this problem? Thanks!
Try this. I don't believe you need to use target in FB canvas aps anymore. Also a form ID would be good.
<form method="POST" id="my_form" action="message.php">
<input type="text" name="your_name" />
<input type="hidden" value="<?php print $_POST["signed_request"] ?>" name="signed_request" />
<input type="submit" name="submit" />
</form>
POSTing to Canvas URLs (as in http://apps.facebook.com/namespace) is simply not supported.
But why post to the top window instead of simply staying within the iframe? It's way better as it doesn't require the entire page to be reloaded, only the iframe.

Getting correct URL when using GET

When clicking a button, I would like my URL to become this:
users.php?action=search&formvar1=value&formvar2=value&...
This is what I've tried:
<form id="search" action="users.php?action=search" method="get">
But this doesn't seem to work (it doesn't add the action=search part). Is there any way to do this? I know it works when using POST instead of GET, so why wouldn't it here?
Thank you
You can do that similarly to a POST form. Simply include the default attribute as hidden form field:
<form id="search" action="users.php" method="get">
<input type="hidden" name="action" value="search">
This way it will be added as parameter to the URL like all other variables.
The browser is building the query string from scratch.
Instead, you can add an <input type="hidden" name="action" value="search" />.

Categories