Array count is not working properly in my form .. I cloned the input values
please check whole code in this link Click Here
Here is php code
if(isset($_POST['Submit'])) {
echo $cnt = count($_POST['task_description']); //die();
for($i=0;$i<$cnt; $i++ ){
mysqli_query($con,"INSERT INTO ts_task(project,task_title,task_description,minutes,created_date,status)VALUES('".$_POST['project'][$i]."','".$_POST['task_title'][$i]."','".$_POST['task_description'][$i]."','".$_POST['minutes'][$i]."','".date('Y-m-d')."','".$_POST['status'][$i]."')");
}
header("Location:tasklist.php");
die();
}
Here is my HTML code
First Array
<input name="task_title[]" class="form-control" type="text" style="width:150px;">
<input class="form-control" type="text" name="task_description[]" style="width:150px;">
<input class="form-control" type="text" name="project[]" style="width:150px;">
<input class="form-control" type="text" name="minutes[]" style="width:150px;">
Second Array
<input name="task_title[]" class="form-control" type="text" style="width:150px;">
<input class="form-control" type="text" name="task_description[]" style="width:150px;">
<input class="form-control" type="text" name="project[]" style="width:150px;">
<input class="form-control" type="text" name="minutes[]" style="width:150px;">
i print the count of POST value but it return only 1..
please verify :
both textbox contains at least some value.
both are in same forms.
Related
Im new to laravel, my question is - is there any way to retrieve data from redirect() without using with() function, i have a view with values filled from database returned from controller. based on the value selected, i want to fill the form
Controller-
public function getSearchData()
{
return view("welcome",["data"=>User::all()]);
}
public function getSearchDetail(Request $request)
{
$searchdata = User::where("email",$request->user)->first();
return redirect("/")->with(["searchdata"=>$searchdata]);
}
Route -
Route::get("/",[UserController::class,"getSearchData"]);
Route::get("/search",[UserController::class,"getSearchDetail"]);
View -
<form action="/search" method="GET">
<select name="user" id="user">
#isset($data)
#foreach ($data as $detail)
<option value="{{$detail->email}}">{{$detail->name}}</option>
#endforeach
#endisset
</select>
<button>Submit</button>
</form>
<form action="">
<input type="text" name="name" id="name" value="">
<input type="text" name="email" id="email" value="">
<input type="text" name="password" id="password" value="">
<select name="gender" id="gender">
<option value=""></option>
</select>
<input type="text" name="phone" id="phone" value="">
</form>
only way i know how to fill the form is using session(), like this
<input type="text" name="name" id="name" value="#if (session('searchdata'))
{{ session('searchdata')->name }}
#endif">
and this is not good, i don't want my single <input /> to be that long, is there any solution to this?
I have a html form with select. Based on select option i want to display a sub form with different values and insert this data to database. I figured out how to display a sub form, but i don't know how to insert different values into database. Let's say i have an option CD with value size, a BOOK with value weight and FURNITURE with three values - width, length and height. With CD and BOOK it is simple, but how do i handle furniture with three parameters?
<form class="form-group" action="" method="post">
<label for="id">SKU</label>
<input type="text" name="id" class="form-control">
<label for="name">Name</label>
<input type="text" name="name" class="form-control">
<label for="price">Price</label>
<input type="text" name="price" class="form-control">
<label for="type-switch">Type</label>
<select class="form-control" name="type-switch" id="type" onchange="changeOptions(this)">
<option value="" selected="selected"></option>
<option value="form_1">DVD</option>
<option value="form_2">Book</option>
<option value="form_3">Furniture</option>
</select>
</form>
<!-- Sub Form-->
<form class="sub-form" name="form_1">
<label for="size">Size(MB)</label>
<input class="form-control" type="text" name="size" id="">
</form>
<form class="sub-form" name="form_2">
<label for="weight">Weight(KG)</label>
<input class="form-control" type="text" name="weight" id="">
</form>
<form class="sub-form" name="form_3">
<label for="height">Height(CM)</label>
<input class="form-control" type="text" name="height" id="">
<label for="width">Width*(CM)</label>
<input class="form-control" type="text" name="width" id="">
<label for="length">Length(CM)</label>
<input class="form-control" type="text" name="length" id="">
</form>
</div>
I have a standard form with all user info, I want to have a drop down list where the state input is so the user can select the state. I have a database with state code and description. Here's the code for my form, just need to know how to add the drop down list so it will show up where the state code is. I've tried putting the drop down using the regular drop down code but when I do that the drop down list shows up at the top of the form.
<section class="main-container">
<div class="main-warpper">
<h2>Sign up</h2>
<form class="signup-form" action="includes/signupinc.php" method="POST">
<input type="text" name="mbrnumber" placeholder="Member Number">
<input type="text" name="alias" placeholder="Alias">
<input type="text" name="firstname" placeholder="First Name">
<input type="text" name="lastname" placeholder="Last Name">
<input type="text" name="address" placeholder="Address">
<input type="text" name="city" placeholder="City">
<input type="text" name="state" placeholder="State">
<input type="text" name="zipcode" placeholder="Zip Code">
<input type="text" name="email" placeholder="E-mail">
<input type="password" name="pwd" placeholder="Password">
<button = type="submit" name="submit">Sign Up</button>
</form>
</div>
</section>
I've been playing around with this and have come up with something like I want. I would like the state code drop down list to look like the placeholder in the rest of the form. Width height I know I can style this but not sure just how to do that. Here's the code I have come up with. The state drop down list comes from my database.
<section class="main-container">
<div class="main-warpper">
<h2>Sign up</h2>
<form class="signup-form" action="includes/signup.inc.php" method="POST">
<input type="text" name="clubname" placeholder="Your databae name(lower case only no spaces)">
<input type="text" name="mbrnumber" placeholder="Member Number">
<input type="text" name="alias" placeholder="Alias">
<input type="text" name="firstname" placeholder="First Name">
<input type="text" name="lastname" placeholder="Last Name">
<input type="text" name="address" placeholder="Address">
<input type="text" name="city" placeholder="City">
<tr>
<input type="text" name="state" placeholder="State">
<select name="state">
<?php
$sql="Select * from matchstates";
echo "<option value='' selected>Select State</option>";
foreach ($conn->query($sql) as $row) {
echo "<option value=$row[statecode]>$row[statename]</option>";
}
?>
</select>
</tr>
<input type="text" name="zipcode" placeholder="Zip Code">
<input type="text" name="email" placeholder="E-mail">
<input type="password" name="pwd" placeholder="Password">
<button = type="submit" name="submit">Sign Up</button>
</form>
</div>
I have a large amount of input fields. How can I pass the values into an array so I can pass the array from one page to another?
example:
<input type="text" value=<?php $arry = "compName" ?> placeholder="Company Name" />
Is this legal? How can I do this properly?
EDIT:
In my page, I have "add" and "delete" buttons that will add/delete more input fields. I also have a "preview" button at the bottom. User will add/delete before hitting preview. Preview will collect all input and will call the next page. So the amount of field is unknown.
Here's what my code/markup looks like:
<div class="panel" style="width: 98%; margin:0 auto">
<div class="row">
<div class="large-6 columns">
Advertiser Info: <hr>
<input type="text" value="compName" placeholder="Company Name" />
<input type="text" value= "adEmail" placeholder="Email" />
<input type="text" value="adContName" placeholder="Contact Name" />
<input type="text" value="adPhone" placeholder="Phone # (NO DASHES)" />
<input type="text" value="adStreet" placeholder="Street Address" />
<input type="text" value="adCity" placeholder="City" />
<input type="text" value="adState" placeholder="State/Provice" />
<input type="text" value="adZip" placeholder="Zip/Postal Code" />
<input type="text" value="adCountry" placeholder="Country" />
</div>
<div class="large-6 columns">
Billing Info: <hr>
<input type="text" value="bEmail" placeholder="Email" />
<input type="text" value="bContName" placeholder="Contact Name" />
<input type="text" value="bPhone" placeholder="Phone # (NO DASHES)" />
<input type="text" value="bStreet" placeholder="Street Address" />
<input type="text" value="bCity" placeholder="City" />
<input type="text" value="bState" placeholder="State/Provice" />
<input type="text" value="bZip" placeholder="Zip/Postal Code" />
<input type="text" value="bCountry" placeholder="Country" />
</div>
</div>
</div>
So when the user hits add and EXACT copy of above code will be made.
With that said, I want to be able to use PHP arrays for html values to pass. How can I set my inputs so that I can do this?
You can do some tweaks like:
Using input type elements as array elements.
So that:
<input type="text" name="elem[name]" value="<?php echo $YOUR_VALUE;?>"
<input type="text" name="elem[class]" value="<?php echo $YOUR_VALUE;?>"
<input type="text" name="elem[marks]" value="<?php echo $YOUR_VALUE;?>"
So that the variables are you are posting should be less.
In this case, you are posting only one variable instead of three.
Use Jquery to get all the values of input fields and make a json object of {input_name:value} or array variable of key value and then pass it in argument.
var key_value = {};
$('input').each(function(){
key_value[$(this).attr('name')]= $(this).val();
})
alert(JSON.stringify(key_value));
Now you have an object with field name as key and its value.
HTML FORM
<form class="form" method="post" action="process.php">
<h4 class="form-heading">Please New Enter Customer Information</h4>
<label for="inital">Inital:</label>
<select id="inital" name="inital" required="required">
<option value="mr">Mr</option>
<option value="ms">Ms</option>
<option value="mrs">Mrs</option>
<option value="prof">Prof</option>
<option value="dr">Dr</option>
</select>
<label for="firstname">First Name:</label>
<input type="text" placeholder="First Name" name="firstname" required="required" >
<label for="lastname">last Name:</label>
<input type="text" placeholder="Last Name" name="lastname" required="required">
<label for="mobile">Mobile:</label>
<input type="tel" placeholder="Mobile" name="mobile" required="required">
<label for="landline">Landline:</label>
<input type="tel" placeholder="Landline" name="landline">
<label for="email">Email:</label>
<input type="email" placeholder="Email" name="email" required="required">
<label for="address">Address:</label>
<input type="text" placeholder="Address" name="address" required="required">
<label for="postocde">Postal Code:</label>
<input type="text" placeholder="Post Code" name="postcode">
<label for="accessibility">Accessibility:</label>
<input type="text" placeholder="Accessibility Needs" name="accessibility" value="">
<button class="btn btn-large btn-primary" type="submit">Enter</button>
process.php
<? php
require( '../connect_db.php' ) ;
$inital = $sql->real_escape_string($_POST[inital]);
$firstname = $sql->real_escape_string($_POST[firstname]);
$lastname = $sql->real_escape_string($_POST[lastname]);
$mobile = $sql->real_escape_string($_POST[mobile]);
$landline = $sql->real_escape_string($_POST[landline]);
$email = $sql->real_escape_string($_POST[email]);
$address = $sql->real_escape_string($_POST[address]);
$postcode = $sql->real_escape_string($_POST[postcode]);
$accessibility = $sql->real_escape_string($_POST[accessibility]);
$query = "INSERT INTO `customer` (inital, firstname, lastname, mobile, landline, email, address, postcode, accessibility) VALUES ('$inital','$firstname', '$lastname','$mobile','$landline','$email','$address','$postcode','$accessibility')";
/* execute the query, nice and simple */
$sql->query($query) or die($query.'<br />'.$sql->error);
?>
I have tried alternatives too but to no satisfaction like not including $inital =($_POST[inital]); Instead putting right into INSERT INTO section but that still does not help either.
It either prints out the whole code on screen or blank. I've looked at similar problems on here and on forums all them seem to present the issue differently and when i change it suit the so called answer it still does not work!
My other page that lists all the tables using the following connection required statment works works fine so there is no problem with connection to the database but at this moment just cannot insert content. Grr
Two problems:
change <? php to <?php
and then add quotes to your post data values. $_POST[inital] to $_POST['inital']
and for your information i would do isset($_POST['value']) ? $_POST['value'] : '';
you still need to check post value before using it.
Check the <? php tag. it should be <?php