POST error with Markdown in Jekyll for Github Page - php

I am trying to implement a simple form in my Github page to learn how to use POST in html forms. The code I am using right now contains:
2014-07-05-post1.markdown:
<form action="/scripts/1.php" method="post">
Name: <input type="text" name="name"><br>
E-mail: <input type="text" name="email"><br>
<input type="submit">
</form>
1.php:
<html>
<body>
Welcome <?php echo $_POST["name"]; ?><br>
Your email address is: <?php echo $_POST["email"]; ?>
</body>
</html>
However this returns an error:
How do you correctly use POST requests in Markdown and Jekyll.

I think you can't.
Jekyll in the end generates just a static site, i.e. a bunch of HTML and CSS files. The server does nothing but serving those files, the server doesn't do any processing. But when you do a HTTP POST, you send data to the server and it would have to do something with the data (e.g. saving it to a database or sending an email).
So your form is correct but there's nothing on the server-side that can receive it. However, you could send the form data to a third-party server or use a PHP or node.js server for that.

Related

HTML PHP form post showing up blank?

I have two files, testpage.html and testpage.php in the same folder.
This is testpage.html
<!DOCTYPE HTML>
<html>
<body>
<form action="testpage.php" method="post">
Name: <input type="text" name="name"><br>
E-mail: <input type="text" name="email"><br>
<input type="submit">
</form>
</body>
</html>
This is testpage.php
<html>
<body>
Welcome <?php echo $_POST["name"]; ?><br>
Your email address is: <?php echo $_POST["email"]; ?><br>
</body>
</html>
The form seems to work okay but when I hit submit nothing shows up on the next page. no matter what I enter int he form, it always reads "Welcome" "Your email address is:" with nothing entered after that like its supposed to.
Do I have something configured incorrectly? Am I using the wrong browser (firefox)?
Thanks!
"I am accessing it via file:///C:/... should I be accessing it some other way instead?"
Just as I thought.
There you go. A web browser will not parse PHP directives that way.
It must be accessed as http://localhost/yourfile.xxx
Plus, a webserver and PHP need to be installed in order to parse PHP directives.
"I don't think I have Xampp or any virtual server set up... I'll look into that, any tips on where to start?"
You need to install one. Here are a few links to get you started and depending on the platform you are using.
https://www.apachefriends.org/
http://www.wampserver.com/
https://www.mamp.info
http://www.easyphp.org/
Pick your flavour.

PHP POST not working correctly

When I submit my form, I get sent to the correct file as specified in the action attribute of my form, but the PHP in the file isn't printing the variables at all... I've combed through posts of other people having the same issue, but none of their solutions fix my problem. I've stripped my code down to a simple, textbox, button, and a php file that's supposed to print the textbox value.
If it matters, I'm running this locally in chrome, not using any servers or websites yet, I'd like to get my code working locally before I upload to my server.
HTML
<html>
<form action="Submit.php" method="post">
<input type="text" placeholder="First Name" name="firstName" id="firstName" required>
</br></br>
<input type="submit" name="submitted" value="Submit">
</form>
</html>
PHP
<html>
<body>
Name <?php echo $_POST["firstName"]; ?><br>
</body>
</html>
All I get when I click the button is a white page with "Name" printed.
Thanks!
Running scripts in response to HTTP requests is something that's done by the webserver. If you just use local files, the script will simply be loaded into the browser as a text or HTML file, it won't be executed. You can't do form processing like this.
You need to run a local server, then access the form as http://localhost/form.html

How to send data from Google Ad form using php action hosted in different server

I have a Gmail Sponsored Promotion Ad which has a form. The form collects basic data like name and email, then redirects the user to a page where they can download a pdf file and sends the form data to my email via a php file (submit.php). However, I can't host submit.php in the same server as the form, Google doesn't allow any other files other than index.html and the images, and no script either, only vanilla HTML. All I can do is link to an external action.
This works when the submit.php file is hosted on the same server as the form, but not when they are hosted in different servers - I don't get the email with the data from the form. Why is that? And what can I do to circumvent it?
ps. I don't know any PHP
Form hosted in http://google.com/
<form action=" http://me.com/submit.php" method="post">
<input type='email' name='email'></input>
<input type='submit'></input>
</form>
submit.php hosted in http://me.com
<?php
$email = $_POST['email'];
$msg .= $email;
if (mail ($email_sender, $email_subject, nl2br($msg), $email_headers)){
?>
<script language= "JavaScript">
location.href="http://file.pdf"; </script>
?>
The Problem is not easy to solve ... Here you can find some information about the reason cross-domain-form-posting
One way could be:
In submit.php (when i understand you right) you have access of POST/GET data, if so .. write a function to send the data to a foreign domain, eg. use CURL functions or use a DB

Very basic php/html form

I'm very new to php/html, and I'm trying to teach myself the basics of creating and processing an html form.
I created a folder called Website. In it I created an html file index.html. I also created a file submit.php.
(this code is taken from: http://www.w3schools.com/php/php_forms.asp)
In index.html I have:
<html>
<body>
<form action="submit.php" method="post">
Name: <input type="text" name="name"><br>
E-mail: <input type="text" name="email"><br>
<input type="submit">
</form>
</body>
</html>
In submit.php I have:
<html>
<body>
Welcome <?php echo $_POST["name"]; ?><br>
Your email address is: <?php echo $_POST["email"]; ?>
</body>
</html>
When I open the html file in chrome and fill in the blanks and press submit, I get redirected to a page with the code in submit.php:
<html>
<body>
Welcome <?php echo $_POST["name"]; ?><br>
Your email address is: <?php echo $_POST["email"]; ?>
</body>
</html>
I should be getting this output:
Welcome Hannah
Your email address is Hannah#example.com
What am I doing wrong that the output isn't working?
Thanks!
PHP is processed on a server, so you can't treat it like HTML, it needs to be placed on a server that has apache installed. You can install one on your computer, using something like the following:
WAMP
LAMP
MAMP
XAMPP
Sounds like you are doing this via files on your desktop and not via a web server. Either on the Internet or via your local machine. I took your example 100% as presented, placed it within my htdocs folder in MAMP (LAMP for the Macintosh) and it behaves 100% as expected.
The difference between loading files on your desktop versus a web server is a web server will process the PHP. If you just do it as files, then the file gets loaded & doesn’t get parsed.

Locally testing form handling with PHP

I am creating an online order form for a wholesale nursery. I am trying to test the PHP locally and have successfully set up WAMP. When I test basic scripts, they run just fine but when I try using _POST to send data to variable from HTML input fields, nothing gets transferred to my PHP variables as noted when I try echoing them to a page. Is there something I need to do to test _POST and _GET methods locally that I don't know about?
I tried testing my ability to do so using a simple example I found at W3 schools:
<html>
<body>
<form action="test.php" method="post">
Name: <input type="text" name="fname"><br>
Age: <input type="text" name="age"><br>
<input type="submit">
</form>
</body>
</html>
Here is the PHP:
<html>
<body>
Welcome <?php echo $_POST["fname"]; ?>!<br>
You are <?php echo $_POST["age"]; ?> years old.
</body>
</html>
Like I said, I used WAMP and both files are located in the wamp/www/ folder.
First of all all forms need a method (get, post) and an action (where to send the data) in the html.
<form action='your/location.php' method='post'>
<input type='text' name='username'/>
<input type='submit' value='submit'/>
</form>
All inputs must have a name attribute this is for referencing data in the php script
<input type='text' name='username'/>
In your/location.php you will receive an array with the data under the name:
$_GET or $_POST depending on your method set in the form tag.
To access specific data use $_POST['username'] (replace username with any names set on any of the submitted form inputs)
To print out on the screen use
echo $_POST['username'];
Check if your file is under the extension .php and has the name test
If you get partial output and by partial i mean only the html part start you php server Apache or Nginx or whatever wamp uses, it might not start with all the functionality without specified to do so.
Make sure you open the page under localhost if you are testing it separately.
If for some reason you can't seem to get wamp to work try xampp which is similar and in my opinion better and never failed me.

Categories