Force user to pick at least one checkbox - Laravel - php

How to validate if user has picked at least one checkbox by validating on the server side in Laravel 5.2
I have a simple select box:
<label for="has_driverslicense">KFZ Führerschein: </label>
<select class="form-control" required="required" id="has_driverslicense" name="has_driverslicense">
<option value="0">Nein</option>
<option value="1">Ja</option>
</select>
and a hidden div:
<div id="kfz" style="display: none;">
<div>
<input id="checkbox-20" class="checkbox-style" name="B" type="checkbox">
<label for="checkbox-20" class="checkbox-style-3-label">B (Auto bis 3,49t)</label>
</div>
<div>
<input id="checkbox-21" class="checkbox-style" name="B+E" type="checkbox">
<label for="checkbox-21" class="checkbox-style-3-label">BE (Auto mit Anhänger)</label>
</div>
<div>
<input id="checkbox-22" class="checkbox-style" name="C1" type="checkbox">
<label for="checkbox-22" class="checkbox-style-3-label">C1 (LKW bis 7,49t)</label>
</div>
<div>
<input id="checkbox-23" class="checkbox-style" name="C" type="checkbox">
<label for="checkbox-23" class="checkbox-style-3-label">C (LKW bis 40t)</label>
</div>
<div>
<input id="checkbox-24" class="checkbox-style" name="CE" type="checkbox">
<label for="checkbox-24" class="checkbox-style-3-label">CE (LKW mit Anhänger)</label>
</div>
<div>
<input id="checkbox-25" class="checkbox-style" name="fahrerkarte" type="checkbox">
<label for="checkbox-25" class="checkbox-style-3-label">Fahrerkarte</label>
</div>
<div>
<input id="checkbox-26" class="checkbox-style" name="gabelstapler" type="checkbox">
<label for="checkbox-26" class="checkbox-style-3-label">Gabelstaplerführerschein</label>
</div>
<div>
<input id="checkbox-27" class="checkbox-style" name="gelaendestapler" type="checkbox">
<label for="checkbox-27" class="checkbox-style-3-label">Geländestaplerführerschein</label>
</div>
<div>
<input id="checkbox-28" class="checkbox-style" name="IPAF" type="checkbox">
<label for="checkbox-28" class="checkbox-style-3-label">IPAF – Arbeitsbühnen</label>
</div>
</div>
When user chooses yes/ja he should choose which category does he have.
At the moment all works but i can get a user with driving licence but no category and that is baaaad! :) If you know what i mean!
Help please.
Here is the FIDDLE example

You need to name all of your checkboxes with the same name attribute, ie name="license_type" and you can then switch their names to value ie value="B".
Once this is done in your validation rules you would set.
'license_type' => 'required_if:has_driverslicense,1'

Related

Empty / Null Return Value from Bootstrap Radio Button Group Selection

Would appreciate someone explaining to me why I only get an empty string back from PHP when trying to get radio-button group selection.
$currentlyemployed = null;
if (isset($currentlyemployedyes)) {
$currentlyemployed = "Yes";
}
else {
$currentlyemployed = "No";
}
NOTE: text inputs within the same form post and I can get their values.
Example snippets:
START FORM MARKUP
<div class="row">
<div class="col-sm-6 text-left">
<h5>Are you currently employed?</h5>
<div class="control-group">
<div class="controls">
<label>
<input type="radio" id="currentlyemployedyes" name="currentlyemployed" value="yes" />Yes</label>
<label>
<input type="radio" id="currentlyemployedno" name="currentlyemployed" value="no" />No</label>
<p class="help-block"></p>
</div>
</div>
</div>
</div>
END FORM MARKUP
START PHP CODE SNIPPET
$currentlyemployed = $_POST['currentlyemployed']; RETURNS empty string
/* FYI
$currentlyemployedyes = $_POST['currentlyemployedyes']; RETURNS "Yes"
$currentlyemployedno = $_POST['currentlyemployedno']; RETURNS "No"
*/
END PHP CODE SNIPPET
The code you have written works as expected. You can check out the snippet below.
Bootstrap or not it does not matter. The name="currentlyemployed" sent from the form to php server and then php binds it into $_POST associative global array.
<?php
echo "<pre>";
var_dump($_POST);
echo "</pre>";
echo "Currently Employed: ".$_POST['currentlyemployed'];
?>
<hr>
<div class="row">
<div class="col-sm-6 text-left">
<form method="POST">
<h5>Are you currently employed?</h5>
<div class="control-group">
<div class="controls">
<label>
<input type="radio" id="currentlyemployedyes" name="currentlyemployed" value="yes" />Yes</label>
<label>
<input type="radio" id="currentlyemployedno" name="currentlyemployed" value="no" />No</label>
<p class="help-block"></p>
</div>
</div>
<input type="submit">
</form>
</div>
</div>
I don't consider this a legitimate "answer", but, rather, a "work-around".
Would like to provide attribution, but forget where I found this, might have even been here on stack overflow.
<div class="row">
<div class="col-sm-6 text-left">
<h5>Are you currently employed?</h5>
<div class="control-group">
<div class="controls">
<label>
<input type="radio" id="currentlyemployedyes" name="currentlyemployed" value="yes" **onclick="$('#currentlyemployed').val('Yes');"** />
Yes</label>
<label>
<input type="radio" id="currentlyemployedno" name="currentlyemployed" value="no" **onclick="$('#currentlyemployed').val('No');"** />
No</label>
<p class="help-block"></p>
</div>
**<input name="currentlyemployed" id="currentlyemployed" type="hidden" value="" />**
</div>
</div>
</div>

Duplicate Form using button

I'm trying to duplicate 4 input text. For example I want to duplicate 'Produk Simpanan Saham', then only 4 input on 'Produk Simpanan Saham' div will be duplicated. I already tried a few methods using jQuery but it seem doesn't work.
<form action="" method="post" class="form-horizontal">
<br><br>
<div class="form-group">
Upload File :
<input type="file" name="file">
</div>
<div class="saham">
<div class="w3-container w3-black">
<h3>
<center>Produk Simpanan Saham</center>
</h3>
</div>
<label for="kp_produk">Kode Produk :</label>
<input type="text" name="kp_produk" class="form-control">
<br>
<label for="produk_saham">Produk :</label>
<input type="text" name="produk_saham" class="form-control">
<br>
<label for="bunga_saham">Bunga :</label>
<input type="text" name="bunga_saham" class="form-control">
<br>
<label for="ket_saham">Keterangan :</label>
<input type="text" name="ket_saham" class="form-control">
</div>
<div class="harian">
<div class="w3-container w3-black">
<h3>
<center>Produk Simpanan Harian</center>
</h3>
</div>
<label for="kp_harian">Kode Produk :</label>
<input type="text" name="kp_harian" class="form-control">
<br>
<label for="produk_harian">Produk :</label>
<input type="text" name="produk_harian" class="form-control">
<br>
<label for="bunga_harian">Bunga :</label>
<input type="text" name="bunga_harian" class="form-control">
<br>
<label for="ket_harian">Keterangan :</label>
<input type="text" name="ket_harian" class="form-control">
</div>
you mush have blueprint of field first like
var blueprint= '<div class="saham">'+
'<div class="w3-container w3-black">'+
'<h3>'+
'<center>Produk Simpanan Saham</center>'+
'</h3>'+
'</div>'+
'<label for="kp_produk">Kode Produk :</label>'+
'<input type="text" name="kp_produk[]" class="form-control">'+
'<br>'+
......
used [] for all name field to get array request when you send form to server
example :
'<input type="text" name="kp_produk[]" class="form-control">'+
and make button add like (jquery) example
<button onclick="$('form').append(blueprint)">add</button>
just use
var dom=$($('.saham')[0]).clone();
//copy dom
$('.form-horizontal').html(dom):
//paste dom
dont forget to add [] on name tag dom input to set data send to array, because if you not set. data with key kp_produk value is last tag name with name kp_produk
if you use [] (kp_product[]) data will set to array
kp_product=['anu1',anu2];

HTML form not posting data into MySQL database via PHP processor

Context:
I'm working with the following stack: HTML/CSS, PHP, MySQL to build a web app that stores and retrieves data entered to a form.
Problem:
When I enter data into the form (the html part of index.php) locally it is not actually POSTing that data into the mysql database I have setup and is throwing an error saying there is an unknown column.
I think that the problem is in the inserting values part. If anyone has any idea as to why it's not posting I would love any help I can get. Thanks for your time!
Pics:
Code:
index.php
<?php
include("dbconfig.php");
try {
/* connect with credentials held in dbconfig file */
$conn = new PDO("mysql:host=$server;dbname=$db", $user, $pass);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
echo "Successfully Connected!";
/* input sanitization */
$title = htmlspecialchars($_POST['title']);
$overview = htmlspecialchars($_POST['overview']);
$threat_details = htmlspecialchars($_POST['threat_details']);
$cust_name = htmlspecialchars($_POST['cust_name']);
$fld_insight = htmlspecialchars($_POST['fld_insight']);
$competitor = htmlspecialchars($_POST['competitor']);
$id = htmlspecialchars($_POST['id']);
$rev_damage = htmlspecialchars($_POST['rev_damage']);
echo "data sanitized";
/* submits data IF the submit button is pressed */
if(isset($_POST['submit'])) {
/* insert the values passed into the html form into mysql database */
$sql = "INSERT INTO comp (title, overview, threat_details, cust_name, fld_insight, competitor, id, rev_damage) VALUES ('titleBinded', 'overviewBinded', 'threatDetailsBinded', 'customerNameBinded', 'fieldInsightBinded', 'competitorBinded', 'idBinded', 'revDamageBinded')";
$sqlPrepared = $conn->prepare($sql);
$sqlPrepared->bindParam(':titleBinded',$title);
$sqlPrepared->bindParam(':overviewBinded',$overview);
$sqlPrepared->bindParam(':threatDetailsBinded',$threat_details);
$sqlPrepared->bindParam(':customerNameBinded',$cust_name);
$sqlPrepared->bindParam(':fieldInsightBinded',$fld_insight);
$sqlPrepared->bindParam(':competitorBinded',$competitor);
$sqlPrepared->bindParam(':idBinded',$id);
$sqlPrepared->bindParam(':revDamageBinded',$rev_damage);
$sqlPrepared->execute();
echo "Successfully Inserted!";
}
/* commit the transaction */
if (!$conn->commit()) {
print("Commit failed\n");
exit();
}
/* close connection */
$conn->close();
}
catch(PDOException $e) {
echo "Connection failed: " . $e->getMessage();
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css">
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Raleway">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<div class="form-style-2-heading">Create New Competitor</div>
<style>
html,body,h1,h2,h3,h4,h5 {font-family: "Raleway", sans-serif}
</style>
<body class="blue">
</head>
<body>
<!-- Top container -->
<div class="w3-bar w3-top w3-blue w3-large" style="z-index:4">
<span class="w3-bar-item w3-center">Create New Competitor</span>
</div>
<div class="w3-main" style="margin-left:300px;margin-top:43px;">
<!-- SUBMIT PAGE CONTENT TO DATABASE -->
<form method="POST">
<label id="info">
<span>Opportunity Title<span class="required">*</span></span>
<br>
<input type="text" class="input-field" name="opti"></label>
<br>
<br>
<label id="info">
<span>Opportunity Overview<span class="required">*</span></span>
<br>
<input type="text" class="input-field" name="opov"></label>
<br>
<br>
<label id="info">
<span>Competitive Threat Details<span class="required">*</span></span>
<br>
<input type="text" class="input-field" name="compdet"></label>
<br>
<br>
<label id="info">
<span>Customer Name<span class="required">*</span></span>
<br>
<input type="text" class="input-field" name="custnme"></label>
<br>
<br>
<label id="info">
<span>Field Insight<span class="required">*</span></span>
<br>
<input type="text" class="input-field" name="fldinsght"></label>
<br>
<br>
<label id="info">
<span>Name of Company Competitor<span class="required">*</span></span>
<br>
<input type="text" class="input-field" name="cmpname"</label>
<br>
<br>
<label id="info">
<span>Enter Deal ID<span class="required">*</span></span>
<br>
<input type="text" class="input-field" name="id"</label>
<br>
<br>
<label id="info">
<span>Approx. Revenue Implications<span class="required">*</span></span>
<br>
<input type="text" class="input-field" name="rev"</label>
<br>
<br>
<b>Technologies/Domains Included</b>
<br>
<br>
<label id="container">Tech1
<input type="checkbox" checked="checked">
<span class="checkmark"></span>
</label>
<br>
<label id="container">Tech2
<input type="checkbox">
<span class="checkmark"></span>
</label>
<br>
<label id="container">Tech3
<input type="checkbox">
<span class="checkmark"></span>
</label>
<br>
<label id="container">Tech4
<input type="checkbox">
<span class="checkmark"></span>
</label>
<br>
<label id="container">Tech5
<input type="checkbox">
<span class="checkmark"></span>
</label>
<br>
<label id="container">Tech6
<input type="checkbox">
<span class="checkmark"></span>
</label>
<br>
<label id="container">Tech7
<input type="checkbox">
<span class="checkmark"></span>
</label>
<br>
<br>
<b>Geo/Theatre</b>
<br>
<br>
<label id="container">Geo1
<input type="checkbox" checked="checked">
<span class="checkmark"></span>
</label>
<br>
<label id="container">Geo2
<input type="checkbox">
<span class="checkmark"></span>
</label>
<br>
<label id="container">Geo3
<input type="checkbox">
<span class="checkmark"></span>
</label>
<br>
<label id="container">Geo4
<input type="checkbox">
<span class="checkmark"></span>
</label>
<br>
<label id="container">Geo5
<input type="checkbox">
<span class="checkmark"></span>
</label>
<br>
<label id="container">Geo6
<input type="checkbox">
<span class="checkmark"></span>
</label>
<br>
<label id="container">Geo7
<input type="checkbox">
<span class="checkmark"></span>
</label>
<br>
<label id="container">Geo8
<input type="checkbox">
<span class="checkmark"></span>
</label>
<br>
<label id="container">Geo9
<input type="checkbox">
<span class="checkmark"></span>
</label>
<br>
<label id="container">Geo10
<input type="checkbox">
<span class="checkmark"></span>
</label>
<br>
<label id="container">Geo11
<input type="checkbox">
<span class="checkmark"></span>
</label>
<br>
<label id="container">Geo12
<input type="checkbox">
<span class="checkmark"></span>
</label>
<br>
<label id="container">Geo13
<input type="checkbox">
<span class="checkmark"></span>
</label>
<br>
<label id="container">Geo14
<input type="checkbox">
<span class="checkmark"></span>
</label>
<br>
<label id="container">Geo15
<input type="checkbox">
<span class="checkmark"></span>
</label>
<br>
<label id="container">Geo16
<input type="checkbox">
<span class="checkmark"></span>
</label>
<br>
<br>
<label><span> </span><input type="submit" value="Submit" name="submit" /></label>
</form>
</div>
</html>
create.sql
drop database if exists comp;
create schema comp;
use comp;
create table comp (
titleBinded VARCHAR(50),
overviewBinded VARCHAR(255),
threatDetailsBinded VARCHAR(255),
customerNameBinded VARCHAR(30),
fieldInsightBinded VARCHAR(255),
competitorBinded VARCHAR(30),
idBinded INT,
revDamageBinded INT,
PRIMARY KEY (idBinded)
);
create table technologies (
name VARCHAR(225),
PRIMARY KEY (name)
);
create table geography (
area VARCHAR(255),
PRIMARY KEY (area)
);
Since your create table statement contains the column names, you have to use those in your query:
create table comp (
titleBinded VARCHAR(50),
overviewBinded VARCHAR(255),
threatDetailsBinded VARCHAR(255),
customerNameBinded VARCHAR(30),
fieldInsightBinded VARCHAR(255),
competitorBinded VARCHAR(30),
idBinded INT,
revDamageBinded INT,
PRIMARY KEY (idBinded)
);
The query should look like this:
INSERT INTO comp (titleBinded, overviewBinded, threatDetailsBinded, customerNameBinded ...
etc.
Now, you have a : in your bind statements -
$sqlPrepared->bindParam(':titleBinded',$title);
$sqlPrepared->bindParam(':overviewBinded',$overview);
$sqlPrepared->bindParam(':threatDetailsBinded',$threat_details); ...
etc.
so you should use those in your query too, without quotes:
VALUES (:titleBinded, :overviewBinded, :threatDetailsBinded, :customerNameBinded, :fieldInsightBinded, :competitorBinded, :idBinded, :revDamageBinded)
Because you're binding your variables you can get rid of the lines where you use htmlspecialchars() as this does not sanitize your data, the binding in a prepared statement takes care of it.
In a nutshell
You have to have a form element with a name attribute. From there you can bind that variable when posted to use in the query:
<input type="text" name="this_input_name" />
If using the POST method the variable can be used in the bind like this:
$sqlPrepared->bindParam(':thisBoundName', $_POST['this_input_name']);
Your query would then look something like this:
INSERT INTO `tablename` (`this_column_name`) VALUES (:thisBoundName)
Take note of how the named input this_input_name is used to bind the parameter :thisBoundName and how the parameter is used as the value to be inserted in the column (created at the time the table is created).

While is $_FILE superglobal not being passed

So I am working on a file upload form that seems to lose the information in the file super global from one step to another. So what I do is I print out the file super global before I verify through captcha and then print it out once I validate through the captcha. For some way I lose the information after verifying the captcha. I have tried storing the information in a cookie and a session variable but with no luck. In terms of the cookie direction it saves the file super global information into the cookie only if I hit refresh before captcha validation. In terms of session storage it stores the information in the session variable before I verify the captch but then lose it after I verify the captach. Can you guys people help, and thanks in advance. My code is below:
$DIRECTORY_NAME = "/home/www/xxx/xxxPhotos/";
$FILES = array();
$SPEAKER_STATUS_DROPDOWN = '<option value="">...</option><option value="Suggested">Suggested</option><option value="Invited">Invited</option><option value="Confirmed">Confirmed</option>';
if (empty($_SESSION['captcha']) || strtolower(trim($_REQUEST['captcha'])) != $_SESSION['captcha']) {
$captcha = false;
} else {
$captcha = true;
}
if (!empty($_POST) && $captcha) {
$UNIQ_ID = $_POST['uniq_id'];
$FORM_ID = $_POST['form_id'];
//$uniqid = createuniqid();
// Upload file
if ($_FILES["file"]["name"] != "") {
if ($_FILES["file"]["error"] > 0)
{
echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
die();
}
else
{
$allowedExtensions = array("jpg","gif","tiff","pdf");
if ($file["file"]['tmp_name'] != '') {
if (!in_array(end(explode(".",
strtolower($file["file"]['name']))),
$allowedExtensions)) {
die($file["file"]['name'].' is an invalid file type!<br/>'.
'<a href="javascript:history.go(-1);">'.
'<&lt Go Back</a>');
}
}
$filename = "AS_".$uniqid."". strrchr($_FILES["file"]["name"], '.');
move_uploaded_file($_FILES["file"]["tmp_name"],
$DIRECTORY_NAME . $filename);
$filenamequery = ", attachment='$filename' ";
$filenameemailbody = "<br>Attachment: http://www.verney.ca/viewabstract.php?filename=$filename";
}
die('reached here');
}
HTML Form
<form name="frmAbstract" id ="frmAbstract" method="post" action="storiesv.php" onSubmit="return validation();" enctype="multipart/form-data" style="margin-left:20px;">
<input type="hidden" name="uniq_id" value="">
<input type="hidden" name="form_id" value="6">
<div><label class="labelHeader"><strong><h1>Form</h1></strong></label><br/></div>
<div class="formrow">
<label for="question_390">First Name of Submitter: <span style="color:#FF0000">*</span></label>
<input type="text" id="question_390" name="question_390" style="width:500px" maxlength="255" value="">
</div>
<div class="formrow">
<label for="question_391">Last Name of Submitter: <span style="color:#FF0000">*</span></label>
<input type="text" id="question_391" name="question_391" style="width:500px" maxlength="255" value="">
</div>
<div class="formrow">
<label for="question_392">Title: </label>
<input type="text" id="question_392" name="question_392" style="width:500px" maxlength="255" value="">
</div>
<div class="formrow">
<label for="question_393">Organization: </label>
<input type="text" id="question_393" name="question_393" style="width:500px" maxlength="255" value="">
</div>
<div class="formrow">
<label for="question_394">Phone: </label>
<input type="text" id="question_394" name="question_394" style="width:500px" maxlength="255" value="">
</div>
<div class="formrow">
<label for="question_395">Email: <span style="color:#FF0000">*</span></label>
<input type="text" id="question_395" name="question_395" style="width:500px" maxlength="255" value="">
</div>
<div class="formrow">
<label for="question_396">Involvement with the CBS: </label>
<input type="text" id="question_396" name="question_396" style="width:500px" maxlength="255" value="">
</div>
<div class="formrow">
<label for="question_397">First became a CBS member in (yyyy): <span style="color:#FF0000">*</span></label>
<input type="text" id="question_397" name="question_397" style="width:500px" maxlength="255" value="">
</div>
<div class="formrow">
<label for="question_398">Your story/experience/anecdote (limit of 250 words): </label>
<textarea name="question_398" name="question_398" style="width:500px;height:200px;"></textarea>
</div>
<div class="formrow" >
<label>Do you have a photo / graphic to upload (scans of print photos are acceptable)? </label>
<div class="checkboxdiv"><input type="radio" style="width:20px;float:left;border:0px;"id="question_399_0" name="question_399[]" value="Yes"><label for="question_399_0">Yes</label></div><div class="checkboxdiv"><input type="radio" style="width:20px;float:left;border:0px;"id="question_399_1" name="question_399[]" value="No"><label for="question_399_1">No</label></div><strong><em></em></strong><div style="clear:both;"></div></div>
<div>
<label for="question_400">Attachment: (Only jpg, gif, tiff, pdf, will be accepted) </label>
<input type="file" id="question_400" name="question_400" style="width:500px;">
</div>
<div class="formrow">
<label for="question_401">For photos submitted, please include names of people in the photo, location, and date. </label>
<textarea name="question_401" name="question_401" style="width:500px;height:200px;"></textarea>
</div>
<div class="formrow" >
<label>Do we have permission to publish this photo in a slide show to be featured at the 2014 CBS Conference and possibly in a printed collection of memoirs intended for past and present CBS members? </label>
<div class="checkboxdiv"><input type="radio" style="width:20px;float:left;border:0px;"id="question_402_0" name="question_402[]" value="Yes"><label for="question_402_0">Yes</label></div><div class="checkboxdiv"><input type="radio" style="width:20px;float:left;border:0px;"id="question_402_1" name="question_402[]" value="No"><label for="question_402_1">No</label></div><strong><em></em></strong><div style="clear:both;"></div></div><div><label class="labelHeader"><strong>Questions</strong></label><br/></div>
<div class="formrow">
<label for="question_404">Tell us about your experience(s) with the CBS. </label>
<input type="text" id="question_404" name="question_404" style="width:500px" maxlength="255" value="">
</div>
<div class="formrow">
<label for="question_405">How did you become involved in the CBS? </label>
<input type="text" id="question_405" name="question_405" style="width:500px" maxlength="255" value="">
</div>
<div class="formrow">
<label for="question_406">What is your best memory of the CBS? </label>
<input type="text" id="question_406" name="question_406" style="width:500px" maxlength="255" value="">
</div>
<div class="formrow">
<label for="question_407">Who have been your role models in the field? </label>
<input type="text" id="question_407" name="question_407" style="width:500px" maxlength="255" value="">
</div>
<div class="formrow">
<label for="question_408">What has been the most significant accomplishment of Canadian bioethics? </label>
<input type="text" id="question_408" name="question_408" style="width:500px" maxlength="255" value="">
</div>
<div class="formrow">
<label for="question_409">What is our biggest challenge going forward? </label>
<input type="text" id="question_409" name="question_409" style="width:500px" maxlength="255" value="">
</div>
</fieldset>
<div style="clear:both;"><br><input type="submit" name="btnSave" id="btnSave" value="Next" class="submitbutton" "></div>
<p> </p>
</form>
So the code above is the original code I have been working with. It essentially does the file upload after the captcha is validated, and this is where I lose $_FILES super global
ANSWER: Thanks for all those who viewed my question. The issue was the captcha was in a form on it own page with a enctype set. Therefore the $_FILES super global was overwritten with that forms $_FILES, which of course is not set.
The name of your file input is question_400, so you would need $_FILES["question_400"]["name"], etc.

Html form posting, no data passed on [duplicate]

This question already has answers here:
Does form data still transfer if the input tag has no name?
(3 answers)
Closed 5 years ago.
I've been sitting with this problem for a while now, can't seem to figure out whats wrong with the code.
The problem is that no data gets posted from the form to the script.
<div class="mws-panel-body">
<form class="mws-form" action="blueprints/add" method="post" id="pForm">
<div class="mws-form-inline">
<div class="mws-form-row">
<label>Blueprint name</label>
<div class="mws-form-item small">
<input type="text" class="mws-autocomplete mws-textinput" id="pName" value="" />
<div>The name of the blueprint, search completion is enabled.</div>
</div>
</div>
<div class="mws-form-row">
<label>Hangar</label>
<div class="mws-form-item micro">
<select id="pHangar">
<option value="0" selected>Personal</option>
<option value="1">Corporation</option>
</select>
<div>Indicates who the blueprint belongs to.</div>
</div>
</div>
<div class="mws-form-row">
<label>State</label>
<div class="mws-form-item micro">
<select id="pState">
<option value="1" selected>Original</option>
<option value="0">Copy</option>
</select>
<div>The state of the blueprint, be it original or a copy.</div>
</div>
</div>
<div class="mws-form-row">
<label>Productions runs</label>
<div class="mws-form-item small">
<input type="text" class="mws-textinput" id="pRuns" value="0" />
<div>The number of production runs left on copy.</div>
</div>
</div>
<div class="mws-form-row">
<label>Material efficiency</label>
<div class="mws-form-item small">
<input type="text" class="mws-textinput" id="pME" value="0" />
<div>The current material efficiency level of the blueprint.</div>
</div>
</div>
<div class="mws-form-row">
<label>Production efficiency</label>
<div class="mws-form-item small">
<input type="text" class="mws-textinput" id="pPE" value="0" />
<div>The current production efficiency level of the blueprint.</div>
</div>
</div>
</div>
<div class="mws-button-row">
<input type="submit" value="Add blueprint" class="mws-button blue" />
<input type="reset" value="Reset" class="mws-button gray" />
</div>
</form>
</div>
It seems to be a problem with the form itself, as if the form is set to get, it just enters the script with a question-mark only, blueprints/add?, meaning no data gets passed on at all.
Any pointers or suggestions will be appreciated.
My platform is PHP if that helps.
You should be using the name attribute of input to send the data to a PHP post script. Example:
Form:
<form action="add.php" method="post">
<input type="text" name="firstname" />
</form>
Script (add.php):
<?php
//print the $_POST['firstname'] variable
echo $_POST['firstname'];
?>
You need to add the name attribute to your input and select elements
<input type="text" name="myinput">
Php will then build your $_POST array with those names.

Categories