send a php variable as part of an html form - php

I am working on a website which I didn't create and to which I do not have full access (I can create a page and add html scripts but not much more)
I am trying to add a form which will send data to be processed by a third-party servlet.
I am trying to include in this form the client ID, which I saw can be retrieved using the php functionsession_id().
My question is, how to send this information along with the rest of the input data.
my form for now is this:
<form class="form-horizontal" action = "url" method="POST" target="_blank">
<fieldset>
<!-- Select Basic -->
<div class="form-group">
<label class="col-md-4 control-label" for="selectbasic">Culture</label>
<div class="col-md-4">
<select id="Crop" name="Crop" class="form-control">
<option value="1">Maïs</option>
<option value="2">Ble</option>
</select>
</div>
</div>
<!-- Select Basic -->
<div class="form-group">
<label class="col-md-4 control-label" for="selectbasic">Produit</label>
<div class="col-md-4">
<select id="Product" name="Product" class="form-control">
<option value="Iodure d'azote">Iodure D'azote</option>
<option value="Desherbant">Desherbant</option>
</select>
</div>
</div>
<!-- Text input-->
<div class="form-group">
<label class="col-md-4 control-label" for="area">Surface</label>
<div class="col-md-4">
<input id="Area" name="Area" type="text" placeholder=" " class="form-control input-md" required="">
<span class="help-block">en Ha</span>
</div>
</div>
<!-- Text input-->
<div class="form-group">
<label class="col-md-4 control-label" for="dose">Dosage</label>
<div class="col-md-4">
<input id="Dose" name="Dose" type="text" placeholder="" class="form-control input-md" required="">
<span class="help-block">en L/Ha</span>
</div>
</div>
<div class="form-group">
<!--need to get the actual id-->
<input type="hidden" value="1" name = "ID"/>
<input type="submit" value="Ajouter" />
</div>
</fieldset>
</form>
Since this is my first time handling web apps, is there something obvious i'm missing?

OK i was lacking basic understanding of php. sorry for bothering,
the answer was here
i just had to write
<input type="hidden" value="<?php echo session_id();?>" name = "ID"/>
instead of
<input type="hidden" value="1"name = "ID"/>

Related

GET-method don´t get the date in the URL

i have a Form with different inputs. Now I call GET and want to give all information to another site.
<form action="/listShifts" method="GET">
<div class="row">
<div class="m-1 col-sm-3">
<label class="control-label"><spring:message
code="shifts.startdate"/></label>
<input type="date" class="form-control" value="">
</div>
<div class="m-1 col-sm-3">
<label class="control-label"><spring:message
code="shifts.enddate"/></label>
<input type="date" class="form-control" value="">
</div>
<div class="m-1 col-sm-3">
<label class="control-label"><spring:message
code="shiftstatus.name"/></label>
<select name="stateId" class="form-control">
<option value=""><spring:message code="shifts.selectshiftstate"/></option>
<option value=""><spring:message code="shifts.allstates"/></option>
<c:forEach items="${states}" var="state">
<option value="${state.stateId}">${state.stateName}</option>
</c:forEach>
</select>
</div>
<button type="submit" class="mt-4 btn btn-outline-info align-self-center"><spring:message
code="shifts.filter2"/></button>
</form>
The state ID is written to the URL. The date not. How can i change this? Don´t know how to fix that problem.
You need to add name parameter to your inputs to submit through forms.
If you want to submit date, Just add name attribute to your date field.
<div class="m-1 col-sm-3">
<label class="control-label">
<spring:message code="shifts.startdate"/>
</label>
<input type="date" class="form-control" value="" name="start_date">
</div>
<div class="m-1 col-sm-3">
<label class="control-label">
<spring:message code="shifts.enddate"/>
</label>
<input type="date" class="form-control" value="" name="end_date">
</div>
Now, you are getting only state, Because you added name attribute only to your state dropdown.
<select name="stateId" class="form-control">
...

laravel show method not found exception when shortern URL link is passed in POST request

I have a laravel working directory on local. All forms are posting data on Local but only addshow form is not working on live. I came across that when I filled the link field with a google shortern URL. Laravel gives a method not allowed exception on submission of the form. Putting any other link beside shorten link works fine on live.
<form class="" role="form" method="post" action="{{ url('/addshow') }}">
{{ csrf_field() }}
<div class="box-body">
<div class="row">
<div class="col-sm-8">
<label for="name" class="col-sm-3 control-label">Title<span>*</span></label>
<div class="col-sm-9">
<input class="form-control" type="text" name="title" id="name" value="" placeholder="Enter Title"/>
</div>
</div>
</div>
<br/>
<div class="row">
<div class="col-sm-8">
<label for="name" class="col-sm-3 control-label">Place<span>*</span></label>
<div class="col-sm-9">
<input class="form-control" type="text" name="place" id="place" value="" placeholder="Enter place"/>
</div>
</div>
</div>
<br/>
<div class="row">
<div class="col-sm-8">
<label for="name" class="col-sm-3 control-label">Time<span>Start / End</span></label>
<div class="col-sm-4">
<input class="form-control" type="text" name="start_time" id="start_time" value="<?= date('h:m'); ?>" placeholder="Enter Start time"/>
</div>
<!-- <div class="col-sm-4 hidden-lg">
<input class="form-control" type="time" name="end_time" id="end_time" value="<?php// date('h:m'); ?>" placeholder="Enter End time"/>
</div> -->
</div>
</div>
<br/>
<div class="row">
<div class="col-sm-8">
<label for="name" class="col-sm-3 control-label">Date<span>*</span></label>
<div class="col-sm-9">
<input class="form-control" type="date" name="date" id="date" value="<?= date('y-m-20y') ?>" placeholder="Enter date"/>
</div>
</div>
</div>
<br/>
<div class="row">
<div class="col-sm-8">
<label for="name" class="col-sm-3 control-label">Link<span>*</span></label>
<div class="col-sm-9">
<input class="form-control" type="url" name="link" id="link" value="" placeholder="Enter Url"/>
</div>
</div>
</div>
<br/>
<div class="row">
<div class="col-sm-8">
<label for="status" class="col-sm-3 control-label">Status<span>*</span></label>
<div class="col-sm-9">
<select class="form-control" name="status">
<option value="1">Activated</option>
<option value="0">Deactivated</option>
</select>
</div>
</div>
</div>
</div>
<br/>
<!-- /.box-body -->
<div class="box-footer clearfix">
<div class="row">
<div class="col-sm-6">
<span class="pull-right">
<input class="btn btn-info" type="submit" name="Submit" id="Submit" value="Create" placeholder=""/>
</span>
</div>
</div>
</div>
</form>
plus this is route Route::post('/addshow', 'DashboardController#addshow');
public function addshow(Request $request) {
echo"<pre>";print_r($request->all());echo"</pre>";exit();
Shows::create($request->all());
return redirect(url('/allshows'));
}
for the time being validation and other stuff not including to keep it simple
this happens with me too the only solution i came accross that when i put the shortern URL it will give you method not found exception in most cases so simply allow user to enter only last 6 digits or alphabets of URL and save to database . only this way i solved this problem and hope you will find it helpfull . plus you should also see the collation from default to utf8_general_ci
The most critical piece of information that I can gather from your question is that you're getting a MethodNotAllowedHttpException which tells us that the specific issue is that the request is coming in using a different HTTP method than you have set the route up to handle.
From the code samples you have provided both your form and your route seem to use the POST method so it seems that submitting the form is not the cause of the issue. To be certain you could try adding a something like dd('test'); right at the start of your addshow method. If you still get the exception then it means either your form is not actually using the POST method or the route is incorrectly configured.
One alternative is that the MethodNotAllowedHttpException is not for /addshow. You mention that it appears when you add a Google shortened URL to the link field, does it appear when you enter other links? If so it could be that the Google shortened URL is failing validation and redirecting to a URL that does not use the GET method. It's impossible to say for certain without your validation code but it would be worth checking what URL your browser displays when you get the error screen.

Combine select dropdown with input text

I've read the other answers to my question regarding combining both the select and text fields, but when I try to apply any of the solutions to my form it does not work.
Can someone modify my form so that you end up with a dropdown containing both the select options and a text input field?
Please include the appropriate jquery script as well.
Here is my form code:
<form id="ajax-contact-form" action="drumming_for_jared_registration.php" method="post">
<div class="row">
<div class="span12">
<div class="control-group">
<label class="control-label" for="inputName">Date:</label>
<div class="controls">
<input class="span4" type="text" id="inputName" name="Date" placeholder="Date:" style="color:white" onBlur="if(this.value=='') this.value=''" onFocus="if(this.value =='Date:' ) this.value=''">
</div>
</div>
</div>
<div class="row"></div>
<div class="span4">
<div class="control-group">
<label class="control-label" for="inputName">New To Studio?</label>
<div class="controls">
<select input class="span14" type="text" id="inputLevel" name="New_to_Studio">
<option>New To Studio?</option>
<option>Yes</option>
<option>No</option>
</select>
</div>
</div>
</div>
<div class="row"></div>
</div>
<button type="submit" class="submit">Send</button>
</form>

Update Database tables with values input by user in CodeIgniter using PHP

I'm trying to update one of my user tables in the Database with values taken from the the user. But for some reason it's not updating anything.
HTML Form
<form class="form-horizontal" method = "post">
<fieldset>
<!-- Form Name -->
<legend>User Details</legend>
<div>
<?php echo $this->session->flashdata('msg'); ?>
</div>
<!-- Text input-->
<div class="form-group">
<label class="col-md-4 control-label" for="name">Full Name</label>
<div class="col-md-8">
<input id="name" name="name" type="text" placeholder="something" class="form-control input-md">
</div>
</div>
<!-- Text input-->
<div class="form-group">
<label class="col-md-4 control-label" for="dob">Date of Birth</label>
<div class="col-md-4">
<input id="dob" name="dob" type="text" placeholder="" class="form-control input-md">
</div>
</div>
<!-- Multiple Radios -->
<div class="form-group">
<label class="col-md-4 control-label" for="gender">Gender</label>
<div class="col-md-2">
<select id="gender" name="gender" class="form-control">
<option value="1">Male</option>
<option value="2">Female</option>
</select>
</div>
</div>
<!-- Text input-->
<div class="form-group">
<label class="col-md-4 control-label" for="degree">Degree</label>
<div class="col-md-8">
<input id="degree" name="degree" type="text" placeholder="degree" class="form-control input-md">
</div>
</div>
<!-- Text input-->
<div class="form-group">
<label class="col-md-4 control-label" for="specialization">Specialization</label>
<div class="col-md-8">
<input id="specialization" name="specialization" type="text" placeholder="specialization" class="form-control input-md">
</div>
</div>
<!-- Select Basic -->
<div class="form-group">
<label class="col-md-4 control-label" for="year">Degree Year</label>
<div class="col-md-2">
<select id="year" name="year" class="form-control">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
</select>
</div>
</div>
<!-- Select Basic -->
<div class="form-group">
<label class="col-md-4 control-label" for="semester">Semester</label>
<div class="col-md-2">
<select id="semester" name="semester" class="form-control">
<option value="1">1</option>
<option value="2">2</option>
</select>
</div>
</div>
<!-- File Button -->
<div class="form-group">
<label class="col-md-4 control-label" for="filebutton">Upload Profile Picture</label>
<div class="col-md-4">
<input id="filebutton" name="filebutton" class="input-file" type="file">
</div>
</div>
<!-- Button -->
<div class="form-group">
<label class="col-md-4 control-label" for="submit"></label>
<div class="col-md-4">
<a href="<?php echo base_url("/index.php/studentDashboardController/saveUserDetails"); ?>" >
<button id="submit" name="submit" class="btn btn-primary">Save Changes</button>
</a>
</div>
</div>
</fieldset>
studentDashboardController
public function saveUserDetails()
{
$this->load->model('userModel');
if (isset($this->session->userdata['logged_in']))
{
$username = ($this->session->userdata['logged_in']['username']);
}
$user = $this-> userModel-> getUserUid($username); //Gets the uid of the current user
$this->userModel->saveUserDetails($user);
$this->session->set_flashdata('msg', '<div class="alert alert-success text-center">Successfully Inserted Data</div>');
$this->load->view('studentDashboard/common',$data);
redirect(base_url('index.php/studentDashboard/editProfile',$data1));
}
userModel
public function saveUserDetails($uid)
{
$data = array(
'name' => $this->input->post('name')
);
$this->db->where("uid",$uid);
$this->db->update("sysuser",$data);
}
The sysuser has the uid and name fields.I' not sure what I'm doing wrong here. Any help in this regard will be appreciated
You dont send your post data to controller. Change $this->userModel->saveUserDetails($user); as
$this->userModel->saveUserDetails($user,$this->input->post('name'));
Now Model should be like
public function saveUserDetails($uid,$name)
{
$data = array(
'name' => $name
);
$this->db->where("uid",$uid);
$this->db->update("sysuser",$data);
}
and make sure you have set correctly form action like
<form class="form-horizontal" method="post" action="<?php echo site_url('studentDashboardController/saveUserDetails');?>">

HTML/Bootstrap form with Json API

I want to create a simple HTML form (ideally using bootstrap).
On this form some input elements are filled by the user(which is simple!) but I also need to call an API with json data to fill a drop down box. like list of countries,etc.
How can I implement API into a form?
thanks
<form class="form-horizontal">
<fieldset>
<!-- Form Name -->
<legend>My form</legend>
<!-- Text input-->
<div class="control-group">
<label class="control-label" for="title">Title</label>
<div class="controls">
<input id="title" name="title" type="text" placeholder="Article on Banking,etc." class="input-medium">
</div>
</div>
<!-- Select Basic -->
<div class="control-group">
<label class="control-label" for="Article Type">Article Type</label>
<div class="controls">
<select id="Article Type" name="Article Type" class="input-xlarge">
<option>ashkanarvaneh.co.uk/test/api.json</option>
</select>
</div>
</div>
<!-- Textarea -->
<div class="control-group">
<label class="control-label" for="summary">Summary</label>
<div class="controls">
<textarea id="summary" name="summary">Enthusiastically strategize superior infomediaries after clicks-and-mortar process improvements. Appropriately incubate stand-alone methodologies vis-a-vis pandemic potentialities. Authoritatively build.</textarea>
</div>
</div>
<!-- Button -->
<div class="control-group">
<label class="control-label" for="submit">Submit</label>
<div class="controls">
<button id="submit" name="submit" class="btn btn-primary">Submit</button>
</div>
</div>
</fieldset>
</form>
Try Example
<!-- Select Basic -->
<div class="control-group">
<label class="control-label" for="Article Type">Article Type</label>
<div class="controls">
<select id="Article Type" name="Article Type" class="input-xlarge">
<?php
$countries = file_get_contents("http://ashkanarvaneh.co.uk/test/api.json");
$countries = json_decode($countries, true);
foreach($countries as $country)
{
echo "<option value='".$country['Id']."'>".$country['Description']."</option>";
}
?>
<!--<option>http://publicapidev.chambersandpartners.com/api/taggedlocations</option>-->
</select>
</div>
</div>
Note The above code is tested & works fine.

Categories