form search to url - php

I have the following code:
<form action="search.php" method="get" name="searchprod" id="prodsearch">
<table border="0" cellpadding="0" cellspacing="0">
<tbody><tr>
<td><input name="q" type="text" id="searchbox" value="Search" onfocus="this.value=''; this.style.color='#333333';" /></td>
<td><input type="submit" value="Search" class="searchButton" /></td>
</tr>
</tbody></table>
</form>
When a user searches how can i make it so it looks like this "Dvd-player.html" instead of "search.php?q=dvd+player"
I have the .htaccess in place however not sure how to do it within the form.

You could use Javascript to change the form action to searchbox-value.html in the onsubmit event of the form.

Related

how to send data of all the forms in a page using one submit button?

Here is my index.php
<!doctype html>
<html>
<head>
<title>welcome to vikash general shop</title>
<link rel="stylesheet" type="text/css" href="css/table_styling.css">
</head>
<body>
<table>
<tr>
<td>Item</td>
<td>Amount(kg)</td>
<td>Amount(gm)</td>
</tr>
<tr>
<td>Sugar</td>
<td><form method="POST" action="process.php"><input type="text" name="sugar_amount_kg"/></form></td>
<td><form method="POST" action="process.php"><input type="text" name="sugar_amount_gm"/></form></td>
</tr>
<tr>
<td>Rice</td>
<td><form method="POST" action="process.php"><input type="text" name="rice_amount_kg"/></form></td>
<td><form method="POST" action="process.php"><input type="text" name="rice_amount_gm"/></form></td>
</tr>
</table>
<form method="POST" action="process.php">
<input type="submit" name="submit" value="submit" />
</form>
</body>
</html>
actually i want to send data of all the forms in page using one submit button it is not working. It's obvious because submit button is only sending it's own form tag(quite selfish :P). So i want to know how to send data of all the forms using one submit button...
or if you have any other solution for my code then please tell me...
Just make one form. Wrap your table with form tags, because it's all being processed by process.php anyway.
<form method="POST" action="process.php">
<table>
<tr>
<td>Item</td>
<td>Amount(kg)</td>
<td>Amount(gm)</td>
</tr>
<tr>
<td>Sugar</td>
<td><input type="text" name="sugar_amount_kg"/></td>
<td><input type="text" name="sugar_amount_gm"/></td>
</tr>
<tr>
<td>Rice</td>
<td><input type="text" name="rice_amount_kg"/></td>
<td><input type="text" name="rice_amount_gm"/></td>
</tr>
</table>
<input type="submit" name="submit" value="submit" />
</form>
You do not need to add the form tags multiple times. Just wrap it around the input fields and add the action attribute in it like so:
<table>
<form action="process.php" method="post">
<tr>
<td>Item</td>
<td>Amount(kg)</td>
<td>Amount(gm)</td>
</tr>
<tr>
<td>Sugar</td>
<td><input type="text" name="sugar_amount_kg"/></td>
<td><input type="text" name="sugar_amount_gm"/></td>
</tr>
<tr>
<td>Rice</td>
<td><input type="text" name="rice_amount_kg"/></td>
<td><input type="text" name="rice_amount_gm"/></td>
</tr>
<input type="submit" name="submit" value="submit" />
</form>
</table>
And then you can get the inputs in process.php as follows:
if(isset($_POST['submit'])){ //checking if form was submitted
$sugar_amount_kg = $_POST['sugar_amount_kg'];
...
}
Hope this helps!
This question has been asked a few times. Do a quick search and you will see ways of doing this with JS/jQuery. Examples here and here.
Doing it in one form really might make more sense though for your specific use.

Multiple Submit Buttons in HTML

For testing purpose I designed simple HTML form as follows
<html>
<head>
<title>Test Form</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<table border="0" align="center">
<tbody>
<tr>
<td>First Name</td>
<td><input type="text" name="txtfname" value="" size="10" /></td>
</tr>
<tr>
<td>Last Name</td>
<td><input type="text" name="txtlname" value="" size="10" /></td>
</tr>
<tr>
</tbody>
</table>
</body>
</html>
Now on this single HTML page I want to perform basic SQL functionality with MySQL using PHP. I want 4 submit buttons (Insert Delete Update Search) on single HTML form. I tried it by taking DIV tag but still its not working. Any suggestions???
<form method="post">
<table border="0" align="center">
<tbody>
<tr>
<td>First Name</td>
<td><input type="text" name="txtfname" value="" size="10" /></td>
</tr>
<tr>
<td>Last Name</td>
<td><input type="text" name="txtlname" value="" size="10" /></td>
</tr>
<tr>
<input type="submit" name="insert" value="insert" />
<input type="submit" name="update" value="update" />
<input type="submit" name="delete" value="delete" />
<input type="submit" name="search" value="search" />
</tr>
</tbody>
</table>
</form>
Now you can check which button was used to submit using regular php stuff isset() like below.
<?php
if(isset($_POST['insert'])) {
//perform insert
}
if(isset($_POST['search'])) {
// perform search
}
?>
u mean to ask u want to perform 4 action's.
just use an ajax call on onClick action of each button.
do not create a form, just make a function call.
You can create four forms on your HTML page as following
<form action="insert.php" method="post">
<!-- Some form data here -->
<input type="submit">
</form>
<form action="delete.php" method="post">
<!-- Some form data here -->
<input type="submit">
</form>
<form action="update.php" method="post">
<!-- Some form data here -->
<input type="submit">
</form>
<form action="search.php" method="post">
<!-- Some form data here -->
<input type="submit">
</form>
from your question I understand above scenario
Hope it helps
you can do tat using this code...
<input type="button" onclick="var e = document.getElementById('form_id'); e.action='adress1'; e.submit();" value="submit1">
<input type="button" onclick="var e = document.getElementById('form_id'); e.action='adress2'; e.submit();" value="submit2">
<input type="button" onclick="var e = document.getElementById('form_id'); e.action='adress3'; e.submit();" value="submit3">

IE8 has no $_POST data

I am currently working on a login page, using Dreamveaver CS4.
My form looks like this (I have kept the code complete):
<form id="login" name="login" method="POST" action="<?php echo $loginFormAction; ?>"
enctype="multipart/form-data">
<input type="hidden" name="loginnow" id="loginnow" value="go">
<table border="0" cellpadding="5" cellspacing="0">
<tr>
<td rowspan="4"><img src="images/icons/login_icon.jpg" width="240" height="218" alt="login-icon"></td>
<td>Benutzername</td>
<td><input name="usern" type="text" class="fieldSm" id="usern"></td>
</tr>
<tr>
<td>Passwort</td>
<td><input name="passwrd" type="password" class="fieldSm" id="passwrd"></td>
</tr>
<tr>
<td colspan="2" align="center"><input name="submit" type="submit" class="button" id="submit" value="Anmelden"></td>
</tr>
<tr>
<td colspan="2">Hier können Sie sich registrieren</td>
</tr>
</table>
</form>
Now the php script checks for the hidden field
<?php if (isset($_POST['loginnow'])) {
# do some DW magic ;)
}
?>
With Firefox it works nicely and I can login properly, however is fails with IE8.
So, I was checking with:
<pre>
<?php print_r($_POST); ?>
</pre>
This results in and empty array when using IE8. $_REQUEST only has only the PHPSESSID.
I have searched several sites, with no results or hints (mostly the issues are with graphical submit buttons).
If anyone could give a hint where my error is, I would be very grateful.
All of your pages are with the suffix php? are you using a mamp/wamp or real webserver with php?

$_SERVER['PATH_INFO'] ..Undefined index: PATH_INFO

I am using a code to be put as a header:
$fullurl=$_SERVER['PATH_INFO'];
echo '
<form action="'. $fullurl .'" method="POST">
<table width="1000" border="1" cellpadding="10" id="navigationBar">
<tr>
<td> Register</td>
<td> Control Panel</td>
<td> Donate </td>
<td align="right">name:<input name="name" type="text" /></td>
<td>password:<input name="pass" type="text" /> <input name="login" type="submit" value="Login" /> </td>
</tr>
</table>
</form>
';
I include the header across page files with the require once. What I want is that the fullurl variable to obtain the full url of the page it is "required_once" on, and when I click submit, I want it to redirect to the page the header is on.. I added the url onto the action of the form..
But what I get is this:
Undefined index: PATH_INFO
I tried to use those instead:
explode('/', substr(parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH),1));
$_ENV['PATH_INFO'];
But they didnt work too :(
<form action="" method="POST">
that's all
also, there is no point in echoing raw HTML
use this code instead of yours
?>
<form action="" method="POST">
<table width="1000" border="1" cellpadding="10" id="navigationBar">
<tr>
<td> Register</td>
<td> Control Panel</td>
<td> Donate </td>
<td align="right">name:<input name="name" type="text" /></td>
<td>password:<input name="pass" type="text" /> <input name="login" type="submit" value="Login" /> </td>
</tr>
</table>
</form>
You can also try:
<form action="<?=$_SERVER['PHP_SELF']?>" method="POST">
<input type="submit" name="form-submit" value="Submit" />
This will cause the form to submit on itself (current page). Use a variable in your form to detect submission or 'regular page load'. E.g.
if (isset($_POST['form-submit'])){
//do stuff
}
In a more recent environment, with Apache / PHP-FPM you need to enable the following option in php.ini to avoid "Undefined index: PATH_INFO"
cgi.fix_pathinfo=1

Troubles with html-forms

index.php:
<form action="update_db.php" method="post">
<?php
require_once 'modules/' . $currentModule . '.php';
?>
</form>
modules/some_module.php
...
<input type="submit" />
...
update_db.php:
#extract( $_POST );
print_r( $_POST );
After loading index.php i see need form. But during submitting i'm coming to the same page (index.php). Why?
http:/****/admin/
Here is html-code generated: http://dpaste.com/93396/
It's so strange, but form generates 2 times... I removed all part of code and rewrited it. Now everything is fine. Thanks all.
I took a look at your site. Your form action is index.php and that is why you keep seeing the same page after you click submit. If your code above is correct, ensure that you do not have <form> tags in your module containing the submit button.
<form action="index.php" method="post">
<table align="center">
<tr>
<td>Логин: </td>
<td><input type="textfield" name="login" /></td>
</tr>
<tr>
<td>Пароль: </td>
<td><input type="password" name="password" /></td>
</tr>
<tr>
<td></td>
<td align="right"><input type="submit" name="submit" value="вход" /></td>
</tr>
<table>
</form>
you have this:
<form action="index.php" method="post">
not this:
<form action="update_db.php" method="post">
Change it and your form will post to update_db.php

Categories