PHP Request for posting Form to Iframe - php

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>";
?>

Related

How to send a form only if a field is empty

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 :)

HTML Form Not POSTing? Has name field?

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']);?>">

Unable to get JFactory::getApplication in joomla using cBox popup

I am Developing popup component for joomla site,
The Pop up Working Great , In my Popup i get phone number from user, i need to store that phone number to joomla database , but i am unable to call JFactory::getDBo(), when i call these method , popup was not working, i am in trouble , any help will be appreciate me.. thanxs in advance...
site/default.php
<script>
function openColorBox() {
$.colorbox({
innerWidth:500,
innerHeight:300,
iframe:true,
href: "subscribe.php",
overlayClose:true,
onLoad: function() {
$('#cboxClose').remove();
}
});
}
setTimeout(openColorBox, 1000);
</script>
site/subscribe.php
<body class="oneColFixCtr">
<div id="container">
<form name="Mail_list" action="#" method="post">
<p>
<label for="phone">Your Mobile Number </label>
<input type="tel" name="phone" id="phone" size="10" pattern="\d{10}" required />
<input type="hidden" name="date1" id="date1" value="<?php echo date('d.m.y'); ?>" />
</p>
<input type="submit" name="submit" value="Enter">
</form>
</div>
Your form is not posting the data anywhere when sumitted. Your action="#" will never allow the form to submit. Set your action to PHP_SELF if you need to submit it back to subscribe.php, then have a check in your subscribe.php that processes your form.
The better method would be to have your popup content in a hidden div and open that div instead of using an iframe. Use subscribe.php as your logic for saving the users data to the database. Using ajax to submit the form wouldn't be a bad idea either.

PHP form - with validation honeypot

I have the below for that works well, but is open for spam bots.
I want to put in a honeypot, not a captcha.
The code below works with the validation for the name, email, message,
but I can not get it to work with the honeypot.
Can anyone look at the "honeypot" code and tell me how to fix it?
I would like for the form to give an $success2 = "No Spamming allowed" that acts like the form was submitted, but does not actually submit the form.
Thanks
The Form:
<form id="contactform" action="send2.php" method="post"><div id="success"></div><div id="error"></div>
<label for="name">Name:</label><input type="text" id="name" name="name"/>
<label for="email">Email:</label><input type="text" id="email" name="email"/>
<label for="message">Message:</label><textarea id="message" name="message" rows="12" cols="20"></textarea>
<label id="robot">Are you a robot?</label><input type="text" name="robot" id="robot">
<input type="submit" value="Send your message" id="send" />
</form>
The PHP:
can be found here: http://goviewmy.com/contact/showcode/
Sorry, but i cannot get the PHP code to post in this question, so I attached a link to it.
Thanks
Honeypots work best if they have a field name that sounds legit, they should also be hidden using javascript to change the css after the page loads. (Most) bots don't have javascript enabled so they cannot process that this field should not be filled out.
I use something like this:
<div class='req'>
<label for='website'>Leave blank</label>
<input type='text' name='website'>
</div>
Hide it with jquery:
$(document).ready(function(){
$(".req").hide();
});
reject it server side if the field is filled out with something like this
if($_POST['website'] != ''){
echo "It appears you are a bot!";
}
else{
//process the rest of the form
}

Form not parsing correctly

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.

Categories