Form action URL - Plus to space - html

I have a form in my wordpress theme. I want add a "plus" to space in url.
My source code:
<form method="get" id="searchform" action="/search/" onsubmit="return false;">
<input type="text" name="s" id="s" placeholder="Search" />
<input type="submit" class="submit" id="searchsubmit" value="<?php esc_attr_e( '', 'themeO' ); ?>" onclick="window.location.href=this.form.action + this.form.s.value;" />
</form>
my actual search url - keyword : "good job"
http://www.example.com/search/good job
I need this url:
http://www.example.com/search/good+job

You can use replace() to replace spaces with pluses:
window.location.href=this.form.action + this.form.s.value.replace(/\s+/g,"+");

Related

add parameters to form url before submit

I need to add a path to a file to the form url before submitting. I created therefore a text field and want to add the text to the url without php.
can somebody help?
the existing code:
<form action="http://127.0.0.1:8080/WebService1/HTTPMethod_1?new_value=value" method="post">
<input type="text" value="" size="30" name="filename">
<input type="submit" name="submit" value="Submit" class="continue-button">
</form>
look into using hidden input fields. these allow you to send form data, but not necessarily show a form field.
for instance:
<script type="text/javascript">
function setFormAction() {
document.myForm.action = document.getElementById("url").value;
}
</script>
<form name="myForm" method="POST" action="default.php">
<input type="value" name="url" id="url" />
<input type="submit" name="submit" onclick="setFormAction();" />
</form>

Can't type in textarea [duplicate]

I need help. My form in my page looks like below however when I click on the text box the cursor won't appear and I can't type
<form name="input" action="postblog.php?name=<?PHP echo ($_GET['name']); ?>" method="post">
Post: <input type="text" name="text2">
<input type="submit" value="Submit">
</form>
There's probably an error that's not being displayed on your screen because it's appearing inside the HTML tags. Make sure to check if $_GET['name'] is set first:
<form name="input" action="postblog.php?name=<?php echo ($_GET && isset($_GET['name'])) ? $_GET['name'] : 'No_Name_Value_From_GET'; ?>" method="post">
Post: <input type="text" name="text2" />
<input type="submit" value="Submit" />
</form>
In this instance, if $_GET['name'] is not set, the value for ?name= will be No_Name_Value_From_GET (but you can change it to whatever you want).
HTH... :)

How to GET data but preserve link array

Let's say I have index.php?couple=old and I want to GET new data (search all couples that are "old" but get new data) for example
<form action="index.php?couple=old" method="get">
<input type="text" name="search" >
<input type="submit" name="search_btn" />
</form>
And someone enters keyword "Smith" it should be index.php?couple=old&search=Smith
couple must be a variable to pass, otherwise PHP does not store it as part of $_GET.
You need:
<form action="index.php" method="get">
<input type="hidden" name="couple" value="old" />
<input type="text" name="search" />
<input type="submit" name="search_btn" />
</form>
maybe little bit more better solution (if you have couple of parameters you want to use).
<form action="index.php" method="get">
<?php foreach($_GET as $name=>$value):?>
<input type="hidden" name="<?php echo $name; ?>" value="<?php echo $value; ?>" />
<?php endforeach;?>
<input type="text" name="search" />
<input type="submit" name="search_btn" />
</form>

mysql 404 error

have the following code:
<?php
if (isset($_POST['submitted'])) {
$reqwidth = $_POST['reqwidth'];
$reqside = $_POST['reqside'];
$reqrad = $_POST['reqrad'];
$sqlinsert = "INSERT INTO tirelist (width, sidewall, radial) VALUES ('$reqwidth','$reqside', '$reqrad')";
if (!mysqli_query($dbcon, $sqlinsert)) {
die('error inserting new record');
}
$newrecord = "1 record added to database";
}
?>
<html>
<head>
<title>Request Tire Size</title>
</head>
<body>
<h1>Request Tire Size</h1>
<form method="post" action="insert-data.php">
<input type="hidden" name="submitted" value="true" />
<fieldset>
<legend>Request Tire</legend>
<label>Tire Width: <input type="text" name="reqwidth" /></label>
<label>Tire Sidewall: <input type="text" name="reqside" /></label>
<label>Tire Radial: <input type="text" name="reqrad" /></label>
</fieldset>
<br />
<input type="submit" value="Send Order Request" />
</form>
when i click send order request, I get a 404 error.
i noticed the page is called ~http://localhost/index.php?p=test2~, but when i click it redirects me to ~http://localhost/insert-data.php~
been trying for hours, wondering what i could do to fix it
Change
<form method="post" action="insert-data.php">
to have index.php?p=test2 instead.
In your form, you reference insert-data.php. Does that exist?
If you're trying to submit the form to the same file, you can try to use this:
<form method="post" action="<?php echo $_SERVER['PHP_SELF'] ?>">
Try this instead. form method="post" action="/insert-data.php"

How do I make my Search Field show some text and make it disappear when it's clicked

I want my search field to say "Where are you" make it disappear when clicked and and appear again when if he clicks outside leaving it blank.
This is the search form:
<div id="search-10" class="widget_search">
<form role="search" method="get" id="searchform" action="http://chusmix.com/?s=" onsubmit="window.location = action + s.value + '+: <?php the_search_query() ?>'; return false;">
<div>
<input class="ubicacion" type="text" value="" name="s" id="s2" style="margin-left:0px;">
<input type="submit" id="searchsubmit" value="Buscar">
</div>
</form></div>
I tried this but for some reason it didn't work:
<li id="search-10" class="widget_search">
<form role="search" method="get" id="searchform" action="http://chusmix.com/">
<div>
<input class="ubicacion" type="text" value="" name="s" id="s" style="margin-left:418px;">
<input type="submit" id="searchsubmit" value="Buscar" onblur=" if(this.value== '') this.value='Where are you';" onfocus=" if(this.value=='Where are you') this.value=''; " value="Where are you" name="keyword" />
</div>
</form></li>
This removes the default text when a user clicks on the search form and adds it back when the user clicks off the search form.
<form id="searchform" method="get" action="search.php">
<input class="textbox" value="Search" name="s" id="s" onfocus="if (this.value == 'Search') {this.value = '';}" onblur="if (this.value == '') {this.value = 'Search';}" type="text">
<input type="submit" id="searchsubmit" value="" class="searchsubmit" />
</form>
Fake the border of the input using a div, and position the real input and a label inside it - one of top of the other.
Conceal the label when the element gets the focus, put it back when the focus is lost if the value is blank.
There is an example using jQuery.
See the example below for raw javascript -
<input type="text" onblur=" if(this.value== '') this.value='Where are you';" onfocus=" if(this.value=='Where are you') this.value=''; " value="Where are you" name="keyword" />
Beside this, you can use jquery, dojo, mootools plugin to handle this.