0

I have this code (it's an include), but the thing is that when I send the form the $_POST data is not being sent. Im checking for $_POST data like this

if(isset($_POST['ft_upload']) && $_POST['ft_upload'] == 1){ //$usuario -> uploadFirstTime2($db); echo "ok"; } 

and the code for the form is

<div class="ft_userImage" style="background: url(<?php echo $usuario -> getProfileImage(); ?>);"></div> <p class="ft_step2_continue"><?=$TEXT_BUTTONS['continue'];?></p> <form action="" method="POST" class="ft_step2_form_upload"> <input type="hidden" name="ft_upload" value="1" /> </form> <script> $("p.ft_step2_continue").click(function(){ $(".ft_step2_form_upload").submit(); }); </script> 
9
  • What happens when you hit the submit button? Commented Sep 24, 2016 at 17:51
  • VAR_DUMP($_POST); returns array(0) { } Commented Sep 24, 2016 at 17:52
  • When I hit the submit button the page is refreshed Commented Sep 24, 2016 at 17:53
  • Check in your browser's console the request you made - look at network tab or something and look for "form data" and "request method". Commented Sep 24, 2016 at 17:53
  • Is not showing anything, just the request to stylesheets and jquery files Commented Sep 24, 2016 at 17:57

4 Answers 4

1

check.php

<?php if(isset($_POST['ft_upload']) && $_POST['ft_upload'] == 1) { echo "ok"; } ?> 

index.html

<!DOCTYPE html> <html> <head> <title>form</title> </head> <body> <form action="check.php" method="POST" class="ft_step2_form_upload"> <input type="hidden" name="ft_upload" value="1" /> </form> <button id="ft_step2_continue">SEND</button> <script type="text/javascript" src="https://code.jquery.com/jquery-1.12.4.min.js"></script> <script> $("#ft_step2_continue").click(function(){ $(".ft_step2_form_upload").submit(); }); </script> </body> </html> 

it works fine.

i think, you just forgot action="check.php" in your form tag.

Sign up to request clarification or add additional context in comments.

Comments

0

Here check this:

<?php var_dump($_POST); ?> <html> <head> <title></title> </head> <body> <form action="" method="POST" class="ft_step2_form_upload"> <input type="hidden" name="ft_upload" value="1" /> </form> <script src="https://code.jquery.com/jquery-3.1.1.min.js" integrity="sha256-hVVnYaiADRTO2PzUGmuLJr8BLUSjGIZsDYGmIJLv2b8=" crossorigin="anonymous"></script> <script> $("p.ft_step2_continue").click(function(){ $(".ft_step2_form_upload").submit(); }); </script> </body> </html> 

Ok so i did this. Saved it in a php file. And then triggered the submit and it outputs:

array(1) { ["ft_upload"]=> string(1) "1" } 

Your php code should be in the same file where the form html is written because your action attribute is empty.

Comments

0

You need to specify the action attribute.

<form action="check.php" method="POST" class="ft_step2_form_upload">

1 Comment

i've tried with that but does'nt work. Anyway the action is optional. If is blank redirects to the same page
0

I think you want transfer a file to server??? if yes:

<form method="POST" action="this-file-name.php" enctype="multiform/form-data"> Your Photo: <input type="file" name="filet" required="required"> <input type="submit" value="Send Photo"> </form> <?php if(isset($_FILES['filet'])) { $dir = './my_dir_name/'; $file_name = $_FILES['filet']['name']; $doit = @move_uploaded_file($_FILES['filet']['tmp_name'],$dir.$file_name); if($doit) { echo 'File '.$file_name.' uploaded'; } } ?> 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.