[symfony 2]form don't send a file - php

<div id="option-action">
<form action="{{ path('lab_univer_cpanel') }}" method="post" enctype="multipart/form-data" >
<table>
<tr>
<td><label>Titre</label></td>
<td><input type="text" id="titre" name="titreNews"></td>
<td></td>
</tr>
<tr>
<td><label>Image</label></td>
<td><input type="file" id="image" name="image" /></td>
<td></td>
</tr>
<tr>
<td><label>Contenue</label></td>
<td><textarea name="content" ></textarea></td>
<td></td>
</tr>
<div class="submit">
<input type="submit" name="addNews" value="+" class="addbtn">
</div>
</table>
</form>
</div>
I don't find the file image in the controller
This is the code to get request :
if ($req->request->get('addNews')) {
$titre = $req->request->get('titreNews');
$content = $req->request->get('content');
$membre = $em->getRepository('LabUniverBundle:Member')
->findOneBy(array('nom'=>'user'));
$image = $req->files->get('image');
print_r($image);
The result is a blank page !
I test with an other form like that :
<form action="{{ path('lab_univer_cpanel')}}" method="post" enctype="multipart/form-data" >
<input type="file" name="image" />
<input type="submit" value="send" name="checkUpload" />
</form>
It works !!!

Related

PHP can't get post data from jQuery dynamic method

I use .after method in Jquery to insert the html element.
This is my Jquery Code
$('#add_terms').click(function () {
var i = $('#terms>textarea').length;
$terms = $('#terms' + i);
i++;
console.log($terms);
$terms.after('<br><br>' + i + '. <textarea id="terms' + i + '" name="terms[]" ' + 'cols="60" rows="2" style="vertical-align:middle;"></textarea>');
})
My html:
<table width="98%" cellspacing="1" cellpadding="3" style="border-collapse:separate; border-spacing:0px 10px;">
<form method="post" enctype="multipart/form-data" name="form1" id="form1" action='' target="_self">
<tr>
<td align="center"> terms</td>
<td id="terms">
1.
<textarea id="terms1" name="terms[]" cols="60" rows="2"
style="vertical-align:middle;"><?php echo $terms1?></textarea>
<br><br>
2.
<textarea id="terms2" name="terms[]" cols="60" rows="2"
style="vertical-align:middle;"><?php echo $terms2?></textarea>
<br>
<input id="add_terms" name="add_terms" type="button" class="bt-add" value="add" style="margin-top:10px">
</td>
</tr>
<tr>
<td colspan="2" align="center">
<input id="add" name="add" type="submit">
<input id="clear" name="clear" type="reset" class="bt-return">
</td>
</tr>
</form>
</table>
I post the form,then I can get the value of terms1 and terms2 with using
print_r($_POST['terms']);
However, I can't get the value of terms3, terms4.
Hope this help you.
<form method="post" enctype="multipart/form-data" name="form1" id="form1" action='' target="_self">
<td align="center"> terms</td>
<td id="terms">
1.
<textarea id="terms1" name="terms[]" cols="60" rows="2"
style="vertical-align:middle;"><?php echo $terms1?></textarea>
<br><br>
2.
<textarea id="terms2" name="terms[]" cols="60" rows="2"
style="vertical-align:middle;"><?php echo $terms2?></textarea>
<br>
<input id="add_terms" name="add_terms" type="submit" class="bt-add" value="add" style="margin-top:10px">
</td>
</form>

Login form script change after introducing username and password

I have this form:
<div class="page3">
<form id="indexform" action="index.php" method="post">
<table class="datatable2" style="padding:20;" >
<tr>
<td><center>Username </center><input type="text" name="name" value="" size="10" /></td>
</tr>
<tr>
<td><center>Password </center><input type="password" name="password" value="" size="10" /></td>
</tr>
<tr>
<td colspan="2" class="datatable2" style="padding:55 0 0 38;">
<input type="submit" value="Log In" name="admsubmit" class="subbtn" style="background-image: url(imagini/autentificare.png);background-repeat:no-repeat;background-position:10 5;background-size:17px;"/></form>
</td>
<tr>
<td colspan="2" class="datatable2" style="padding:40 0 0 8;">
<form action="parola_uitata.php"> <input type="submit" align="right" value="Ai uitat parola?" class="subbtn" style="background-image: url(imagini/parola_uitata.png);background-position:11;background-repeat:no-repeat;background-size:17px;margin:-45 1;padding-left:30;" name="parola_uitata"></form>
</td>
</tr>
</table>
</div>
IMAGE:
and i want to know how i can hide after logging, and only displaying in same div some like : Hello ($_SESSION['user']) -- go to admin panel. If someone can give me some idea it would be helpful me.
Wrap an if statement around your markup, and display based on the state of the session (if they are logged in or not)
<div class="page3">
<?php if(!isset($_SESSION['logged_in'])) : ?>
<form id="indexform" action="index.php" method="post">
<table class="datatable2" style="padding:20;" >
<tr>
<td><center>Username</center><input type="text" name="name" value="" size="10" /></td>
</tr>
<tr>
<td><center>Password </center><input type="password" name="password" value="" size="10" /></td>
</tr>
<tr>
<td colspan="2" class="datatable2" style="padding:55 0 0 38;">
<input type="submit" value="Log In" name="admsubmit" class="subbtn" style="background-image: url(imagini/autentificare.png);background-repeat:no-repeat;background-position:10 5;background-size:17px;"/></form>
</td>
<tr>
<td colspan="2" class="datatable2" style="padding:40 0 0 8;">
<form action="parola_uitata.php"> <input type="submit" align="right" value="Ai uitat parola?" class="subbtn" style="background-image: url(imagini/parola_uitata.png);background-position:11;background-repeat:no-repeat;background-size:17px;margin:-45 1;padding-left:30;" name="parola_uitata">
</form>
</td>
</tr>
</table>
<?php else : ?>
<-- User logged in, show control panel stuff !-->
<?php endif; ?>
</div>

PHP form to send email from Website

This is my html form requesting feedback.
What would the corresponding PHP form be to place on my webserver to send the email? I am new at website design and have only learnt CSS+ HTML.
<table width="518" border="0">
<tr>
<td width="165"><form name="form1" method="post" action="">
<label for="nameco">Name/Company</label>
:
</form></td>
<td width="343"><input name="nameco" type="text" id="nameco" size="70"></td>
</tr>
<tr>
<td><form name="form2" method="post" action="">
<label for="area">Area you are located :</label>
</form></td>
<td><input name="area" type="text" id="area" size="70"></td>
</tr>
<tr>
<td><form name="form3" method="post" action="">
Products interested in :
</form></td>
<td><table width="198">
<tr>
<td width="190"><label>
<input type="radio" name="Product" value="awnings" id="Product_0">
Awnings</label></td>
</tr>
<tr>
<td><label>
<input type="radio" name="Product" value="carport" id="Product_1">
Carport/Shadeport</label></td>
</tr>
<tr>
<td><label>
<input type="radio" name="Product" value="patio" id="Product_2">
Patio</label></td>
</tr>
<tr>
<td><label>
<input type="radio" name="Product" value="other" id="Product_5">
Other
<input type="text" name="other1" id="other1">
</label></td>
</tr>
</table></td>
</tr>
<tr>
<td><form name="form4" method="post" action="">
<label for="contactno">Contact Number :</label>
</form></td>
<td><input name="contactno" type="text" id="contactno" size="70"></td>
</tr>
<tr>
<td><form name="form5" method="post" action="">
<label for="email">Email Address :</label>
</form></td>
<td><input name="email" type="text" id="email" size="70"></td>
</tr>
<tr>
<td><form name="form7" method="post" action="">
<label for="Comments">Additional Comments :</label>
</form></td>
<td><input name="Comments" type="text" id="Comments" size="70"></td>
</tr>
<tr>
<td><form name="form8" method="post" action="">
<input type="submit" name="Submit" id="Submit" value="Submit">
</form></td>
<td><form name="form9" method="post" action="">
<input type="submit" name="reset" id="reset" value="Reset Form">
</form></td>
</tr>
</table>
This is from dreamweaver. And how do i let the form know to send via this PHP file?
If I can give you advise, don't use so many forms, just use one and set action in send.php.
send.php can look like this:
<?php
$to = "$_POST['email']";
$subject = "$_POST['subject']";
$message = "$_POST['message']";
$from = "your#email.com";
$headers = "From:" . $from;
mail($to,$subject,$message,$headers);
echo "Mail Sent.";
?>

Error when trying to fill in registration fields

I'm trying to create a login and registration system with PHP for a school assignment, but it's currently not really working...
The problem is it generates an error saying the fields are empty, even when you filled the fields in with data, so it shouldn't give this error.
The code:
<html>
<head>
<title>Music Database</title>
<link rel="stylesheet" href="layout.css" type="text/css" />
<?php
// Verbinden met de database //
include('connect.php');
// Registreer data verkrijgen en in variabelen zetten //
if(isset($_POST['r_submit'])){
$r_username = $_POST['r_username'];
$r_password = $_POST['r_password'];
$confirm_r_password = $_POST['confirm_r_password'];
$r_name = $_POST['r_name'];
$r_surname = $_POST['r_surname'];
$r_birth = $_POST['r_dateofbirth'];
$r_mail = $_POST['r_mail'];
}
?>
</head>
<body>
<div id="login">
<form name="login" action="login.php" method="post">
<p>Login: <input class="input" type="text" name="username" value="Username" />
<input id="password" type="password" name="password" value="Password" /></p>
<div><a class="link" href="register.php">Register here!</a></div>
<p align="center"><input class="submit" type="submit" name="login_submit" value="Submit" /></p>
</form>
</div>
<div id="header">
<a class="link" href="index.php">Music Database</a>
</div>
<div id="search">
<form name="search" action="search.php" method="post">
<p>Search for: <input class="input" type="text" name="search" value="<?php if(isset($_POST['search'])) print $_POST['search']; ?>" />
<input class="submit" type="submit" name="search_submit" value="Submit" /></p>
<p>Artist: <input type="checkbox" name="artistsearch" checked />
Album: <input type="checkbox" name="albumsearch" />
Song: <input type="checkbox" name="songsearch" />
Genre: <input type="checkbox" name="genresearch" /></p>
</form>
</div>
<div id="wrapper"><br /></div>
<div id="content">
<h1>Register down here please:</h1>
<table id="wrap_table">
<tr>
<td>
<div id="reg_content">
<div id="reg_form">
<form name="register_login" action="register.php" method="post">
<fieldset>
<legend>Login Data: </legend>
<table class="r_table">
<tr>
<td>Username<sup>*</sup>: </td>
<td><input class="input" type="text" name="r_username" value="<?php if(isset($r_username)){ print $_POST['r_username']; } ?>"/></td>
<?php
if(isset($_POST['r_submit'])){
if(!isset($r_username)){
echo "<td>Error: No Username has been entered!</td>";
}
}
?>
</tr>
<tr>
<td>Password<sup>*</sup>: </td>
<td><input class="input" type="password" name="r_password" value="<?php if(isset($r_password)){ print $_POST['r_password']; } ?>"/></td>
<?php
if(isset($_POST['r_submit'])){
if(!isset($r_password)){
echo "<td>Error: No Password has been entered!</td>";
}
}
?>
</tr>
<tr>
<td>Confirm Password<sup>*</sup>: </td>
<td><input class="input" type="password" name="confirm_r_password" value="<?php if(isset($confirm_r_password)){ print $_POST['confirm_r_password']; } ?>"/></td>
<?php
if(isset($confirm_password)){
if($confirm_r_password != $r_password){
echo "<td>Error: The passwords don't match!</td>";
}
}
?>
</tr>
</table>
</fieldset>
</form>
</div>
</td>
<td>
<div id="reg_form">
<form name="register_personal" action="register.php" method="post">
<fieldset>
<legend>Personal Data: </legend>
<table class="r_table_personal">
<tr>
<td>Name: </td>
<td><input class="input" type="text" name="r_name" value=""/></td>
</tr>
<tr>
<td>Surname: </td>
<td><input class="input" type="text" name="r_surname" value=""/></td>
</tr>
<tr>
<td>Date of Birth: </td>
<td><input class="input" type="text" name="r_dateofbirth" value=""/></td>
</tr>
<tr>
<td>E-mail<sup>*</sup>: </td>
<td><input class="input" type="text" name="r_mail" value="<?php if(isset($r_mail)){ print $_POST['r_mail']; } ?>"/></td>
<?php
if(isset($_POST['r_submit'])){
if(!isset($r_mail)){
echo "<td>Error: No E-mail has been entered!</td>";
}
}
?>
</tr>
</table>
</fieldset>
</form>
</div>
</div>
</td>
</tr>
<tr>
<td>Fields with an asterisk<sup>*</sup> are required for registry!
<div id="reg_content">
<form name="submit_registry" action="register.php" method="post">
<input class="submit" type="submit" name="r_submit" value="Submit!" />
</form>
</div>
</td>
</tr>
</table>
</div>
<div id="footerbreak"><br /></div>
<div id="footer"> © Jorik ter Molen & Camiel Collet, 2011.</div>
</body>
do you have your <form action="" method="post"> in there?
you can also debug your $_POST global to see whats happening (if data is hitting your script)
var_dump($_POST);
So you include the first "form" page in the second php file after the code right?
First of all in the PHP file you should add all the
if(isset($_POST['submit'])){
segments into one:
if(isset($_POST['submit'])){
$r_username = $_POST['r_username'];
$r_password = $_POST['r_password'];
$confirm_r_password = $_POST['confirm_r_password'];
$r_name = $_POST['r_name'];
$r_surname = $_POST['r_surname'];
$r_birth = $_POST['r_dateofbirth'];
$r_mail = $_POST['r_mail'];
}
Your problem is most probably in $_POST['submit'] since you have two checks, one for $_POST['submit'] and another for $_POST['r_submit']
Unless you send it both ways i suggest you change the PHP file to check for 'r_submit'
Update:
Try putting the form inside the register.php page so it looks like this:
<?php
if(isset($_POST['r_submit'])){
$r_username = $_POST['r_username'];
$r_password = $_POST['r_password'];
$confirm_r_password = $_POST['confirm_r_password'];
}
?>
<form action="register.php" method="post">
<td>Username<sup>*</sup>: </td>
<td><input class="input" type="text" name="r_username" value="<?php if(isset($r_username)){ print $_POST['r_username']; } ?>"/></td>
<?php
if(isset($_POST['r_submit'])){
if(!isset($r_username)){
echo "<td>Error: No Username has been entered!</td>";
}
}
?>
</tr>
<tr>
<td>Password<sup>*</sup>: </td>
<td><input class="input" type="password" name="r_password" value="<?php if(isset($r_password)){ print $_POST['r_password']; } ?>"/></td>
<?php
if(isset($_POST['r_submit'])){
if(!isset($r_password)){
echo "<td>Error: No Password has been entered!</td>";
}
}
?>
</tr>
<tr>
<td>Confirm Password<sup>*</sup>: </td>
<td><input class="input" type="password" name="confirm_r_password" value="<?php if(isset($confirm_r_password)){ print $_POST['confirm_r_password']; } ?>"/></td>
<?php
if(isset($confirm_password)){
if($confirm_r_password != $r_password){
echo "<td>Error: The passwords don't match!</td>";
}
}
?>
</tr>
<input name="r_submit" type="submit" value="Submit" />
</form>
Solution:
<html>
<head>
<title>Music Database</title>
<link rel="stylesheet" href="layout.css" type="text/css" />
<?php
// Verbinden met de database //
include('connect.php');
// Registreer data verkrijgen en in variabelen zetten //
if(isset($_POST['r_submit'])){
$r_username = $_POST['r_username'];
$r_password = $_POST['r_password'];
$confirm_r_password = $_POST['confirm_r_password'];
$r_name = $_POST['r_name'];
$r_surname = $_POST['r_surname'];
$r_birth = $_POST['r_dateofbirth'];
$r_mail = $_POST['r_mail'];
}
?>
</head>
<body>
<div id="login">
<form name="login" action="login.php" method="post">
<p>Login: <input class="input" type="text" name="username" value="Username" />
<input id="password" type="password" name="password" value="Password" /></p>
<div><a class="link" href="register.php">Register here!</a></div>
<p align="center"><input class="submit" type="submit" name="login_submit" value="Submit" /></p>
</form>
</div>
<div id="header">
<a class="link" href="index.php">Music Database</a>
</div>
<div id="search">
<form name="search" action="search.php" method="post">
<p>Search for: <input class="input" type="text" name="search" value="<?php if(isset($_POST['search'])) print $_POST['search']; ?>" />
<input class="submit" type="submit" name="search_submit" value="Submit" /></p>
<p>Artist: <input type="checkbox" name="artistsearch" checked />
Album: <input type="checkbox" name="albumsearch" />
Song: <input type="checkbox" name="songsearch" />
Genre: <input type="checkbox" name="genresearch" /></p>
</form>
</div>
<div id="wrapper"><br /></div>
<div id="content">
<h1>Register down here please:</h1>
<table id="wrap_table">
<tr>
<td>
<div id="reg_content">
<div id="reg_form">
<form name="register_login" action="register.php" method="post">
<fieldset>
<legend>Login Data: </legend>
<table class="r_table">
<tr>
<td>Username<sup>*</sup>: </td>
<td><input class="input" type="text" name="r_username" value="<?php if(isset($r_username)){ print $_POST['r_username']; } ?>"/></td>
<?php
if(isset($_POST['r_submit'])){
if(!isset($r_username)){
echo "<td>Error: No Username has been entered!</td>";
}
}
?>
</tr>
<tr>
<td>Password<sup>*</sup>: </td>
<td><input class="input" type="password" name="r_password" value="<?php if(isset($r_password)){ print $_POST['r_password']; } ?>"/></td>
<?php
if(isset($_POST['r_submit'])){
if(!isset($r_password)){
echo "<td>Error: No Password has been entered!</td>";
}
}
?>
</tr>
<tr>
<td>Confirm Password<sup>*</sup>: </td>
<td><input class="input" type="password" name="confirm_r_password" value="<?php if(isset($confirm_r_password)){ print $_POST['confirm_r_password']; } ?>"/></td>
<?php
if(isset($confirm_password)){
if($confirm_r_password != $r_password){
echo "<td>Error: The passwords don't match!</td>";
}
}
?>
</tr>
</table>
</fieldset>
</div>
</td>
<td>
<div id="reg_form">
<fieldset>
<legend>Personal Data: </legend>
<table class="r_table_personal">
<tr>
<td>Name: </td>
<td><input class="input" type="text" name="r_name" value=""/></td>
</tr>
<tr>
<td>Surname: </td>
<td><input class="input" type="text" name="r_surname" value=""/></td>
</tr>
<tr>
<td>Date of Birth: </td>
<td><input class="input" type="text" name="r_dateofbirth" value=""/></td>
</tr>
<tr>
<td>E-mail<sup>*</sup>: </td>
<td><input class="input" type="text" name="r_mail" value="<?php if(isset($r_mail)){ print $_POST['r_mail']; } ?>"/></td>
<?php
if(isset($_POST['r_submit'])){
if(!isset($r_mail)){
echo "<td>Error: No E-mail has been entered!</td>";
}
}
?>
</tr>
</table>
</fieldset>
</div>
</div>
</td>
</tr>
<tr>
<td>Fields with an asterisk<sup>*</sup> are required for registry!
<div id="reg_content">
<input class="submit" type="submit" name="r_submit" value="Submit!" />
</div>
</form>
</td>
</tr>
</table>
</div>
<div id="footerbreak"><br /></div>
<div id="footer"> © Jorik ter Molen & Camiel Collet, 2011.</div>
</body>
Around line 82 where you have the php check for the matching passwords, replace it with:
<?php
if(isset($_POST['r_submit'])){
if($confirm_r_password != $r_password)
{
echo "<td>Error: The passwords don't match!</td>";
}
}
?>
Although this is just a basic check and nothing secure since the user can leave both passwords empty and they still match.

PHP Uploaded Filename not printing

This is simple and should work but doesn't, so I'm obviously derping pretty hard somewhere. The uploaded file name should print after form submission.
<?php
if (isset($_POST["submit"])) {
$name_of_uploaded_file = $_FILES['uploaded_file1']['name'];
print($name_of_uploaded_file);
}
?>
<form id="contactform" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<table>
<tr>
<td>
<table>
<tr>
<td>
Attach Logo:
</td>
<td>
<input type="file" id="uploaded_file1" name="uploaded_file1" />
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td>
<input name="submit" id="submit" type="submit" value="Send" />
</td>
</tr>
</table>
</form>
You need the content encoding type set on your form open tag.
<form enctype="multipart/form-data" action="uploader.php" method="POST">

Categories