php form sanitation before sending to external url - php

I have a form on my site that gets submitted to a third party site which basically adds the form data as a record in the third party database. This is implemented with the form "action" attribute. I have no control over what the third party does after the form is submitted. See below for the implementation.
I'm doing javascript validation, but I also need to be able to do server-side sanitation and validation of the form data with php before it gets sent to the third party. I may also want to implement a CAPTCHA.
What approach can I take to achieve this? I thought about having the form submit to the script that houses the form, and collecting all of my $_POST variables, do the validation, and then maybe redirect to the third party URL, but not quite sure how the third party would receive all the form data if its not longer the form action. Is it possible to just tack all of my form variables on as a query string the third party URL?
<form id="contactform" name="contactform" onsubmit="return validateForm(this)" method="post" encType="multipart/form-data" action="https://thirdpartysite.com/db/?action=AddRecord&apptoken=xxx">
<input class="contactfield required contact_name_first" type="text" id="firstname" name="firstname" placeholder="FIRST NAME" />
<input class="contactfield required contact_name_last" type="text" id="lastname" name="lastname" placeholder="LAST NAME" />
<input class="contactfield required contact_org" type="text" id="organization" name="organization" placeholder="ORGANIZATION" />
<input class="contactfield required contact_email" type="text" id="email" name="email" placeholder="EMAIL" />
<input class="contactfield required contact_phone" type="text" id="phone" name="phone" placeholder="PHONE" />
<textarea class="contactfield required contact_msg" id="message" name="message" cols="40" rows="10" placeholder="HOW CAN WE HELP YOU?"></textarea>
<input type="hidden" name="rdr" value="http://www.mysite.com/thank-you" /><!-- Note: this gets passed to the third party site as the page to redirect back to after third party site receives the form data" -->
</form>

Related

Firebase Hosting - PHP Starts file download

I have just put up a site on firebase, on it is a form where users can put in their database credentials to access it remotely. The form uses POST to send the details to a php page, and its code looks like this:
<form name="login-form" action="login.php" method="post">
<input autocomplete="off" name="ip_address" type="text" placeholder="Enter DB IP"/>
<br/>
<input autocomplete="off" name="db" type="text" placeholder="Enter DB Name"/>
<br/>
<input autocomplete="off" name="username" type="text" placeholder="Enter Username"/>
<br/>
<input name="password" type="password" placeholder="Enter Password"/>
<br/>
<input id="login-button" type="submit" value=">"/>
</form>
Using my apache2 web server, this process works fine, and the user is redirected, however when deployed with firebase (firebase deploy --only hosting), the process instead triggers a file download of login.php. Why is this happening? The file structure for the public folder is exactly the same as it is for apache, as is each files content.

PHP form needs be sumbited 2 times to get post [duplicate]

This question already has answers here:
Checking if form has been submitted - PHP
(9 answers)
Closed 12 months ago.
I'm novice and i want save images from a Form in php.
my code is pretty simple:
<form method="POST" enctype="multipart/form-data" action="">
<label for="nom">Nom :</label><input type="text" name="nom" id="nom">
<label for="adresse">Adresse :</label><input type="text" name="adresse" id="adresse">
<label for="tel">Numéro de télephone :</label><input type="text" name="tel" id="tel">
<label for="mail">E-mail :</label><input type="text" name="mail" id="mail">
<label for="web">Url du site web</label><input type="text" name="web" id="web">
<label for="images">Logo/image</label>
<input type="file" multiple name="images" id="images" />
<input type="submit" class="bouton" id="valider" value="valider"/>
</form>
and I just want see if my images arrive in my $_FILES.
so i have at the top of my index.php
<?php
echo var_dump($_FILES);
?>
when i press the submit button the 1st time, it's still empty, but if i press it a second time, i get it.
do someone knows why ?
thank you.
The first click is putting you on the webpage of the form as it
can't work without fields populated.
The second click is running your action with files inside it, so
it works.
Why ?
Because you are displaying your form in various webpages, you must handle your form action in a website global point of view. You are using php so try to use the layout feature for html is one thing, but do not forget to do the same for handling your POST action globally.

204 Error - Hubspot Form Error

I am trying to integrate HubSpot into a custom form and my PHP knowledge is limited. So any help would be very much appreciated.
When submitting my form i am getting a log of 204. When I go to my form submissions I can see an entry but no data is being carried across.
Bellow is my form code.
HTML:
<input id="first_name" class="hs-input" name="first_name" type="text" placeholder="First Name" autocomplete="given-name" value="" required>
<input id="lastname" class="hs-input" name="last_name" type="text" placeholder="Last Name" autocomplete="family-name" value="" required>
<input id="phonenumber" class="hs-input" name="phone_number" type="number" placeholder="Phone Number" value="" required>
<input value="Submit" typeI"submit">
And i am using the PHP script from this link:
https://developers.hubspot.com/docs/methods/forms/submit_form
Thanks
A 204 status code is actually a success status code;
The 204 (No Content) status code indicates that the server has successfully fulfilled the request and that there is no additional content to send in the response payload body.
HTTP Protocol definition
So basically it tells you; "Hey, I'm all good. Data received and processed". You don't need additional information do you? Only when it fails you would want to know why it fails.
When you copied the script form the Hubspot API docs, did you notice this line?
//Need to populate these variable with values from the form.
The variables right below that line ($firstname, $lastname, etc) don't actually exist yet. You will have to add something like this before that line;
$firstname = $_POST['first_name'];
$lastname = $_POST['last_name'];
// etc.

Sending Bootstrap Form Data To Email Address

I have a bootstrap form which I need to send to am email address once the contact form has been submitted. I've built the form using Bootstrap but I've not used PHP before and I'm not sure how to integrate this with the rest of the site.
Is there an alternative to PHP for simply and safely submitting this form data to the email address?
<div class="row" id="contact_us_form">
<h1>Ready to talk?</h1>
<h4 style="margin-bottom:30px">Please call 0345897394852, email email#email.com or fill out the contact form below for a FREE 15 minute consultation.</h4>
<div class="col-sm-5 form-group">
<input class="form-control" id="name" name="fname" placeholder="First Name" type="text" required>
<input class="form-control" id="name" name="lname" placeholder="Last Name" type="text" required>
<input class="form-control" id="email" name="email" placeholder="Email" type="email" required>
</div>
<div class="col-sm-7 form-group">
<textarea class="form-control" id="comments" name="comments" placeholder="Message" rows="5"></textarea>
</div>
<div class="col-sm-12 form-group"><button class="btn btn-default pull-right" type="submit">Send</button></div>
</div>
You could do it in a few steps. Or just one tutorial.
You should first learn some more about how PHP form handling works. Start with this: http://www.w3schools.com/php/php_forms.asp (Dont forget the <form> tags around your form, as you currently do not have these)
(You could do validation, as you want it safely send: http://www.w3schools.com/php/php_form_url_email.asp)
Then move on to sending emails. As linked by #shubham: How to send an email using PHP?
It is not that hard. There are many complete tutorials online. As a simple google search delivered this tutorial: http://www.html-form-guide.com/email-form/php-form-to-email.html
Also be cautious when implementing a contact form. A contact form without captcha validation is prone to spam. Please consider implementing captcha. Hope this helps.

Joomla! Contact form inside an article, can't get action php file working

I'm trying to create a contact form on my own. I noticed that it can be achieved by placing the form inside an article, instead of a custom html module.
In the client side, it seems to work. I even added a captcha manually (the re-captcha plugin doesn't seem to work for me). The problem is, I set form's action property as "mail.php", and just added this "mail.php" file to the the template root. The "mail.php" supossedly retrieves the data send by post, and finally composes and sends the email, showing a "message send" notification.
Anyway, when I click on submit, the form page is just reloaded. I guess that Joomla! can't find my "mail.php". I guess that this issue is related to the joomla structure and my inability to place the "mail.php". Any help will be wellcome.
This is how my article looks like (wysiwyg editor mode disabled):
<form action="mail.php" method="post" target="_blank">
<p><label for="nombre">Nombre:</label></p>
<p><input maxlength="50" name="nombre" size="30" type="text" /></p>
<p><label for="email">Email:</label></p>
<p><input maxlength="50" name="email" required="required" size="30" type="text" /></p>
<p><label for="asunto">Asunto:</label></p>
<p><input maxlength="150" name="asunto" size="30" type="text" /></p>
<p><label for="mensaje">Mensaje:</label></p>
<p><textarea cols="50" maxlength="700" name="mensaje" required="required" rows="8"></textarea></p>
<div class="g-recaptcha" data-sitekey="6Lefblahblahblahblah"> </div>
<p><input type="submit" /></p>
</form>

Categories