I dont see the reason why one particular html field is not sending data.
My html:
<form id="login_registro_form" role="form" method="post" action="./controllers/register.php">
<div class="row my-4 justify-content-md-center">
<label class="col-lg-3" for="regName">NOMBRE</label>
<input type="text" class="form-control" id="regName" placeholder="SEGÚN APARECE EN EL DNI/PASAPORTE" name="regName">
<div class="invalid-feedback ">El nombre es un campo obligatorio </div>
</div>
<div class="row my-4 justify-content-md-center">
<label class="col-lg-3" for="reg_birthday">CONFIRMA TU TALLA</label>
<select class="form-select" id="talla" nombre="talla" aria-label="Default select example">
<option value="xs">XS</option>
<option value="s">S</option>
<option value="m" selected>M</option>
<option value="L">L</option>
<option value="xl">XL</option>
<option value="xxl">XXL</option>
</select>
</div>
<div class="login_cb justify-content-md-center">
<label for="reg_allergies">ALERGIAS, INTOLERANCIAS O DIETAS ESPECIALES</label>
<input type="checkbox" class="form-check-input " id="reg_allergies" name="allergies" >
</div>
<button id="register_button" type="submit" class="btn btn-primary" >GUARDAR</button>
</form>
While this is shortened all the other imput fields are working and enclosed within the same div class="row my-4 justify-content-md-center"
In my php i tried checking with:
var_dump($_POST);die;
I am able to see there that ALL of the other variables are there except the options
And one more thing. I have some validations before i send the information:
$('#login_registro_form').submit(function(e) {
//My validations for the rest of the form
console.log($('#talla').val()); //THIS IS ACTUALLY SHOWING THE INFORMATION
return (errores.length <= 0 );
});
So the information IS there just before posting it, but for some reason it is not being recognised as part of the form
Edit: I know i can retrieve the information using jquery and send it it by creating a new field, but im trying to understand my html mistake here.
You have not given the <select> element a name="talla" attribute, Therefore it is not sent to the PHP code. Only fields with a name= attribute can send data to PHP Code.
Related
I am trying to achieve something via php.
Here there are couple of options.
<select class="custom-select" id="inputGroupSelect01">
<option selected="">Select Clusters ...</option>
<option value="math-related">Math Related</option>
<option value="science-related">Science Related</option>
</select>
There are Group of subject fields which will appear when the options are changed respectively.
<div class="form-row pb-5" id="math-related"">
<div class="form-group col-md-3">
<input type="number" class="form-control" id="num1" placeholder="English">
</div>
<div class="form-group col-md-3">
<input type="number" class="form-control" id="num2" placeholder="Math">
</div>
<div class="form-group col-md-3">
<input type="number" class="form-control" id="num3" placeholder="Science">
</div>
<div class="form-group col-md-3">
<input type="number" class="form-control" id="num4" placeholder="Computer">
</div>
</div>
When the option is changed to Math related OR Science Related option, the related 5-6 subject fields will be populated like image below. Some might have 5, some might have 8.
How to refresh the page and load the new sets of input fields according to selection done via PHP?
Example Image for fields
First of all change your select dropdown with your page url + parameter and make sure to replace YOUR_PAGE_URL with actual url as follows -
<select onChange="window.location.href=this.value" class="custom-select" id="inputGroupSelect01">
<option value="">Select Clusters ...</option>
<option value="YOUR_PAGE_URL?topic=math-related">Math Related</option>
<option value="YOUR_PAGE_URL?topic=science-related">Science Related</option>
</select>
After then just do a GET parameter checking on your page to populate your fields like -
if( issset($_GET['topic']) ){
if( $_GET['topic'] == 'math-related' ){
echo "Add your math related above 5-8 fields html here.";
}elseif( $_GET['topic'] == 'science-related' ){
echo "Add your science related above 5-8 fields html here.";
}
}
<form class="form-inline" action="./test.php?id=1">
<li class="nav-item">
<div class="form-group">
<select class="custom-select custom-select-lg mb-3" id="objectType">
<option selected>Object Type</option>
<option value="Toy">Toy</option>
<option value="Furniture">Furniture</option>
<option value="Gift">Gift</option>
<option value="Household">Household</option>
<option value="Instrument">Instrument</option>
</select>
</div>
</li>
<li class="nav-item">
<div class="form-group">
<select class="custom-select custom-select-lg mb-3" id="materialType">
<option selected>Material Type</option>
<option value="Mud">Mud</option>
<option value="Cloth">Cloth</option>
<option value="Thread">Thread</option>
<option value="Jute">Jute</option>
<option value="Cotton">Cotton</option>
<option value="Can">Can</option>
<option value="Bamboo">Bamboo</option>
</select>
</div>
</li>
<li class="nav-item">
<div class="form-group">
<div class="input-group">
<input class="form-control" type="search" placeholder="Search">
<span class="input-group-btn">
<button class="btn btn-outline-secondary" type="submit" id="searchSubmit"><i class="fa fa-search"></i>
</button>
</span>
</div>
</div>
</li>
</form>
I have this form. When the submit button is called test.php page is called with request id value 1. In test.php form field's value will be used for making query.
test.php code snippet of a portion
$id=$_REQUEST['id'];
if ($id==1)
{
$result = search($_POST['imageName'],$_POST['objectType'],$_POST['materialType']);
echo $_POST['imageName'];
}
else
{
$result = home_page_image();
}
When I click the submit button after fill the field the test.php?id=1 is not appear in the browser address bar that confirms me that the page is not called.
Edit 1
I have added method(POST) as #PL200 mentioned in his answer but nothing is echo after search() function in test.php. I also put a alert but not shown. alert is work before search function and post value is neither echo before nor after of search function. That indicates the form values are not posted in test.php.
Edit 2
Actually I call the same page when click the submit button is clicked.
You've included no method for your form. Change the first line of your html to:
<form class="form-inline" method="POST" action="./test.php?id=1">
That should fix the problem that you're having.
I understand what you were trying to do, but note that some browsers will ignore the query arguments passed with the form action attribute. So whenever the form has been submitted, on some browsers the $_GET['id'] might not be defined, just inconsistent behavior.
Also,you didn't specify any method attribute for your form.
What you should have done instead
Use a hidden input form element to pass your value, this is the recommended way to do it.
<form class="form-inline" action="./test.php" method="post">
<!-- put values to pass here -->
<input type="hidden" value="1" name="id" />
...
</form>
Furthermore, you could also place the hidden input field outside the form element and use the form id to reference it with the input field form attribute. See example below:
<form id="form-id" class="form-inline" action="./test.php" method="post">
<!-- put values to pass here -->
...
</form>
<!-- Bind this hidden input field to your form -->
<input type="hidden" value="1" name="id" form="form-id" />
Note that there's no limitation to the numbers of hidden input field you can use in a single form, howbeit, make it simple.
There is no name of form input.
<form class="form-inline" action="./test.php?id=1" method="POST">
<li class="nav-item">
<div class="form-group">
<select class="custom-select custom-select-lg mb-3" name="objectType">
<option selected>Object Type</option>
<option value="Toy">Toy</option>
<option value="Furniture">Furniture</option>
<option value="Gift">Gift</option>
<option value="Household">Household</option>
<option value="Instrument">Instrument</option>
</select>
</div>
</li>
<li class="nav-item">
<div class="form-group">
<select class="custom-select custom-select-lg mb-3" name="materialType">
<option selected>Material Type</option>
<option value="Mud">Mud</option>
<option value="Cloth">Cloth</option>
<option value="Thread">Thread</option>
<option value="Jute">Jute</option>
<option value="Cotton">Cotton</option>
<option value="Can">Can</option>
<option value="Bamboo">Bamboo</option>
</select>
</div>
</li>
<li class="nav-item">
<div class="form-group">
<div class="input-group">
<input class="form-control" type="search" placeholder="Search" name="imageName">
<span class="input-group-btn">
<button class="btn btn-outline-secondary" type="submit" id="searchSubmit"><i class="fa fa-search"></i>
</button>
</span>
</div>
</div>
</li>
</form>
And alert message is not shown after search() method because in search() method something is wrong. I debug and correct the error in search() method. Now all works.
This question already has answers here:
PHP parse/syntax errors; and how to solve them
(20 answers)
Closed 6 years ago.
ive been all around trying to fix the code but i still get an error
Parse error: syntax error, unexpected 'userfirstName' (T_STRING), expecting ',' or ';' in /home/crosswayprinting/public_html/ztest2/functions/shop.php on line 66
here's the code btw
whats my mistake :/ ?
<?php if($user_home->is_logged_in()){
echo '
<div class="row">
<div class="col-lg-8 col-lg-offset-2">
<h2 class="section-heading">Place an Order</h2>
<div class="text-center" style="input, select, textarea{
color: #000;
}">
</div><BR>
<form role="form" class="userTrans" method="POST">
<input type="hidden" value="OrderInsert" name="act_userTrans">
<div class="form-group">
<label for="typeofservice">Select Type of Service</label>
<select id="typeofservice" class="form-control" name="typeofservice">
<option value="Tarpaulin">Tarpaulin</option>
<option value="Rush ID">Rush ID</option>
<option value="Photocopy">Photocopy</option>
<option value="Graphic Layout">Graphic Layout</option>
<option value="Invitation">Invitation</option>
<option value="Panaflex">Panaflex</option>
<option value="Signages">Signages</option>
<option value="Stickers">Stickers</option>
<option value="Sintra board">Sintra board</option>
<option value="Large Format Photo">Large Format Photo</option>
<option value="PVC ID">PVC ID</option>
<option value="Lamination">Lamination</option>
<option value="Bag Tags">Bag Tags</option>
<option value="Notary Public">Notary Public</option>
<option value="Scan">Scan</option>
</select>
</div>
<div class="form-group">
<label for="templateselect">Template Selection</label>
<select id="templateselect" class="form-control" name="templateselect">
<option value="Own Made Template">Own Made Template</option>
<option value="Pre-made Template">Pre-made Template</option>
</select>
</div>
<div class="form-group">
<label for="text">More details about your order</label>
<input type="text" class="form-control" id="orderdetails" name="orderdetails">
</div>
<div class="form-group">
<label for="text"> Customer Name</label>
<input type="text" value=" <?php echo $row['userfirstName']; ?> " class="form-control" id="customer" name="customer">
</div>
/* this is the code btw what makes it an error, i am trying to
echo a customer's name and make it Passive or uneditable textbox so it can
register to my orderlist to whom ordered */
<button type="submit" class="btn btn-default userTrans">Submit</button>
</form>
';
}
else{
echo '
<center> Please Login to Place an Order </center>
';}
?>
Get rid of the echo statements wrapping your HTMl. There's no need, just escape out of the PHP interpreter and print your HTML. Then you won't get an error when you're doing <?php echo $row['userFirstName']; ?>....Something like this:
<?php if($user_home->is_logged_in()){ ?>
<div class="row">
<div class="col-lg-8 col-lg-offset-2">
<h2 class="section-heading">Place an Order</h2>
<form role="form" class="userTrans" method="POST">
<input type="hidden" value="OrderInsert" name="act_userTrans">
<div class="form-group">
<label for="typeofservice">Select Type of Service</label>
<select id="typeofservice" class="form-control" name="typeofservice">
<option value="Tarpaulin">Tarpaulin</option>
<option value="Rush ID">Rush ID</option>
<option value="Photocopy">Photocopy</option>
<option value="Graphic Layout">Graphic Layout</option>
<option value="Invitation">Invitation</option>
<option value="Panaflex">Panaflex</option>
<option value="Signages">Signages</option>
<option value="Stickers">Stickers</option>
<option value="Sintra board">Sintra board</option>
<option value="Large Format Photo">Large Format Photo</option>
<option value="PVC ID">PVC ID</option>
<option value="Lamination">Lamination</option>
<option value="Bag Tags">Bag Tags</option>
<option value="Notary Public">Notary Public</option>
<option value="Scan">Scan</option>
</select>
</div>
<div class="form-group">
<label for="templateselect">Template Selection</label>
<select id="templateselect" class="form-control" name="templateselect">
<option value="Own Made Template">Own Made Template</option>
<option value="Pre-made Template">Pre-made Template</option>
</select>
</div>
<div class="form-group">
<label for="text">More details about your order</label>
<input type="text" class="form-control" id="orderdetails" name="orderdetails">
</div>
<div class="form-group">
<label for="text"> Customer Name</label>
<input type="text" value=" <?php echo $row['userfirstName']; ?> " class="form-control" id="customer" name="customer">
<!-- now the above won't give an error -->
</div>
<button type="submit" class="btn btn-default userTrans">Submit</button>
</form>
</div>
</div>
<?php } else { ?>
<!-- Do not use center tags when you're using bootstrap framework -->
<!--<center> Please Login to Place an Order </center>-->
<div class="text-center"> Please Login to Place an Order </div>
<?php } ?>
Also what's going on with your inline styles? That's not how this works:
<div class="text-center" style="input, select, textarea{
color: #000;
}">
Just move that CSS somewhere else. You can't use targeted selectors within the style="" tag, only relevant CSS.
I am using Bootstrap. I am trying to create a working form, but the submit function doesn't work.
Here is my form HTML:
<form class="form-horizontal" role="form" action="mph.php" method="POST">
<div class="modal-body">
<fieldset>
<!-- Form Name -->
<legend>Map Problem Reporter</legend>
<!-- Select Basic -->
<div class="form-group">
<label class="col-md-4 control-label" for="selectbasic">What map?</label>
<div class="col-md-6">
<select id="selectbasic" name="selectbasic" class="form-control">
<option value="1">6 Stages of Parkour</option>
<option value="2">20 Stages of Parkour</option>
</select>
</div>
</div>
<!-- Multiple Radios -->
<div class="form-group">
<label class="col-md-4 control-label" for="radios">What kind of problem?</label>
<div class="col-md-4">
<div class="radio">
<label for="radios-0">
<input type="radio" name="radios" id="radios-0" value="1">
Blocks
</label>
</div>
<div class="radio">
<label for="radios-1">
<input type="radio" name="radios" id="radios-1" value="2">
Commands / Command Blocks
</label>
</div>
<div class="radio">
<label for="radios-2">
<input type="radio" name="radios" id="radios-2" value="">
Entities / Items
</label>
</div>
<div class="radio">
<label for="radios-3">
<input type="radio" name="radios" id="radios-3" value="">
Other (describe in the next text field)
</label>
</div>
</div>
</div>
<!-- Textarea -->
<div class="form-group">
<label class="col-md-4 control-label" for="textarea">Describe the Problem</label>
<div class="col-md-4">
<textarea class="form-control" id="textarea" name="textarea"></textarea>
</div>
</div>
<!-- Select Basic -->
<div class="form-group">
<label class="col-md-4 control-label" for="selectbasic">What is the priority?</label>
<div class="col-md-6">
<select id="selectbasic" name="selectbasic" class="form-control">
<option value="1">Huge! It breaks the map!</option>
<option value="2">Big</option>
<option value="">Noticeable</option>
<option value="">Barely Noticeable</option>
<option value="">Almost Hidden</option>
<option value="">I do not know</option>
</select>
</div>
</div>
<input type="submit" name="submit" value="Save Data">
</fieldset>
</form>
And here is my current PHP:
<?php
if(isset($_POST['field1']) && isset($_POST['field2'])) {
$data = $_POST['field1'] . '-' . $_POST['field2'] . "\n";
$ret = file_put_contents('mpr.txt', $data, FILE_APPEND | LOCK_EX);
if($ret === false) {
die('There was an error writing this file');
}
else {
echo "$ret bytes written to file";
}
}
else {
die('no post data to process');
}
?>
When I click "Save Data" in the form, it doesn't update my mpr.txt with the information. Please help.
I see 2 problems:
1) You have created 2 forms with
<form class="form-horizontal" role="form">
and
<form class="form-horizontal">
which should be 1
and
2) You are missing the action attribute in <form> tag i.e. it should be <form class="form-horizontal" role="form" action="<php file name>" method="<request type>">
correct these and I think you should be through.
You do not see the data in your .txt file because you do not have any field named field1 and field2 in your html page. The field names have to match in both html and php files to write/read the data correctly. Please correct the names and you should be through.
Also would appreciate if you accept the answer.
The answer is quit obvious! PHP is trying to find field1 and field2 posted. But in your HTML form you did not define these two properties, consequently PHP won't update the file!
EDIT:
If you submit the form and print_r($_POST) you will get the follow array:
Array ( [selectbasic] => 1 [textarea] => [submit] => Save Data )
As you see, there is no [field1] or [field2] in the response!
Which means PHP cannot proceed to to open and update the text file!
To prevent this, you should define field1 and field2 in your HTML form by adding these input tags or updating the existing ones.
For instance, if you are interested in the select tag and the textarea tag, you should whether update you HTML code or you php code.
You could go with PHP code by updating your if statement into if(isset($_POST['selectbasic'], $_POST['textarea'])) or in your HTML form change the name="selectbasic" into name="field1" and name="textarea" into name="field2 and keep your current php code and so your current PHP if statement that says: if(isset($_POST['field1']) && isset($_POST['field2']))
I hope this explains it all!
I am trying to make a input form dropdown using bootstrap(BootStrap version 2.3.2), but my form dropwdown make a irrelevant space with it.
This is my code:
<div class="control-group" >
<label class="control-label">Event Name</label>
<div class="controls">
<div class="input-prepend">
<? $result=$this->db->get("EventType")->result();
foreach($result as $res){
$event[$res->Id]=$res->Name;
}
$event["Select"]="Select";
$js = 'id="events" class="input-large" onChange="some_function();"';
echo form_dropdown("event_type",$event, 'Select',$js); ?>
</div>
<? echo '<span style=color:red>'.form_error('event_name').'</span>'; ?>
</div>
</div>
Rendered HTML:
<div class="control-group">
<label class="control-label">Event Name</label>
<div class="controls">
<div class="input-prepend">
<select name="event_type" id="events" class="width" onChange="some_function();">
<option value="6">Music</option>
<option value="7">Seminar</option>
<option value="8">Sports</option>
<option value="9">Movie</option>
<option value="11">Conference</option>
<option value="Select" selected="selected">Select</option>
</select>
</div> <span style=color:red></span>
</div>
</div>
This is my output image
There is a gap between button of a dropdown and input text(Right side gap of the text). How can I remove this gap?
But, I want to make this input form dropdown like as
No extra space of right side.
May be there is a style in your css for select or textarea.
Whatever, You can use this style for select.
.select,
textarea,
input[type="text"]{
padding:0px;
}
I hope you will success.So,Try it.