Get input text by php code - php

I need to get the text from an input in my code, and put it like a php variable in the same php file:
Input code part :
<input width="600px" type="text" name="search" id="search_box" class="search_box" placeholder="">
PHP Parameter part :
<form method="post" name="searchform" action="search/<?php echo (xyx) ?>">
How I get the input text in the (xyx) part of the code?
Complete code :
<div class="tipobusqueda" id="tipobusqueda">
<text style="color:#000">Filtrar por :</text>
<form method="post" name="searchform" action="search/<?php echo $value['Id_Cliente'] ?>">
<select id="tiposearch" name="tiposearch" style="width: 100px">
<option value="Nombre">Nombre</option>
<option value="Apellidos">Apellidos</option>
<option value="NIF">NIF</option>
<option value="Dirección">Dirección</option>
<option value="Teléfono">Teléfono</option>
<option value="Estado">Estado</option>
</select>
<input width="600px" type="text" name="search" id="search_box" class="search_box" placeholder="">
<input type="submit" value="Search" class="search_button"><!-- Filtrar texto -->
<br />
</form>
</div>
Thanks.

<html>
<head>
<script type='text/javascript' src="http://code.jquery.com/jquery-2.1.0.min.js"></script>
</head>
<body>
<div class="tipobusqueda" id="tipobusqueda">
<text style="color:#000">Filtrar por :</text>
<form method="post" name="searchform">
<select id="tiposearch" name="tiposearch" style="width: 100px">
<option value="Nombre">Nombre</option>
<option value="Apellidos">Apellidos</option>
<option value="NIF">NIF</option>
<option value="Dirección">Dirección</option>
<option value="Teléfono">Teléfono</option>
<option value="Estado">Estado</option>
</select>
<input width="600px" type="text" name="search" id="search_box" class="search_box" placeholder="">
<input type="button" value="Search" class="search_button">
<br />
</form>
</div>
</body>
</html>
<script>
$('.search_button').click(function(){
location.href='search/'+$('#search_box').val();
});
</script>

Related

Not able to print data from Html in Php file

<body>
<span>
<div class="heading">
<h3><img src="http://zicom.com/img/ilayashop-1482233381.jpg" alt="Zicom Logo" ></h3>
<h1><i>Zicom </i> SMS Application</h1><br>
</span>
</div>
<br>
<div>
<form method='post' action=''>
<label for="fname">Contact Number</label>
<input type="text" id="fname" name="number" placeholder="Contact Number....">
<label for="sms" id="msg">Message</label>
<select id="country" name="message">
<option value="" name="message">Blank</option>
<option value="hello" name="message">Abandoned Call</option>
<option value="" name="message">Audit Call </option>
</select>
<input type="text"id="msg" name="message" placeholder="Type your Message...." >
<input type="submit" value="Send" name="send">
</form>
</div>
<?php
if(isset($_POST)) {
$n = $_POST['number'];
$m = $_POST['message'];
echo "$n $m";
}
?>
</body>
</html>
I have used the same method many times and i have succesfully sent the data to php file, but im unable to do the same. I try to print the content of form, but is not executing.

Code format for conversion from page to same page but with new variable

I have this form:
<form action="<?php echo $php_self;?>" method="get">
<input type="submit" value="go" id="text33" />
<select name="match" id="text33" style="width:100px;">
<option value="1">1</option>
<option value="2">1</option>
</select>:select
</form>
This form is in the title page cup?c=2&match
I want to program the form so that if you press go .. go to the title page
cup?c= 2&match=1
As a function
$ cup=$_GET['c'];
$ match=$_GET['match'];
Just remove action param from tag form:
<form method="get">
<input type="submit" value="go" id="text33" />
<select name="match" id="text33" style="width:100px;">
<option value="1">1</option>
<option value="2">1</option>
</select>
</form>
Or replace your variable
$php_self
To
$_SERVER["PHP_SELF"]
i solve the problem
<form action="cup.php" method="get"><input type="hidden" value="<?php echo "2"; ?>" name="c" /><input type="submit" value="go" id="text33" /> <select name="match" id="text33" style="width:100px;"><option value="1">1</option><option value="2">2</option></select>:select</form>
thank you very much

select tag name not working while using it in php

I have a form in html and I am saving it as search.php:
<form name="myform" action="" method="POST" onsubmit="search_clicked(); return false;">
Keyword<input type="text" name="Keyword" id="Keyword" value="XYZ" required/><!-- value is the default name that appears in the text box-->
<br>
Type
<select name="sel" id="sel" class="form-control" onchange="checkcolors(this.value)">
<option selected value="Users">Users</option>
<option value="Pages">Pages</option>
<option value="Events">Events</option>
<option value="Places">Places</option>
<option value="Groups">Groups</option>
</select>
</form>
<div id="loc_dist_displayarea" style="display:none;">
Location<input type="text" name="Location" value="90007" required/> Distance(meters)<input type="text" name="distance" value="10000" required/>
</div>
<br><br>
<input type="submit" name="Search"/>
<input type="submit" value="clear" id="clear" onclick="return clearclicked()"/>
</form>
and my php script is in the same file:
<div id="body_area" style="display:none">
<?php
echo "hi I am searching ";
if($_SERVER["REQUEST_METHOD"]=="POST")
{
//echo "yes value is selected";
//echo $_POST["Keyword"];
if (isset($_POST['sel'])) {
$selectedval= $_POST["sel"];
echo "$selectedval";
}
//echo $_POST["Location"];
}
echo "no value is selected";
?>
</div>
I am not able to display the $_POST['sel'] while $_POST['Keyword'] is echoed.Please help.
First of all, you arent using good programming practices, you use quotation marks (these " and these ') Indiscriminately. You should only alternate between them when you have them nested.
Next, on the action paramenter you should put the name of the file, even if it's the same.

Code works fine on it's own, but not when included in my form

I have 2 files: add.php (a form to add a recipe into a database, and numbers.php (a list for displaying ingredient options).
Both scripts/pages work separately...but when I include ('numbers.php') the onchange code does not work.
//numbers.php
<form name="numbers" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<select name="select" onchange="javascript: document.numbers.submit();">
<option value=0>-</option>
<option value=1>1</option>
<option value=2>2</option>
<option value=3>3</option>
<option value=4>4</option>
</select>
</form>
<?php
$num_ingredients = $_REQUEST["select"];
$count = 0;
while ($count < $num_ingredients) {
$count++;
include ('../ingredients/list.php');
echo '<br />';
}
?>
//add.php
<form enctype="multipart/form-data" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST">
Recipe Title:
<input type="text" name="recipe_name" maxlength="30" value="<?php echo $recipe_name; ?>" /><br />
Ingredients:
<?php include ('numbers.php'); ?><br />
<input type="submit" value="Add Recipe" />
<input type="button" onclick="history.go(0)" value="Clear" /><br />
</form>
Any help is greatly appreciated, as always :)
------- EDIT --------------------------------------
Here is the page source from add.php as requested
<!DOCTYPE html>
<html lang="en-US">
<head>
<meta http-equiv="Content Type" content="text/html; charset=UTF-8" />
<title>POWERCHEF</title>
<meta name="robots" content="noindex, nofollow">
<meta name="distribution" content="iu">
<meta name="format-detection" content="telephone=yes">
<meta name="copyright" content="Copyright 2012">
</head>
<body>
<!-- ON WITH THE SHOW --><h3>ADD RECIPE</h3><html>
<form enctype="multipart/form-data" action="/kitchen/recipes/add.php" method="POST">
Recipe Title:
<input type="text" name="recipe_name" maxlength="30"
value="" /><br />
Subtitle:
<input type="text" name="recipe_subtitle" maxlength="50"
value="" /><br />
Category:
<input type="text" name="recipe_category" maxlength="50"
value="" /><br />
Subcategory:
<input type="text" name="recipe_subcategory" maxlength="50"
value="" /><br />
<br />
Photo:<br />
<input type="hidden" name="MAX_FILE_SIZE" value="200000" />
<input type="file" name="recipe_photo" value="" /><br />
<br />
Ingredients:<br />
<form name="numbers" method="post"
action="/kitchen/recipes/add.php">
<select name="select" onchange="javascript: document.numbers.submit();">
<option value=0>-</option>
<option value=1>1</option>
<option value=2>2</option>
<option value=3>3</option>
<option value=4>4</option>
<option value=5>5</option>
<option value=6>6</option>
<option value=7>7</option>
<option value=8>8</option>
<option value=9>9</option>
<option value=10>10</option>
<option value=11>11</option>
<option value=12>12</option>
<option value=13>13</option>
<option value=14>14</option>
<option value=15>15</option>
<option value=16>16</option>
<option value=17>17</option>
<option value=18>18</option>
<option value=19>19</option>
<option value=20>20</option>
<option value=21>21</option>
<option value=22>22</option>
<option value=23>23</option>
<option value=24>24</option>
<option value=25>25</option>
<option value=26>26</option>
<option value=27>27</option>
<option value=28>28</option>
<option value=29>29</option>
<option value=30>30</option>
</select>
</form>
<br />
<br />
Prep Instructions:<br />
<textarea name="recipe_prep_instructions" class="" cols="88" rows="15"
value="" /></textarea><br />
<br />
Cooking Instructions:<br />
<textarea name="recipe_prep_instructions" class="" cols="88" rows="15"
value="" /></textarea><br />
<br />
<input type="submit" value="Add Recipe" />
<input type="button" onclick="history.go(0)" value="Clear" /><br />
<br />
</form>
</html>
<footer>
<p>
<small><strong>© 2012 </strong> - All Rights Reserved</small>
</p>
</footer>
<!-- THANKS FOR STOPPING BY! -->
</body>
</html>
You have a typo:
<input type="text" name="recipe_name" maxlength="30" value="<?php echo $recipe_name"; ?>" /><br />
Should be: (notice the removal of the quote in the php block)
<input type="text" name="recipe_name" maxlength="30" value="<?php echo $recipe_name; ?>" /><br />
The quote could possibly be messing up the other script.
EDIT:
Ok, was this also just a copy paste typo?
<form name="numbers" method="post action="<?php echo $_SERVER['PHP_SELF']; ?>">
Should be:
<form name="numbers" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
EDIT2:
Ok, the problem is that the form "numbers" is inside the other form, so it's having trouble accesing it with document.numbers. To fix it you are going to need to access it a different way, such as giving it an id and using getElementById.
the form on add.php did not have a name

How to make multiple-form with single submit button and action with php

Rather inputing one by one for a class/lessen for a day, I'd like to input 10 forms at once.
The HTML is something like this.
All the form do the same thing, add start_time, finish_time and instructor in a database.
However I am not sure how to do this. And I am not sure if this HTML is correct or not.
Any inputs will be appreciated.
Thanks in advance.
HTML
<?php
$date = "2010-10-08";
?>
<form name="form1" method="post" action="inputform.php">
<!-- form 1 -->
<label for='start_time'>1. Start Time</label>
<input type="text" name="start_time" />
<label for='finish_time'>Finish Time</label>
<input type="text" name="finish_time" />
<label for='instructor'>Instructor</label>
<select name="instructor">
<option value="john">John</option>
<option value="mary">Mary</option>
<option value="jim">Jim</option>
</select>
<input type="hidden" name="date" value="<?php echo $date; ?>"/>
<div style="clear: both;"> </div>
<!-- form 2 -->
<label for='start_time'>2. Start Time</label>
<input type="text" name="start_time" />
<label for='finish_time'>Finish Time</label>
<input type="text" name="finish_time" />
<label for='instructor'>Instructor</label>
<select name="instructor">
<option value="john">John</option>
<option value="mary">Mary</option>
<option value="jim">Jim</option>
</select>
<input type="hidden" name="date" value="<?php echo $date; ?>"/>
<div style="clear: both;"> </div>
<!-- form 3 -->
<label for='start_time'>3. Start Time</label>
<input type="text" name="start_time" />
<label for='finish_time'>Finish Time</label>
<input type="text" name="finish_time" />
<label for='instructor'>Instructor</label>
<select name="instructor">
<option value="john">John</option>
<option value="mary">Mary</option>
<option value="jim">Jim</option>
</select>
<input type="hidden" name="date" value="<?php echo $date; ?>"/>
<div style="clear: both;"> </div>
<!-- form 4,5,6,7,8,9,10 -->
<input type="submit" name="submit" value="Submit" />
</form>
you cannot submit multiple forms at once.
only one form with the form specific method/action.
however what probably need are arrays.
you can do something like
<form ...>
<select name="instructor[]">
...
</select>
<select name="instructor[]">
...
</select>
then you will get an array posted which you can loop through.
just look at the structure by printing out $_POST like print_r($_POST); then you'll see

Categories