PHP Form post always empty - php

this must be configuration issue and I'm hoping somebody can help. I'm setting up a new project on my localhost and my PHP Post is always empty. Here's the example:
My Form Page:
<form id="loginForm" action="/post/login" method="post">
<input type="text" name="username" />
<input type="password" name="password" />
<input type="submit" value="Submit" />
</form>
and the "/post/login/index.php" page:
<?php
var_dump( $_POST );
?>
the result:
array(0) { }
It seems like there's no code issue so what's the problem?

The action attribute needs to point to the actual script of the page you want to go to.
Try doing this instead:
<form id="loginForm" action="/post/login/index.php" method="post">

Related

Empty $_POST in Wordpress Archive Page

I have a custom form in my wordpress theme archive.php file but I can't get the post of that form. It's empty.
I have these:
<?php print_r($_POST); ?>
<div class="filtros">
<h3>Búsqueda de documentos</h3>
<form action="#" method="post">
<input type="text" id="name" name="f_name" placeholder="Buscar" value="<?php echo $_POST['f_name']; ?>" />
<div class="dates">
<input type="text" id="inicio" class="date" name="f_inicio" placeholder="Fecha de inicio" value="<?=$_POST['f_inicio']?>" /> /
<input type="text" id="final" class="date" name="f_final" placeholder="Fecha final" value="<?=$_POST['f_final']?>" />
</div>
<div class="submit"><input type="submit" value="Buscar" /></div>
</form>
</div>
Even if I pass the variables throw the URL I cant get that vars with $_GET.
¿Any idea?
While it's not advisable from a security point of view, you can change the method on your form from method="post" to method="get" to have variables posted as $_GET variables instead.
Change action="#" to action="<? echo $_SERVER['REQUEST_URI']?>"
Try change <?= to <? echo
You may need to point the action="myfile.php" to specific file.. See the solutions here:
$_POST returns empty on form submit in wordpress

my form failed to be submitted

I have the following code which works by itself but when I try it on wordpress, it shows the login but when I click on submit, it does not submit the form, and goes to following address and shows a white page.
http://localhost:8080/wordpress/wp-admin/admin.php
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
Username <input type="text" name="username" />
<br />
Password <input type="password" name="password" />
<br />
<input type="submit" value="Login" />
<?php
if(isset($_POST["username"])
....
You should perhaps go into more detail of what you are trying to achieve.
Any reason you are not using wp_login_form()?
As for the white screen, I would also recommend to turn on debugging, inside your wp-config.php file is the line define('WP_DEBUG', false); . Change that to true. ( I can only also assume the login showed a white screen because of missing nonce fields, which would go away with using wp_login_form() )
Add name attribute in the form field
<form method="post" name="form_name" action="<?php echo $_SERVER['PHP_SELF']; ?>">

Having Two Self Submitting Forms

Is it possible for me to have two self submitting forms on a single page. If yes how do I allot different blocks of code to each form ?
Have a hidden input with two different values.
<form action="" ...>
<input type="hidden" name="form_no" value="0">
...
</form>
<form action="" ...>
<input type="hidden" name="form_no" value="1">
...
</form>
On the server side, different on the basis of $_REQUEST['form_no']
Or you could also add it as a name parameter in submit element.
<input type="submit" name="form0">
Use isset($_REQUEST['form0']) to differentiate.
Another way of doing it is to append a GET parameter to differentiate
<form action="<?php echo $_SERVER['PHP_SELF'];?>?form_no=0" ...>
...
</form>
<form action="<?php echo $_SERVER['PHP_SELF'];?>?form_no=1" ...>
...
</form>
Use $_GET['form_no'] to differentiate.
Name your first form form_one, and the second form form_two.
<?php
if (isset($_POST['form_one'])) {
// First form was submitted
}
if (isset($_POST['form_two'])) {
// Second form was submitted
}
?>
Two forms can be placed in a code by giving them different names and keeping their target _blank
<form action="action.asp" method="get">
First name: <input type="text" name="fname" /><br />
Last name: <input type="text" name="lname" /><br />
<input type="submit" name="submit1" value="Submit" />
</form>
<form action="action.asp" method="get">
First name: <input type="text" name="fname" /><br />
Last name: <input type="text" name="lname" /><br />
<input type="submit" name="submit2" value="Submit" />
</form>
<?php
if(isset($_GET['submit1'])){
// first form was submitted
}
if(isset($_GET['submit2'])){
// second form was submitted
}
?>
Each form has a different script specified in this example, but keep in mind that you can simply use the same php file for both actions, specifying a different block of code for each form (that's the php part above).
Someone may have a better answer, but this method has served me well in the past.

Tomcat 6 & PHP with enctype - No input data returned

I have this problem when I'm using PHP5/HTML on Apache-Tomcat6.
Here's an example for one of the forms I use in my site:
<form enctype="multipart/form-data" method="post" action="hello.php" >
<label>Title* :</label>
<input type="text" name="title" />
<label>Image:</label>
<input type="file" name="image" /><br />
<input type="submit" value="Add"/>
</form>
Whenever I add the 'enctype' attribute to any form; neither the $_FILES['image'] is returned nor the $_POST variables. As long as the 'enctype' is not there, everything (except for the file input of course) works as expected. Can any one guide me please?
You won't be able to post data with a method of get on your form.
In test.html:
<form enctype="multipart/form-data" method="post" action="hello.php" >
<label>Title* :</label>
<input type="text" name="title" />
<label>Image:</label>
<input type="file" name="image" /><br />
<input type="submit" value="Add"/>
</form>
In hello.php:
<?php
print_r($_POST);
print_r($_FILES);
Depending upon your server configuration, this will combine $_GET, $_POST, and $_COOKIE, but you'll still want to post with file inputs.
print_r($_REQUEST);

how to pass values from one page to another on jquery form submit

I'm trying to build a form using php & jquery, but I'm a little confused as to what to do with the jquery portion of it...
Basically, when the user submits the first form, I want to direct them to the "next step" form, but I want to retain the values submitted from the first one in a hidden input field...
If someone can either show me how or point me to a good tutorial, I'd appreciate it...
I don't have any of the php or jquery yet, and this is just a simplified version of the html markup...
//first.php
<form name="form1" method="post" action="second.php">
<input type="text" name="name" value="" />Name
<input type="submit" name="step1" value="Next" />
</form>
//second.php
<form name="form2" method="post" action="process.php">
<input type="hidden" name="name" value="{$_POST['name']}" />
<input type="text" name="message" value="" />message
<input type="submit" name="step2" value="Finish" />
</form>
<input type="hidden" name="name" value="{$_POST['name']}" />
should be,
<input type="hidden" name="name" value="<?php echo $_POST['name']}; ?>" />
and also sanitize the input, if you want
I don't no if there is a better way to do that.
But, when I need to do such thing, I do in this way:
<script>
<?php
foreach($_POST as $key => $valule)
{
echo "$('$key').val('$value')";
}
?>
</script>
So, in your nextstep file, all you'll need to do is set up the hidden fields and then just loop through the post vars and set each one via jquery.

Categories