I am having a ton of trouble with parsing A custom form that I created in wordpress, I am on a page called front-page.php where my form is located and the parser is on a page called formhandler.php, I have my parser running from a seperate page.
I am really confused because the form itself is recognizing the parser on the other page, just not actually parsing the data and taking you to the correct page. I get a long unknown URL that takes me to a 404 page within the site itself.
I need help figuring out why this forms code is not working or if the parser is just not in the right location to actually do the parsing work. I am fairly new to wordpress so anything helps right now. I have to get this done right now for my client, any help would be awesome. I just haven't had to use a custom form within WordPress before.
URL:
http://50.22.79.62/~pftech/formhandler.php?selection=http%3A%2F%2F50.22.79.62%2F~pftech%2Fwater-delivery-service%2F&zip=92115&home=on&did_submit=Get+Started%21
FORM PARSER:
<?php
if(isset($_GET['zip'])){
$sandiego = array('91911', '91914', '91915', '91932', '91942', '91945', '91950', '92014', '92025', '92027', '92029', '92037', '92064', '92065', '92067', '92071', '92075', '92101', '92102', '92103', '92104', '92105', '92106', '92107', '92108', '92109', '92110', '92111', '92113', '92114', '92115', '92116', '92117', '92118', '92119', '92120', '92121', '92122', '92123', '92124', '92126', '92127', '92128', '92129', '92130', '92131', '92132', '92134', '92135', '92139', '92140', '92145', '92147', '92154', '92173');
if (in_array($_GET['zip'], $sandiego)){
header("Location: ".urldecode($_GET['selection'])."?zip=".$_GET['zip']."&type=".$_GET['type']);
} else {
header("Location: http://www.pureflo.com/");
}
exit;
}
?>
FORM:
<form method='get' id='gform_1' action='front-page.php'>
<div class="serviceinput">
<label for="services">Services: </label>
<select id="selection" name="selection">
<option value=''>Select a Service</option>
<option value='http://50.22.79.62/~pftech/water-delivery-service/'>Water Delivery</option>
<option value='http://50.22.79.62/~pftech/coffee-delivery/'>Coffee Services</option>
<option value='http://50.22.79.62/~pftech/water-filtration-systems/'>Water Filtration</option>
</select>
</div>
<div class="zipcode">
<label for="zip">Zip Code: </label>
<input name="zip" type="text" maxlength="5" id="zip" />
</div>
<div class="frontradio">
<input name="type" type="radio" id="homeradio" value="home" />
<div class="homelabel"> <label for="homeradio">Home</label></div>
<input name="type" type="radio" id="officeradio" value="office" />
<label for="officeradio">Office</label>
</div>
<div class="homebutton">
<input type='submit' id="submithome" name="did_submit" value="Get Started!">
</div>
</form>
it seems that in the action, you have front-page.php which is the name of the form file. is this what you want to have? 404 means that the page is not found.
I believe you should try action='formhandler.php'. After is found, you can check your parser.
Related
Being a total newbie in PHP, i have issues with implementing the Google reCaptcha on my website.
I oriented myself towards an easier solution which would be: if this field is empty, SEND the form.
Here is my code:
<form method="POST" action="/#contact">
<!-- Name + mail -->
<input type="text" required placeholder="Name" name="name" />
<input type="email" required placeholder="Email" name="email" id="email" value=""/>
<select name="subject" id="category">
<option value="">Subject</option>
<option value="1">1</option>
<option value="1">2</option>
<option value="1">3</option>
<option value="1">4</option>
</select>
<input id="submit" name="submit" type="submit" value="Send"/>
<input type="reset" value="Clear" class="alt" />
<div>
<label>If you're human, leave this field epmty</label>
<input type="text" name="comment">
<?php
if(empty($_POST['comment'])) {
// the field is empty
}
?>
</div>
</form>
My problem is: the form is still being sent, even there is something in the field.
Thanks in advance for your help.
There are 2 solutions to this:
Call a php file that validates the inputs. When a user hits the send button, it goes to a php page. This page retrieves the values of the filled in form and validates it. If an invalid input is found, you can call the main page (ex. index.php) with an error parameter in the url (ex. index.php?error=botfound). And in the beginning of your index.php file, you can write a check if there is an error parameter and display the error message if you want.
Let javascript validate the values of the inputs before the values are sent to a php file. To do this, you change your code from <form method="POST" action="/#contact">
to:
<form method="POST" action="/#contact" onsubmit="DoSubmit();">
With a javascript function something like:
<script>
function DoSubmit(){
if(document.getElementById('idOfInput').value != ""){
alert("Wrong input"); //Or you can actually add an error message to your page.
return false;
}
return true;
}
</script>
I think that script will make sure if the value of the input with id 'ifOfInput' is not empty, it'll give an alert and will not call the php script.
(By the way, you can also make that input invisible so it doesn't annoy normal users but bots will still fill in the input.)
Hope this helped :)
I feel like an absolute moron posting this question, but I'm completely serious, I officially have NO idea why this form isn't posting. I've gone from using AJAX to display information inputted to simple submit-redirect-grab Post data in PHP to $_SERVER["PHP_SELF"] trying to get the information to JUST POST, and it won't. Most of the people asking this question have had their answers revealed as "You need a name field" or "Your javascript is the issue" but I have a name field and I am no longer using javascript. I am utterly and completely confused.
For reference, I'm using PHPStorm and a Local server to test this out. I just logged on fresh today, saved the project, ran it for the first times today, made sure it wasn't just a sort of cached project, and it doesn't appear to have anything with old data.
Please don't mind if some of the form syntax is messy, I just want this darn post to work so I can move on to the meat of what I'm trying to make. Also there is no stylesheet currently, it's mostly empty apart from
.id {
height: 100px;
}
Also none of the form fields are required, you really only need to enter information into one. I've got it doing a var_dump just so I can see all of the form post data, and it's brilliantly not working. I did have it echoing out something in PHP along the lines of "Done!" to show php is being read, and I also had it attempting to echo $_POST["modelnumber"] just to see that. Nope.
index.php
<!DOCTYPE html>
<html>
<link rel="stylesheet" type="text/css" href="index.css">
<body>
<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
Model Number:<br>
<input type="text" id="mod" name="modelnumber"><br><br>
Amazon Item?<br>
<input type="radio" id="amazonItemY" name="amazonItem" value="yes"> Yes<br>
<input type="radio" id="amazonItemN" name="amazonItem" value="no" checked> No<br><br>
Item name:<br>
<input type="text" id="intName" name="itemName"><br><br>
Item Description:<br>
<input type="text" id="internetDescription" name="description"><br><br>
Brand:<br>
<input type="text" id="brand" name="itemBrand"><br><br>
Manufacturer:<br>
<input type="text" id="manufacturer" name="manName"><br><br>
Website category:<br>
<input type="text" id="cmcategory" name="category"><br><br>
Clearance?<br>
<input type="radio" id="clearanceY" name="clearance" value="yes"> Yes<br>
<input type="radio" id="clearanceN" name="clearance" value="no" checked> No<br><br>
Competitor Price: (leave empty if not clearance)<br>
<input type="text" id="competitorPrice" name="compPrice"><br><br>
School price:<br>
<input type="text" id="catStdPrice" name="schoolPrice"><br><br>
Dealer price:<br>
<input type="text" id="dealerStdPrice" name="dealerPrice"><br><br>
Website price(normal):<br>
<input type="text" id="intCsiPrice" name="webPrice"><br><br>
Unit of Measure:<br>
<input type="text" id="unitOfMeasure" name="uom"><br><br>
UPC:<br>
<input type="text" id="upc" name="upcNum"><br><br>
Manufacturer Part Number:<br>
<input type="text" id="mfgr_num" name="manfacNum"><br><br>
Item Attribute:<br> <!--needs to be a dropdown-->
<select id="attribute" name="attributes">
<option value="(1593325)Baseball">Baseball</option>
<option value="(1593326)Basketball">Basketball</option>
<option value="(1593386)Boating + Paddling">Boating + Paddling</option>
<option value="(1593314)Camping Hiking + Climbing">Camping_ Hiking + Climbing</option>
<option value="(1610848)Cricket">Cricket</option>
<option value="(1593313)Cycling">Cycling</option>
<option value="(1593315)Equestrian">Equestrian</option>
<option value="(1593318)Fishing">Fishing</option>
<option value="(1593323)Football">Football</option>
<option value="(1594100)General Sports Equipment + Accessories">General Sports Equipment + Accessories</option>
<option value="(1593320)Golf">Golf</option>
<option value="(1593319)Hunting + Archery">Hunting + Archery</option>
<option value="(1593329)Ice + Roller Hockey">Ice + Roller Hockey</option>
<option value="(1593327)Other Sports">Other Sports</option>
<option value="(1593331)Personal Fitness">Personal Fitness</option>
<option value="(1599122)Pool + Billiards">Pool + Billiards</option>
<option value="(1593321)Rugby">Rugby</option>
<option value="(1593317)Skateboarding + Rollerskating">Skateboarding + Rollerskating</option>
<option value="(1593330)Ski + Snow">Ski + Snow</option>
<option value="(1593322)Soccer">Soccer</option>
<option value="(1593324)Softball">Softball</option>
<option value="(1593316)Tennis">Tennis</option>
<option value="(1593328)Water Sports">Water Sports</option>
</select><br/>
<input type="submit">
</form>
<?php
var_dump($_POST);
?>
RedRazor's answer is not a solution. The PHP interpreter resets the quotes inside of the php tags. This means that you can re-use the same quotes in the interpretation snippet.
This seems more like a PHP Storm issue, try to restart your PHP Storm server. I copied your code exactly to my machine and used PHP Storm built in server. With no modifications your code worked. I've attached some images of my setup.
Also you have to be running the PHP server to get $_POST requests, there is an icon to just open in the browser, which will work for many cases, but it will not work on requests like this due to their nature.
Here are some images of my setup:
Please make sure that there is no conflict between quotation marks ("")
Instead of
<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
Try
<form method="post" action="<?php echo htmlspecialchars($_SERVER['PHP_SELF']);?>">
firstly any help is much appreciated. In very new to php but love wordpress!
I have searched the web everywhere for a simple solution to my issue but struggled to find a working answer.
In short, i have a form on homepage that allows entry of arrival date, departure date and number of guests. i need the form to post these parameters to an booking system provided by a third party BUT hosted on my website via an iframe - but another page, not the homepage where the form is - MUST EMPHASIZE THAT).
Anyway, i'm almost there! but I am struggling to work out the PHP to display a string of php request functions.
Firstly, my current implementation is showing this code on the page source code (NOTE: iframe delibrately spelt wrong to embed here)
<iBrame name="testframe" src="https://externalurl?siteId=KAYSCLAY&request_locale=en&chainAction=newAvailabilitySearch&29/11/201330/11/201312"></ibrame>
The url aspect of the iframe needs to be as follows:
https://externalurl?siteId=KAYSCLAY&request_locale=en&chainAction=newAvailabilitySearch&arrival=09%2F07%2F2013&departure=10%2F07%2F2013&numberOfPersons=1&numberOfChildren=0
So I have two problems. I am only showing two dates combined together in my iframe src string, these need to be seperated, and I am also missing two paramters for some uknown reason - number of people parameters.
Below is my code hardcoded on the iframe php page (html/php) and also my form. Any thoughts, help is much appreciated.
<ibrame name="testframe" src="https://externalurl?siteId=KAYSCLAY&request_locale=en&chainAction=newAvailabilitySearch<?php echo ''.$_REQUEST['arrival'].$_REQUEST['departure'].$_REQUEST['numberOfPersons'].$_REQUEST['numberOfChildren']?>"></ibrame>
`
<div class="FormField Arrival">
<label for="arrival">Arrival Date</label> <input id="arrival" name="arrival" type="text" /></div>
<div class="FormField Departure">
<label for="departure">Departure Date</label> <input id="departure" name="departure" type="text" /></div>
<div class="FormField NumberOfPersons">
<label for="numberOfPersons">Adults</label> <select id="numberOfPersons" name="numberOfPersons"><option value="0">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></select></div>
<div class="FormField NumberOfChildren">
<label for="numberOfChildren">Children</label> <select id="numberOfChildren" name="numberOfChildren"><option value="0">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></select></div>
<div class="FormField Submit">
<input type="submit" value="Book now" /></div>
</form>
<script language="JavaScript">
function validate(theform) {
if (theform.domain.value == "") { alert("No domain entered"); return false; }
return true;
}
</script>`
Try this:
<?php
$adnn = array('arrival', 'departure', 'numberOfPersons', 'numberOfChildred');
foreach($adnn as $v){
$r[] = "&$v=".rawurlencode($_GET[$v]);
}
echo "<iframe name='testframe' src='https://externalurl?siteId=KAYSCLAY&request_locale=en&chainAction=newAvailabilitySearch$r[0]$r[1]$r[2]$r[3]'></iframe>";
?>
In my Codeigniter website I've made a searchform. When I search the page is redirected to a 'searchresults' page.
I always get a lot results and I want to minimize that. I would like to add searchfilters to the 'searchresults' page, so I can search on specific categories/keywords.
I've been searching for this the whole day.
What I've tried is adding a dropdown and a input field to the searchresults page. The dropdown is populated with the categories found with the normal searchform. This works, but I can't filter and limit the searchresutls when I submit the 'second searchform'.
My form on the 'searchresults' page looks like this:
<script type="text/javascript">
$(document).ready(function(){
$(".zoekfilters").hide();
$(".filters").show();
$('.filters').click(function(){
$(".zoekfilters").slideToggle();
});
});
</script>
<div class="zoekfilters">
<br/>
<form action="home/get_filtered_vac" method="post">
<p class="field">
<label class="field">Categorie:</label>
<select name="catselect" id="selection" value="Categorie">
<option selected disabled value="">Selecteer een categorie</option>
<?php foreach($all as $dat ){ ?>
<option value="<?php echo $dat['categorie']; ?>"><?php echo $dat['categorie']; ?></option>
<?php } ?>
</select>
</p>
<br/>
<p class="field">
<label class="field">Tags:</label>
<input name="tag" type="search" placeholder="Tags">
</p>
<br/>
<p class="field">
<label class="field">Aantal uren:</label>
<?php foreach($all as $dat){ ?>
<?php echo $dat['uren']; nbs(2); ?>
<input type="checkbox" value="<?php echo $dat['uren']; ?>">
<?php } ?>
</p>
<br/>
<p class="field">
<input type="submit" value="Filter resultaten">
</p>
</form>
You can try it yourself, so the idea is clear:
Go to: http://kees.een-site-bouwen.nl/vacatures
leave the big searchbox empty and add '9101' to the small searchbox, Now wait a second an then submit the form. You will be redirected to http://kees.een-site-bouwen.nl/vacatureresults
Click on 'Zoekfilters' to open the second searchfrom on the 'searchresults' page.
If people need my model functions I will post them.
I'm trying to set up an html form that allows the user to select a field from a drop-down menu, then specify the information for that field. For example, if they select "Name" from the menu, then enter a name, it posts a specific response.
Here's how the html looks:
<form action="hello.php" method="post">
<select>
<option disabled="yes" selected="yes">Select...</option>
<option value="name">Name</option>
<option value="gender">Gender</option>
<option value="birthday>Birthday</option>
<input name="name" type="text" />
<input type="submit" value="Submit">
</form>
What I'm trying to do is have the php code change responses based on what's submitted. Here's the php code:
$name = $_POST['name'];
$gender = $_POST['gender'];
$bday = $_POST['birthday'];
With the responses:
echo "Hello, $name!";
echo "Your gender is $gender!";
echo "Happy birthday on $birthday!";
depending on what option they select. (I haven't finished the if/elseif/else statements yet because I'm not sure if they're influenced by how the information is recieved.)
Is it possible to do this? I know that my code will only ever return $name in this example, because
<input name="name"...>
But I don't know if it's possible to have the text field's information identified by the drop-down menu. I imagine it's probably possible with Javascript, but I've never used Javascript and wouldn't know how to do this.
Thanks!
EDIT: I found an answer. I ended up setting
<input type="text" name="submit" />
in my html code, and
$submit = $_POST['submit'];
in my php code. Now if I do something such as
echo $submit;
it returns whatever I entered in the html page. Thanks again!
<form action="hello.php" method="post">
<select name="myselectbox">
<option disabled="yes" selected="yes">Select...</option>
<option value="name">Name</option>
<option value="gender">Gender</option>
<option value="birthday>Birthday</option>
<input name="name" type="text" />
<input type="submit" value="Submit" />
</form>
Then in hello.php do this at the top of the file.
var_dump($_POST);
that should help you understand the relationship between a html form and the PHP Postback Form Handler (in your case hello.php)