User input not showing in search form - php

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.

Related

HTML/PHP : how can I have multiple form that send informations to the same page?

My problem is this :
I got 2 forms that are supposed to send different informations to the same page (via POST method). Each form has a submit button. However when I press any of the button, information from both forms are sent to the page.
Is it normal or is there something that I do wrong ?
I can already tell you without looking at your HTML.
You have to properly close the first form before opening the second. Easy mistake to make.
<form method="post" action="page.php">
<input type="text" name="something" />
<input type="submit" value="Submit" />
</form>
<form method="post" action="page.php">
<input type="text" name="somethingelse" />
<input type="submit" value="Submit" />
</form>

Backslash at the end of searchword breaks custom search form

Accidentally, I discovered that whenever there is a backslash at the end of a search, the page after clicking submit will return a broken search form.
In my case, the submit button turned into a text area.
Using Google Chrome's "inspect element" I saw that my search form turned into this:
<form method="get" action="">
<input type="hidden" name="type" value="books">
<input type="text" name="search" value="\"> <input type=">
</form>
</div></div></div><div id=" sidebar"="" class="sidebar widget-area"></form>
The following code is my form. I am guessing that I need to sanitize/escape the value from the input type text? But why isn't esc_attr() working?
<form action="" method="get">
<input type="text" name="search" value="<?php echo esc_attr(stripslashes($_GET['search'])); ?>">
<input type="submit" value="Search">
<input type="checkbox" name="title">
</form>
P.S. I am using this custom search form to search custom fields and display the resulting custom post types using Pods Plugin. It doesn't appear that this is a Pods plugin issue though.
https://github.com/pods-framework/pods/issues/1620
Also, this doesn't appear to be a conflict from another theme or plugin.
I've made some test, I'm guessing that your question was missunderstood, this code should work:
<form action="" method="get">
<input type="text" name="search" value="<?php echo urldecode($_GET['search']); ?>">
<input type="submit" value="Search">
<input type="checkbox" name="title">
</form>
You can check the php urldecode function for extra info.
Decoding an url is the oposite of encoding it, when a special character is submited it needs to be encoded, when you want to display it you'll have to decode it.
EDIT:
After the form is submitted, when its values are processed, then you have to use esc_attr(stripslashes($_GET['search'])) so that the value becomes encoded and sql-injections and other format issues are avoided, again this has to happen in the php file where the form is processed, usually after an if ($_GET) statement.
I have tried dozens of sanitation and escaping. But in the end, only preg_replace worked against that annoying backslash.

Sending Form variables to a external page and get the html from server

I don't know if this is possible, what I want is just to get the html or the plain-text from the result of a form sent to a external page.
In this case, I have a form that send the variables to a external server and the result goes to the iframe, how I retrieve the html or text from the iframe? This is the correct way?
I'm trying to do this just to simplify a repetitive process here on my agency...
<form name="form" method="post" action="https://www.externalpage.com" target="iframe">
<input type="hidden" name="a" value="0000"/>
<input type="hidden" name="b" value="0001" />
<input type="hidden" name="c" value="0002" />
<p>
<input type="submit" id="button" value="Submit" />
</p>
</form>
<iframe name="iframe" scrollbars="no"></iframe>
Assuming from the tags you are using jquery
var myresult = $('iframe[name="iframe"]').html();
Should do the work.
//edit: just noticed the iframe is from an external domain, it might be subject to the same origin policy, in this case the above code might not work

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.

add query on href using input

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

Categories