Ok, I know this is probably a really dumb question but I can't figure out what is going on here. I've got this in my original html file-
<form action="./api" method="POST">
<label for="first-name">First Name: </label>
<input id="first-name" type="text" name="first_name" /><br/>
<label for="last-name">Last Name: </label>
<input id="last-name" type="text" name="last_name" /><br/>
<input type="submit" name="send" value="Submit Form"/>
</form>
In my api folder I have an index.php file that has the following code-
<?php
print_r($_POST);
?>
Thats it- I know its not safe but I was just trying to get it to work. It returns an empty array...
Array ()
I really need a second pair of eyes on this, what am I missing? why isn't the information being transmitted?
Update:
changing the action to action="./api/index.php" returns the posted variables as expected. As someone commented below, I was hitting the index.php in the api folder before because it was returning the empty array. Its strange that it didn't accept the data. Is it common practice in php then to make the target of your post explicit?
Please add the full file path to your action and convert your
$_POST[''] to variables. The code below should work perfectly based on your question.
<form action="../api/index.php" method="POST">
<label for="first-name">First Name: </label>
<input id="first-name" type="text" name="first_name" /><br/>
<label for="last-name">Last Name: </label>
<input id="last-name" type="text" name="last_name" /><br/>
<input type="submit" name="send" value="Submit Form"/>
</form>
Add this to ../api/index.php
<?php
$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];
echo $first_name;
echo $last_name;
?>
Related
I'm trying to create a form post within a larger block of PHP code, but overall my web page fails to load. To troubleshoot this, I've commented out a specific section of code and I think I've found where my error code be, even if I don't know what that error is -- when this code is commented, my page works, albeit without the added content below.
echo '<form method="POST" action="addPeople.php">
First Name: <input type="text" name="FirstName"><br>
Last Name: <input type="text" name="LastName"><br>
Birthdate: <input type="text" name="Birthdate"><br>
Birth City: <input type="text" name="BirthCity"><br>
Birth State: <input type="text" name="BirthState"><br>
Region: <input type="text" name="Region"><br>
<input type="submit" name = "submit" class="button tiny round" value="Add Person" />
</form>'
Have I overlooked a syntax error with my quotations? Or maybe I'm just not handling the form method correctly? Would really appreciate some insight.
You forgot the ;.
Try :
echo '<form method="POST" action="addPeople.php">
First Name: <input type="text" name="FirstName"><br>
Last Name: <input type="text" name="LastName"><br>
Birthdate: <input type="text" name="Birthdate"><br>
Birth City: <input type="text" name="BirthCity"><br>
Birth State: <input type="text" name="BirthState"><br>
Region: <input type="text" name="Region"><br>
<input type="submit" name = "submit" class="button tiny round" value="Add Person" />
</form>';
I have been trying to pre-fill the subject input with information generated in another page, but have been having difficulties with it despite reading a lot of resources about it and seeing examples. I have tried a variety of links, including my most recent attempt with http://www.myurl.com/folder/index.php/contactform?subject=test, but even that doesn't work. Anybody have any advice? Also, if you want to test it out before answering, the page experiencing the problem is the contact page of this website. I've removed information from below to make it more general. Thanks in advance for any and all of the help.
<form id="contactform" method="post">
<input name="recipient" type="hidden" value="myemail" />
<input name="subject" type="hidden" value="Contacter" />
<p id="contactname">
<label>Name:</label>
<input name="name" type="text" />
</p>
<p id="contactemail">
<label>Email:</label>
<input name="email" type="text" />
</p>
<p id="title">
<label>Subject:</label>
<input name="title" type="text" />
</p>
<p id="contactmessage">
<label>Message:</label>
<textarea name="message"></textarea>
</p>
<p id="submit">
<input type="button" value="Send" />
</p>
<input name="redirect" type="hidden" value="myredirectpage" />
</form>
Lets say your page URL is some thing like below
http://www.example.net/index.php?var1=Something&var2=10&var3=ok
You can use $_GET to get the values of var1, var2,and var3 from the above url
In index.php use the below code to fetch url data
echo $_GET['var1'] // Something
echo $_GET['var2'] // 10
echo $_GET['var3'] // ok
Go through this link http://php.net/manual/en/reserved.variables.get.php
With php you can do this with a session.
On the other page(not the form) you can do $_SESSION['subject'] = 'your subject';
On the form page you can acces this cookie ( make sure you have started the session on top of the page with session_start():
<p id="title">
<label>Subject:</label>
<input name="title" type="text" value="<?= $_SESSION['subject'] ?>"/>
</p>
Yes, forms of this question are asked all the time. Due to the infinite possible ways that one can construct a form/php pair, my question still is different. (and much simpler)
I have:
<html>
<body>
<form id="request-inspecton" action="test_form_processor.php" method="POST">
<label class="text-label" for="FirstName">*first name:</label>
<input class="text-input" type="text" name="FirstName" id="FirstName" required="required" placeholder="First Name">
<label class="text-label" for="LastName">*last name:</label>
<input class="text-input" type="text" name="LastName" id="LastName" required="required" placeholder="Last Name">
<input class="button-input" type="submit" value="send" id="buttonSend" name="submitForm" placeholder="Submit form" value="POST">
</form>
</body>
</html>
and:
<?php
var_dump($_POST);
print $_POST["FirstName"];
?>
But all I get is:
array(0) { }
Golly, I just can't figure out what is wrong!\
Incidentally, example currently at:
http://checkitouthomeinspection.com/test_form.html
Strangely enough, it now works in both FF and Chrome. Beats me what the problem was. Thanks for the help. Case closed.
I'm developing a Web site for a school project. Though I mainly work with PHP, I thoght I should as well do some client-side validation.
It took a very short search in Google to find the Validate JQuery plugin.
And so far this is what I've got:
<form id="regform" class="well" method="post" action="Registering.php">
<label>Name: <input type="text" placeholder="Type your name" name="Name" class="required" /></label>
<label>Surname: <input type="text" placeholder="Type your surname" name="Surname" class="required" /></label>
<label>Username: <input type="text" placeholder="Type your username" name="Username" class="required" /></label>
<label>Password: <input type="password" placeholder="Type your password" name="Password" class="required" /></label>
<label>Repeat Password: <input type="password" placeholder="Confirm Password" name="Password-confirm" class="required" /></label>
<label>E-Mail: <input type="Email" placeholder="Type your Email" name="Email" class="required email" /></label>
<label>Birthday: <input type="Date" name="Birthday" /></label>
<label>Gender:</label>
<label>Male <input type="radio" name="Gender" value="0" checked> Female <input type="radio" name="Gender" value="1"></label>
<label>Photo: <input type="url" placeholder="Paste an image link" name="PhotoLink" class="url" /></label>
<label><input type="submit" class="btn btn-primary" name="Submit" value="Register in YouTune" /></label>
</form>
This is the form, pretty much a standard registration one. Nothing to add here.
And then I have this small Javascript:
$(document).ready(function(){
$("#regform").validate({
rules: {
Username: {
remote: { url: "/check_username.php", async: false }
}
},
messages: {
Username: { remote: "Username already on use. Pick a different one." }
}
});
});
Both scripts of the lastest JQuery library and the version 1.10 of the Validate Plugin were added on the head of the document.
Well, to make it short, the validation stuff runs smooth, except that the remote rule is not working. It is as if it wasn't there at all, no error message whether I submit with an already used Username or not. The php file that the Javascript is calling has the following script:
<?php error_reporting(E_ALL);
require_once("../Clases/User.php");
header('Content-type: application/json');
$vUser = new User();
$vResult = $vUser->GetUserByUsername($_REQUEST["Username"]);
if ($vResult) {
echo false;
} else { echo true; }
?>
The GetUserByUsername method goes to a DataBase and searches for a User with the given parameter, then returns true if there was a match up, false if there wasn't.
I've tested it without the remote call from the Javascript and it works fine
So, does anyone know why is this happening?
Thank you beforehand for taking the time read and trying to help me with this small issue.
EDIT: Solved. I just had to fix the source for the remote call. Can't believe I missed that. Anyway, thank you very much for the help.
I am not very sure but see if it works; remove "/" from your url. use "check_username.php" in place of "/check_username.php" or absolute url
I hope someone can help me. I'm a little at loss on how I can achive this: I'm trying to pass infos generated in my php to another form made in Javascript. For example, if I put my first name in the input field and click submit, then it would go to another page with the actual form and have the first name already filled there.
One thing that I did notice was that the javascript form isn't within the <form> tag, it's in a bunch of tables with some input fields. I can post what it looks like in pastebin if this can help in understanding what I mean.
Also with this script im unable to edit it, I did not make it, it is one of those script you just place on your site thats auto generated.
My form looks like this:
<form action="auto-form/index.php" method="post" name="openleads" onsubmit="return checkForm(this);">
<label for="first">First Name <span class="required">*</span></label>
<input id="first_name" type="text" name="first" applicationforms="true" /><br>
<label class="error" for="name" id="first_name_error" style="color:#F00; font-size:11px;">This field is required.</label>
<span class="fields">Zip <span class="required">*</span></span>
<input id="zip" type="text" name="zip" applicationforms="true" /><br>
<label class="error" for="name" id="zip_error" style="color:#F00; font-size:11px;">This field is required.</label>
<label for="last">Last Name <span class="required">*</span></label>
<input id="last_name" type="text" name="last" applicationforms="true" /><br>
<label class="error" for="name" id="last_name_error" style="color:#F00; font-size:11px;">This field is required.</label>
<span class="fields">Email <span class="required">*</span></span>
<input id="email" type="text" name="email" applicationforms="true" /><br>
<label class="error" for="name" id="email_error" style="color:#F00; font-size:11px;">This field is required.</label>
<input class="button" type="submit" name="send" value="Send" />
</form>
Any help is appreciated; like I said, I'm a bit at loss on what to do with this one.
php-form.php
<form action="javascript-form.php" method="post">
<input type="text" name="name" />
<input type="submit" value="Submit" />
</form>
javascript-form.php
<form action="" method="">
<input type="text" name="name" value="<?= (isset($_POST['name'])?htmlentities($_POST['name'],ENT_QUOTES):''); ?>" />
<input type="submit" value="Submit" />
</form>
Use PHP to output the POSTed values in to the value attribute of the form fields. You can also use GET variables and use javascript to parse the window.location and scrape those form values.
this seemed to get this done
<script type="text/javascript" src="http://jquery.offput.ca/js/jquery.timers.js"></script>
<script>
$(document).everyTime(1000,function(i){
if($('#ui-datepicker-div').length>0)
{
$('#first_name').val('<?php echo $_POST['first_name']; ?>');
$('#last_name').val('<?php echo $_POST['last']; ?>');
$('#zip').val('<?php echo $_POST['zip']; ?>');
$('#email').val('<?php echo $_POST['email']; ?>');
}
})
$('#first_name').val('test');
</script>