Action Form not work - php

<form action="/en2/maps-<?php echo $id; ?>/?=. ($_GET['textSearchTerms']).&=. ($_GET['locationSearchTerms'])."><!--Relative url to the page that your map is on-->
Distination:
<select name="textSearchTerms" class="selectpicker" data-live-search="true">
<option value="alfamart">Alfamart</option>
<option value="BCA">BCA</option>
</select>
Location:
<input type="text" name="locationSearchTerms">
<input type="submit" value="Search">
</form>
<form action="/en2/maps-<?php echo $id; ?> not work...
any idea?
I want this link for my form action:
http://indonesia.com/en2/maps-alfamart/?textSearchTerms=alfamart&locationSearchTerms=denpasar
thanks

Use like this
<?php
$id="alfamart";
$textSearchTerms = isset($_GET['textSearchTerms']) ? $_GET['textSearchTerms'] : "";
$locationSearchTerms = isset($_GET['locationSearchTerms']) ? $_GET['locationSearchTerms'] : "";
$url = "/en2/maps-".$id."/?textSearchTerms=".$textSearchTerms."&locationSearchTerms=".$locationSearchTerms;
?>
<form action="<?php echo $url; ?>" method="GET">
Distination:
<select name="textSearchTerms" class="selectpicker" data-live-search="true">
<option value="alfamart">Alfamart</option>
<option value="BCA">BCA</option>
</select>
Location:
<input type="text" name="locationSearchTerms">
<input type="submit" value="Search">
</form>
Added form method GET and your php variable in php tag

Replace
<form action="/en2/maps-<?php echo $id; ?>/?=. ($_GET['textSearchTerms']).&=. ($_GET['locationSearchTerms']).">
with
<form action="/en2/maps-<?php echo $id; ?>/?textSearchTerms=<?php echo $_GET['textSearchTerms']; ?>&locationSearchTerms=<?php echo $_GET['locationSearchTerms']; ?>">
Note:- You missed textSearchTerms and locationSearchTerms in your form action parameter before =.

Related

How to maintain the PHP GET value on the address bar if I use another GET?

I am passing a variable from page1 to page2 using GET and it's already working. However, I also use another get in the <select> <option> on page2 which means when I click an item in the option, the value I get from page1 disappears and becomes undefined since the address bar changes. I want the variable I get from page1 to be compared on SQL where clause. I can't think of a way on how to solve this, I'm not really knowledgeable in PHP, can you help me?
Here is my code(I remove some unnecessary lines): page1
<form method="get" action="home.php">
<div class="form-group">
<input id="codehe" class="form-control" type="codehe" name="codehe" placeholder="Class Code">
</div>
<div class="form-group">
<input class="form-control button" type="submit">
</div>
</form>
page2 (this is how i get the value from page1)
<?php
$codehe = $_POST['codehe'];
echo $codehe;
?>
The other GET (form) on page2
<form method="GET">
<select id="state" multiple name="state" onchange='if(this.value != 0) { this.form.submit(); }'>
<option value="ALL">ALL</option>
<option value="<?php echo $row['subjects'];?>"><?php echo $row['subjects'];?></option>
</select>
</form>
<?php
if(isset($_GET['state'])) {
$str = $_GET["state"];
$sql = "SELECT * FROM classvideo WHERE subjects = '$str' AND linkcode = ''";
?>
The traditional way to do things like this (without client-side code) is to put a hidden input in your form on page 2:
<form method="GET">
<select id="state" multiple name="state" onchange='if(this.value != 0) { this.form.submit(); }'>
<option value="ALL">ALL</option>
<option value="<?php echo $row['subjects'];?>"><?php echo $row['subjects'];?></option>
</select>
<!-- Add this line -->
<input type="hidden" name="codehe" value="<?php echo $_GET['codehe'] %>">
</form>

How to send query with select tag through url

I want send the data I received from the select tag through the url as queries so I can use it and query the database.
I have tried but the values are not showing. I am getting something like: type=&action=
This is my code
<select name="types">
<option value="2 bed room">2 bed room</option>
</select>
<select name="action">
<option value="rent">rent</option>
</select>
$type = $_POST['types'];
$action = $_POST['action'];
$query = "type={$type}&action={$action}";
<a class="site-btn fs-submit" href="search.php?<?php echo $query; ?>"> Advanced search</a>
I expected :
type=2 bed room&action=rent
Try the following code. Here, When you submit the form the whole form data will be passed to search.php and the form method is POST so you can access those data by simply calling $_POST['attribute value of name'].
HTML form:
<form class="filter-form" method="post" action="search.php" enctype="multipart/form-data">
<input type="text "class="d-block d-md-inline" placeholder="Enter State, City or Area" name="city">
<select name="types">
<option value="2 bed room">2 bed room</option>
</select>
<select name="action">
<option value="rent">rent</option>
</select>
<input type="submit" value="Advanced search">
</form>
create a PHP file (search.php):
<?php
//Do what you want here
if (isset($_POST['city'])) {
$city = $_POST['city'];
echo $city;
}
if (isset($_POST['types'])) {
$type = $_POST['types'];
echo $type;
}
if (isset($_POST['action'])) {
$action = $_POST['action'];
echo $action;
}
?>
Replace the link with a button. Attach the query params in the link to the action of the form. Your code should look like below.
<form action="search.php?<?php echo $query; ?>">
<select name="types">
<option value="2 bed room">2 bed room</option>
</select>
<select name="action">
<option value="rent">rent</option>
</select>
<?php
$type = $_POST['types'];
$action = $_POST['action'];
$query = "type={$type}&action={$action}";
?>
<button class="site-btn fs-submit" type="submit">Submit</button>
</form>

How can I get the values from the PHP generated forms?

I dont know where or how to use $_POST to get the values of the forms.
This is the whole code, I uploaded it on GitHub if you want to see the whole thing
This is the file I am trying to get the values out of.
new.php
<?php
if (!empty($_POST) and isset($_POST['actiune']))
{
$actiune = isset($_POST['actiune']) ? $_POST['actiune'] : NULL;
switch($actiune){
//CASE 1
case 'addElev': echo '<div class=dbFormText>Adauga elev</div><div
class="databaseform"><form action="" method="post">
<input type="text" name="numeElev" placeholder="Nume elev"/>
<input type="text" name="orasElev" placeholder="Localitate"/>
<select name="sexElev">
<option value="Baiat">Baiat</option>
<option value="Fata">Fata</option></select>
<input type="text" name="tlfElev" placeholder="Nr. de telefon"/>
<input type="text" name="birthdayElev" placeholder="Nastere(DD-MM-YYYY)"/>
<input type="submit" value="Submit">
</form></div>';
break;
}
}
?>
This is the page of the first dropdown, which gives me the value of the switch
adminpanel.html
<div class="dropdowns">
<form action="" method="post">
<select name="actiune" onchange="this.form.submit()">
<option>Selecteaza actiunea</option>
<option value="addElev">Adauga elev</option>
<option value="addNota">Adauga nota</option>
<option value="addAbsenta">Adauga absenta</option>
<option value="addTeza">Adauga teza</option>
<option value="deleteElev">Sterge elev</option>
<option value="deleteNota">Sterge nota</option>
<option value="deleteAbsenta">Sterge absenta</option>
<option value="deleteTeza">Sterge teza</option>
<option value="modifyElev">Modifica elev</option>
<option value="modifyTeza">Modifica teza</option>
<option value="modifyPurtare">Modifica nota purtare</option>
</select>
<?php include('new.php') ?>
</div>
When you submit a form that has a method of post, e.g.
<form method="post">
(note: action="" is redundant and can be left out)
the target page (in this case, itself) will be provided with the $_POST array.
You can dump the entire array to look at the values by using:
if (!empty($_POST) and isset($_POST['actiune']))
{
var_dump($_POST);
}
This array should contain all the values from within the <form> tag, provided a name has been set (which will be used as the 'key' in the array).
Not sure what is the switch for, added the fetch of postvars at the top of code. I am sure you can do some php to make sure vars are set. Also actiune is not a postvar that is its not the name of anyof the input fields so dont do $_POST['actiune']. it wont work. Else you have to add a hidden field, I did it here for you.
<?php
if (!empty($_POST) {
$numeElev = $_POST['numeElev'];
$orasElev = $_POST['orasElev'];
$sexElev = $_POST['sexElev'];
}
if (!empty($_POST) and isset($_POST['actiune']))
{
$actiune = isset($_POST['actiune']) ? $_POST['actiune'] : NULL;
switch($actiune){
//CASE 1
case 'addElev': echo '<div class=dbFormText>Adauga elev</div><div
class="databaseform"><form action="" method="post">
<input type="text" name="numeElev" placeholder="Nume elev"/>
<input type="text" name="orasElev" placeholder="Localitate"/>
<input type="hidden" name="actiune" placeholder="1"/>
<select name="sexElev">
<option value="Baiat">Baiat</option>
<option value="Fata">Fata</option></select>
<input type="text" name="tlfElev" placeholder="Nr. de telefon"/>
<input type="text" name="birthdayElev" placeholder="Nastere(DD-MM-YYYY)"/>
<input type="submit" value="Submit">
</form></div>';
break;
}
}
?>

make an option from select tag stays the same after reload or change the page, PHP

So im having problems on figuring out how to make option tag so when is pressed it will make the action on all the pages
This is what i have done:
index1.php
include 'select.php'
<title>Ultra 2014 <?php if (isset($title)) {echo $title;} else{echo "Miami";}?> Area</title>
index2.php
include 'select.php'
<title>Ultra 2014 <?php if (isset($title)) {echo $title;} else{echo "Miami";}?> Area</title>
select.php
<div id="regContainer">
<form id="regionSelect" action="<?php $_SERVER['PHP_SELF'] ?>" method="post" onchange="this.form.submit();" >
<select id="selectedRegion" name="selectedRegion" size="1" autocomplete="off">
<option value="miami">miami</option>
<option value="new york">ny</option>
</select>
<input type="submit" value="Enter Region" />
</form>
</div>
process.php
<?php if(!isset($_SESSION)){ session_start();}
if(isset($_POST['selectedRegion'])){
$region = $_POST['selectedRegion'];
if($region == "miami"){
echo "miami selected";
$title = "miami";
}
if($region == "new york"){
echo "new york selected";
$title = "new york";
}
}
?>
when I press the first option, it changes the title normally on the index1.php, but when i go to the index2.php... it does not change the title of that page, I have to press the first option button again to make the change.
Is there anyway to just press the first option from the selection and then change the title of all the pages without having to press the button again?
Any suggestion will help. Thanks
Using the code you currently have you could do the following
<form id="regionSelect" action="<?php $_SERVER['PHP_SELF'] ?>" method="post" onchange="this.form.submit();" >
<select id="selectedRegion" name="selectedRegion" size="1" autocomplete="off">
<option <?php if($_REQUEST['selectedRegion'] == 'miami') echo "selected"; ?> value="miami">miami</option>
<option <?php if($_REQUEST['selectedRegion'] == 'newyork') echo "selected"; ?> value="newyork">ny</option>
</select>
<input type="submit" value="Enter Region" />
</form>
This will ensure the option is selected on page refresh. If you want something that also acts on page change then you will need to use a cookie
if(isset($_REQUEST['selectedRegion'])){
setcookie("region", $_REQUEST['selectedRegion'], time()+3600);
}
<form id="regionSelect" action="<?php $_SERVER['PHP_SELF'] ?>" method="post" onchange="this.form.submit();" >
<select id="selectedRegion" name="selectedRegion" size="1" autocomplete="off">
<option <?php if($_COOKIE["region"] == 'miami') echo "selected"; ?> value="miami">miami</option>
<option <?php if($_COOKIE["region"] == 'newyork') echo "selected"; ?> value="newyork">ny</option>
</select>
<input type="submit" value="Enter Region" />
</form>
You need to change
if(!isset($_SESSION)){ session_start();}
To just
session_start();
What you're saying currently is if you have a session set, don't load the session library to then use that session data.

making site id increment by 1

Hey guys im trying to make a quiz and currently I have ran into an issue, I have made it increment but not send the data, so I need to fix it but don't really know how to, I need the users to be able to select an option the data get sent to the next page but the page must also increase in increment.
this is what I have got
<form name="form2" method="post" >
<select name="answer">
<option value=$myrow['A']><?php echo $myrow['A']?></option>
<option value=$myrow['B']><?php echo $myrow['B']?></option>
<option value=$myrow['C']><?php echo $myrow['C']?></option>
<option value=$myrow['D']><?php echo $myrow['D']?></option>
<input type="submit" name="submit" value="Continue" onclick = "window.location.href = 'testttts.php?id=<?php echo $count?>'"
any help would be great thank you!!
Is this what you mean?
<?php
if(isset($_POST['i'])) {
$i = $_POST['i'];
} else {
$i = 0;
}
echo "increment: " . $i;
$i++;
?>
<form name="form2" method="post" >
<select name="answer">
<option value=$myrow['A']><?php echo $myrow['A']?></option>
<option value=$myrow['B']><?php echo $myrow['B']?></option>
<option value=$myrow['C']><?php echo $myrow['C']?></option>
<option value=$myrow['D']><?php echo $myrow['D']?></option>
</select>
<input type="hidden" name="i" value="<?php echo $i; ?>" />
<input type="submit" name="submit" value="Continue" />

Categories