Bootstrap form does not send file name - php

I have wrote a form in bannervipsites.php :
<form role="form" action="index.php" method ="post">
<div class="form-group">
<label>نام بنر :</label>
<input class="form-control" name="sname" placeholder="نام فارسی یا لاتین بنر">
</div>
<div class="form-group">
<label>URL : </label>
<input class="form-control" name="surl" placeholder="http://">
</div>
<div class="form-group">
<label>Upload banner :</label>
<input type="file" name='upfile' id='upfile' class="filestyle" data-buttonName="btn-primary" data-buttonBefore="true" data-icon="false" >
<input type='hidden' name='bform' value='file'>
<input type='hidden' name='MAX_FILE_SIZE' value='100720'>
</div>
<?php
if ($acctype != 1) {
?>
<div class="form-group">
<label>حداکثر بازدید در ساعت : (عدد 0 یعنی نامحدود)</label>
<input class="form-control" name="scph" placeholder="سقف بازدید در ساعت از چه عددی فراتر نرود؟">
</div>
<?php
}
?>
<div class="form-group">
<label>روی مربع کلیک کنید : </label>
<div class="g-recaptcha"></div>
</div>
<input type="hidden" name="fform" value="bannervip">
<input type="hidden" name="sid" value="0">
<input id="submit" name="submit" value="اضافه کردن" class="btn btn-success" type="submit">
<button type="button" class="btn btn-default" data-dismiss="modal">بستن</button>
</form>
and then post it to index.php
but upfile (the name of uploaded file) does not send.
I can not get
echo $_FILES['upfile']['tmp_name'];
in index.php
what is the problem? it's very odd for me.
it was working in last template .(index.php is ok i'm sure)
what is wrong with bootstrap form

Add
enctype= "multipart/form-data"
to your form.

Related

PHP : Echo not working on POST method from form

I am a bit new to PHP and I'm having a bit of difficulties here and there. I am developing a form and wish to display an error box if any of the fields are empty when the 'Submit' Button is pressed. I've tried the following code but the echo is still not appearing. Any suggestions ?
Form Code:
<div style="padding-top:40px">
<div style="text-center; padding-right:25%; padding-left:25%">
<div class="form-area">
<form role="form" method="$_POST" action="searchEmployee.php">
<br style="clear:both">
<h3 style="margin-bottom:25px; text-align: center;">Visitor Form</h3>
<div class="form-group">
<label>Name:</label>
<input type="text" class="form-control" id="name" name="name" placeholder="Name" required>
</div>
<div class="form-group">
<label>Surname:</label>
<input type="text" class="form-control" id="surname" name="surname" placeholder="Surname" required>
</div>
<div class="form-group">
<label>ID Card:</label>
<input type="text" class="form-control" id="idCard" name="idCard" placeholder="ID Card No" required>
</div>
<div class="form-group">
<label>Visitor Card Number:</label>
<input type="text" class="form-control" id="cardNumber" name="cardNumber" placeholder="Card No" required>
</div>
<div class="form-group">
<intput type="button" id="submit" name="submit" class="btn btn-primary pull-right">Sign In Visitor</button>
</div>
</form>
</div>
</div>
</div>
PHP Code:
<?php
if (isset($_POST['submit'])) {
$required = array('name', 'surname', 'ID', 'visitorCard');
// Loop over field names, make sure each one exists and is not empty
$error = false;
foreach($required as $field) {
if (empty($_POST[$field])) {
$error = true;
}
}
if ($error) {
echo "All fields are required.";
}
}
?>
You are using method as $_POST in your form attribute,
It should be only POST.
So, replace your form line with,
<form role="form" method="POST" action="searchEmployee.php">
and also, change Submit button line to,
<input type="submit" name="submit" value="Sign In Visitor" class="btn btn-primary pull-right" />
Here are few mistakes:
You are using method as $_POST in your form attribute, It should be only POST.
Your form will not submit because your button is not a submit type. it should
<input type="submit" id="submit" name="submit" class="btn btn-primary pull-right" value="Sign In Visitor" />
Or
<button type="submit" id="submit" name="submit" class="btn btn-primary pull-right">Sign In Visitor</button>
You need to make 2 change as below
Change button type like this
<input type="submit" id="submit" name="submit" class="btn btn-primary pull-right" value="Sign In Visitor">
Change Form method
<form role="form" method="POST" action="searchEmployee.php">
Change this
<intput type="button" id="submit" name="submit" class="btn btn-primary pull-right">Sign In Visitor</button>
To
<input type="button" id="submit" name="submit" value="submit" class="btn btn-primary pull-right" />Sign In Visitor
and Also
this
<form role="form" method="$_POST" action="searchEmployee.php">
To
<form role="form" method="POST" action="searchEmployee.php">
How will you get POST['submit'] value when you have not even set, that means your if code won't execute it and so it won't echo or alert it.
For Best practice of debugging always try to do this whenever such instances occurs while coding.
print_r($_POST);
This will show you an array of POST variables
change $_POST to POST and put <input type="submit" instead of <input type = "button"
<div style="padding-top:40px">
<div style="text-center; padding-right:25%; padding-left:25%">
<div class="form-area">
<form role="form" method="post" action="searchEmployee.php"> <br style="clear:both"> <h3 style="margin-bottom:25px; text-align: center;">Visitor Form</h3> <div class="form-group"> <label>Name:</label>
<input type="text" class="form-control" id="name" name="name" placeholder="Name" required> </div>
<div class="form-group"> <label>Surname:</label>
<input type="text" class="form-control" id="surname" name="surname" placeholder="Surname" required> </div> <div class="form-group"> <label>ID Card:</label>
<input type="text" class="form-control" id="idCard" name="idCard" placeholder="ID Card No" required>
</div>
<div class="form-group">
<label>Visitor Card Number:</label> <input type="text" class="form-control" id="cardNumber" name="cardNumber" placeholder="Card No" required>
</div> <div class="form-group">
<input type="submit" id="submit" name="submit" class="btn btn-primary pull-right" value="Sign In Visitor">
</div> </form> </div>
</div> </div>
Php Code:::searchEmployee.php
<?php if (isset($_POST['submit'])) { $required = array('name', 'surname', 'idCard', 'cardNumber');
// Loop over field names, make sure each one exists and is not empty
$error = false;
foreach($required as $field) { if (!isset($_POST[$field])) {
$error = true;
} }
if ($error) {
echo "All fields are required."; } }
?>
First think change button type="submit".
Second think change PHP array
$required = array('name', 'surname', 'idCard', 'cardNumber');

Submit button is not working in my form

This is my form. When I click save, vales are not getting posted and redirected to note.php page.
<form method="post" action="note.php" enctype="multipart/form-data">
<div class="form-group">
<div class="col-sm-1 padding">
<label>Title :</label>
</div>
<div class="col-sm-11 padding">
<input type="text" class="form-control select2-offscreen form-text" name="title" required autocomplete="off" placeholder="Note Heading" tabindex="-1">
</div>
</div>
<div class="toolbar-btns">
<div class="file-attach">
<div class="form-group">
<input type="file" name="file[]" multiple="multiple">
</div>
</div>
<div class="form-group">
<button type="submit" class="btn send-btn" name="btn-note-save">Save</button>
<input type="reset" style="background-color:#417fb9; color:#fff;" class="btn btn-default" id="submitForm" value="Clear"></input>
</div>
</div>
</form>
I think your problem is in note.php. Please use the code below to get the posted values.
<?php
$title=($_POST['title']);
echo $title;
$pic = $_FILES["file"]["name"];
$folder = "../images/users/";
move_uploaded_file($_FILES['file']["tmp_name"], "$folder".$pic);
?>

Submit button has to be in the same form as email/pw field?

I´m quite new to php so this might just be a stupid question. Is there a way to put the submit button into another form field, or must it be the same? Does it really matter if I create a new field somewhere else?
Not working Code:
<div class="container">
<form method="post">
<div class="form-group">
<input type="text" class="form-control" name="emailfield" id="emailfeld2" placeholder="Emailadresse (z.B Max#Max.de)">
<input type="password" class="form-control" name="passwordfield" id="passwortfeld" placeholder="Passwort">
<input type="password" class="form-control" name="cpasswordfield" id="cpasswortfeld" placeholder="Passwort bestätigen">
</div>
</form>
<div class="form-group">
<form method="post">
<button type="submit" class="btn btn-success" name="submitgo">Sign Up!</button>
</form>
</div>
</div>
<?php
echo $_POST['emailfield']."<br>";
?>
<div class="container-opacity">
</div>
Working code:
<div class="container">
<form method="post">
<div class="form-group">
<input type="text" class="form-control" name="emailfield" id="emailfeld2" placeholder="Emailadresse (z.B Max#Max.de)">
<input type="password" class="form-control" name="passwordfield" id="passwortfeld" placeholder="Passwort">
<input type="password" class="form-control" name="cpasswordfield" id="cpasswortfeld" placeholder="Passwort bestätigen">
<button type="submit" class="btn btn-success" name="submitgo">Sign Up!</button>
</div>
</form>
</div>
<?php
echo $_POST['emailfield']."<br>";
?>
<div class="container-opacity">
</div>
It is generally bad practice to have form elements outside of the form they belong to. It will work if you only have one <form> tag and move it outside of you main <div class="container">
<form method="post">
<div class="container">
<div class="form-group">
<input type="text" class="form-control" name="emailfield" id="emailfeld2" placeholder="Emailadresse (z.B Max#Max.de)">
<input type="password" class="form-control" name="passwordfield" id="passwortfeld" placeholder="Passwort">
<input type="password" class="form-control" name="cpasswordfield" id="cpasswortfeld" placeholder="Passwort bestätigen">
</div>
<div class="form-group">
<button type="submit" class="btn btn-success" name="submitgo">Sign Up!</button>
</div>
</div>
</form>
<?php echo $_POST[ 'emailfield']. "<br>"; ?>
<div class="container-opacity">
</div>

How send data one page to another page after clicking submit button

i Have a one problem want to share with all of you.
I am develop a custom page in WordPress here is the link of the page http://muhammadimran.info/testing/ when i try to click on new document button and try to submit form it give me error. Here is my code for this please tell me how i can give link in WordPress in action
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Modal Header</h4>
</div>
<div class="modal-body">
<form action="home1.php" enctype="multipart/form-data" method="POST">
<div class="form-group">
<label for="name1">Name</label>
<input name="name" class="form-control" type="text" />
</div>
<div class="form-group">
<label for="title">Title</label>
<input name="title" class="form-control" type="text" />
</div>
<div class="form-group">
<label for="Startdate">Start Date</label>
<input id="datepicker" class="form-control" class="datepicker" type="text" name="start" required="" />
</div>
<div class="form-group">
<label for="Enddate">End Date</label>
<input id="datepicker1" class="form-control" class="datepicker" type="text" name="end" required="" />
</div>
<div class="form-group">
<label for="Users">Users</label>
<input type="text" class="form-control" name="users" />
</div>
<div class="form-group">
<label for="Fileupload">File Upload</label>
<input type="file" class="form-control" name="file" class="file" name="file" required="">
</div>
<input type="submit" id="submit" class="btn btn-primary submitbutton" name="submit">
</form>
</div>
</div>
You should follow the beloe steps:
create a Template:
Home1 Template with file name home1.php
create a page and select the recently create template (Home1 Template).
replace the form action
<form action="home1.php" enctype="multipart/form-data" method="POST">
with
<form action="http://siteur/templateur/" enctype="multipart/form-data" method="POST">
in home1.php
print_r($_POST);

$_POST not being read

i have a form which inserts book information into the database. however it is not reading the $_POST attribute.
book.php:
<form action="books_manage.php" id="addbook_form" method="post">
<div id="ab_wrapper">
<div id="ab_leftcolumn">
<div id="bookinfo">
<fieldset>
<legend>Book Details</legend>
<div class="field">
<label>Book ID</label>
<input type="text" name="bid" id="bid"/>
</div>
<div class="field">
<label>Name</label>
<input type="text" name="bname" id="bname"/>
</div>
<div class="field">
<label>Author</label>
<input type="text" name="bauthor" id="bauthor"/>
</div>
<div class="field">
<label>Info</label>
<textarea name="binfo" id="binfo" cols="5" rows="5" ></textarea>
</div>
<div class="field">
<label>Date Added</label>
<input type="text" value="<?php echo date('D d M Y')?>" name="bdateadd" id="bdateadd"/>
</div>
<div class="field">
<label>Date Updated</label>
<input type="text" value="<?php echo date("D d M Y")?>" name="bdateupd" id="bdateupd"/>
</div>
<div>
<input type="hidden" name="action" value="save">
<input type="submit" value="Save">
<input type="button" id="addcontent" value="Add Content">
<input type="reset" value="Reset">
</div>
</fieldset>
</div>
</div>
<div id="ab_rightcolumn">
<div id="bookcontents">
<fieldset>
<legend>Book Content</legend>
<div class="field">
<label>Chapter</label>
<input type="text" id="bchapter" name="bchapter"/>
</div>
<div class="field">
<label>Sub-Chapter</label>
<input type="text" id="bsubchapter" name="bsubchapter"/>
</div>
<div class="field">
<label>Content</label>
<textarea id="bcontent" name="bcontent" rows="6" cols="8"></textarea>
</div>
<br />
<div>
<input type="hidden" name="action" value="addnext">
<input type="submit" value="Save and Add Next Chapter">
<input type="submit" name="action" value="Done">
</div>
</fieldset>
</div>
</div>
</div>
</form>
books_manage.php:
<?php
if (isset($_POST['action']) && $_POST['action'] == 'save')
{
echo "You clicked the save button";
}
else {
echo "Hello. The date is " . date("D d M Y") ;
}
?>
the output:
Hello. The date is Thu 08 Jul 2010
it seems it isn't reading the value of the hidden button. it should display "You clicked the save button". Am I missing something?
First of all, multiple <input>s in the same <form> with the same name attribute isn't going to get you the behavior you're looking for.
Instead, you need to provide a name to the submit buttons, and then you can check which button was pressed:
<input type="submit" name="save" value="Add Content">
<input type="submit" name="done" value="No more content">
<?php
if(isset($_POST['save'])) {
echo "saved";
} else if(isset($_POST['done'])) {
echo "done";
}
?>
See comment below by Lèse majesté to learn how the HTML working group effed this one up.
You have two inputs with the name "action" in the same form. Make sure your form field names are unique.
Don't forget you can organise your names using this syntax -
<input name="form1['name']" value="".....
<input name="form2['name']" ..... etc
Then access these variables like this:
$_POST['form1']['name']...
Very useful!
Its becuase you have defined action 3 times
<input type="hidden" name="action" value="save">
<input type="hidden" name="action" value="addnext">
<input type="submit" name="action" value="Done">
Do the followin on your books_manage.php
echo "<pre>";
print_r($_POST);
echo "</pre>";
You will see where you are going wrong.
<input type="hidden" name="action" value="addnext">
<input type="submit" value="Save and Add Next Chapter">
<input type="submit" name="action" value="Done">
you have two inputs with name "action". the action you get is probably "Done", not "save"
You have multiple inputs named action you will get
<input type="hidden" name="action" value="save">
<input type="hidden" name="action" value="addnext">
<input type="submit" name="action" value="Done">
You need to remove the hidden variables and change the name of your first 'submit' to 'action'
<input type="submit" name="action" value="Save">
<input type="submit" name="action" value="Done">
You need to name your submit button "action" and use the value of that button to determine the action. Your code basically has two action form values and the last one is what takes precedence.
<form action="books_manage.php" id="addbook_form" method="post">
<div id="ab_wrapper">
<div id="ab_leftcolumn">
<div id="bookinfo">
<fieldset>
<legend>Book Details</legend>
<div class="field">
<label>Book ID</label>
<input type="text" name="bid" id="bid"/>
</div>
<div class="field">
<label>Name</label>
<input type="text" name="bname" id="bname"/>
</div>
<div class="field">
<label>Author</label>
<input type="text" name="bauthor" id="bauthor"/>
</div>
<div class="field">
<label>Info</label>
<textarea name="binfo" id="binfo" cols="5" rows="5" ></textarea>
</div>
<div class="field">
<label>Date Added</label>
<input type="text" value="<?php echo date('D d M Y')?>" name="bdateadd" id="bdateadd"/>
</div>
<div class="field">
<label>Date Updated</label>
<input type="text" value="<?php echo date("D d M Y")?>" name="bdateupd" id="bdateupd"/>
</div>
<div>
<input type="submit" name="action" value="Save">
<input type="button" id="addcontent" value="Add Content">
<input type="reset" value="Reset">
</div>
</fieldset>
</div>
</div>
<div id="ab_rightcolumn">
<div id="bookcontents">
<fieldset>
<legend>Book Content</legend>
<div class="field">
<label>Chapter</label>
<input type="text" id="bchapter" name="bchapter"/>
</div>
<div class="field">
<label>Sub-Chapter</label>
<input type="text" id="bsubchapter" name="bsubchapter"/>
</div>
<div class="field">
<label>Content</label>
<textarea id="bcontent" name="bcontent" rows="6" cols="8"></textarea>
</div>
<br />
<div>
<input type="submit" name="action" value="Save and Add Next Chapter">
<input type="submit" name="action" value="Done">
</div>
</fieldset>
</div>
</div>
</div>
<?php
if (isset($_POST['action']) && $_POST['action'] == 'Save')
{
echo "You clicked the save button";
}
else if (isset($_POST['action']) && $_POST['action'] == 'Save and Add Next Chapter')
{
echo 'You clicked the "Save and Add Next Chapter" button';
}
else if (isset($_POST['action']) && $_POST['action'] == 'Done')
{
echo 'You clicked the done button';
}
else
{
echo "Hello. The date is " . date("D d M Y") ;
}
?>

Categories