Ok, so I have a partial contact form in the layout, and I'm trying to get the inputted data to pass to the full contact view form instead of submitting request via clicking the submit button. In my partial, it has name, email, and phone input. I want the info to populate the appropriate input and the remaining inputs in the full contact form and the rest to be blank waiting for users to input them. Then naturally on submit it sends out. the full contact form is already working, I just need to get this partial on the layout to work. The problem is it's redirecting it to a view that's a get method. I myself don't like this idea, but it's for my job and this is what they want. I would preferr to not have to make another view. This is what i have so far
the layout form:
{!! Form::open(array('url' => 'contact_index')) !!}
<div class="form-group">
{!! Form::label('Name:') !!}
{!! Form::text('name', null, ['class' => 'form-control', 'placeholder' => '', 'size' => '25']) !!}
</div>
<div class="form-group">
{!! Form::label('Email:') !!}
{!! Form::email('email', null, ['class' => 'form-control', 'placeholder' => '', 'size' => '25']) !!}
</div>
<div class="form-group">
{!! Form::label('Phone:') !!}
{!! Form::text('phone', null, ['class' => 'form-control', 'placeholder' => '', 'size' => '25']) !!}
</div>
<br/>
<div class="form_group">
{!! Form::submit('Submit', ['class' => 'btn btn-primary form-control']) !!}
</div>
{!! Form::close() !!}
this is the controller it redirects to
public function Index()
{
$email = Input::get('email');
$name = Input::get('name');
$phone = Input::get('phone');
session_start();
$_SESSION['name'] = $name;
$_SESSION['email'] = $email;
$_SESSION['phone'] = $phone;
return View('contact_views.Index',compact('email','name','phone'));
}
This is the view of the full contact:
{!! Form::open(array('url' => 'Contact')) !!}
<div class="form-group">
{!! Form::label('Email:') !!}
{!! Form::email('email', null, ['class' => 'form-control',
'placeholder' => '', value =>'$_SESSION['email']', size' => '25']) !!}
</div>
<div class="form-group">
{!! Form::label('Name:') !!}
{!! Form::text('name', null, ['class' => 'form-control', 'placeholder' => '',
value =>'$_SESSION['name']', 'size' => '25']) !!}
</div>
<div class="form-group">
{!! Form::label('Phone:') !!}
{!! Form::text('phone', null, ['class' => 'form-control', 'placeholder' => '',
value =>'$_SESSION['phone']', 'size' => '25']) !!}
</div>
<div class="form-group">
{!! Form::label('Subject:') !!}
{!! Form::text('subject', null, ['class' => 'form-control', 'placeholder' => '',
value =>'', 'size' => '25']) !!}
</div>
<div class="form-group">
{!! Form::label('Message:') !!}
{!! Form::textarea('message', null, ['class' => 'form-control', 'placeholder' => '',
value =>'', 'size' => '25x12']) !!}
</div>
<br/>
<div class="form_group">
{!! Form::submit('Submit', ['class' => 'btn btn-primary form-control']) !!}
</div>
{!! Form::close() !!}
As of now this is the error I'm getting FatalErrorException in b6da938076cfb151c583150cb7d0dec6 line 51:
syntax error, unexpected 'email' (T_STRING), expecting ']' .
You have an extra single quote on the line next to the "size" variable
'placeholder' => '', value =>'$_SESSION['email']', size' => '25']) !!}
Related
Here is my code:
controller file: EmergencyContactsController.php
$surnames = DB::table('salutations')->pluck('name');
return view('patient/emergencycontacts', ['salutation' => $surnames]);
Blade file: patient/emergencycontacts.blade.php
{!! Form::open(array('route' => 'emergencycontacts_store', 'class' => 'form')) !!}
<div class="form-group">
{!! Form::label('Salutation') !!}
{{ Form::select('role', ['' => 'Select Role'] + $salutation, null, ['class' => 'form-control']) }}
</div>
<div class="form-group">
{!! Form::label('First Name') !!}
{!! Form::text('firstname', null, array('required', 'class'=>'form-control', 'placeholder'=>'First Name')) !!}
</div>
<div class="form-group">
{!! Form::label('Last Name') !!}
{!! Form::text('lastname', null, array('required', 'class'=>'form-control', 'placeholder'=>'Last Name')) !!}
</div>
<div class="form-group">
{!! Form::label('Relationship') !!}
{{ Form::select('relationship', ['Father', 'Mother', 'Husband','Wife','Son','Daughter','Uncle','Aunty','Other']) }}
</div>
<div class="form-group">
{!! Form::label('Phone') !!}
{!! Form::text('phone', null, array('required', 'class'=>'form-control', 'placeholder'=>'Phone')) !!}
</div>
<div class="form-group">
{!! Form::label('Fax') !!}
{!! Form::text('fax', null, array('class'=>'form-control', 'placeholder'=>'Fax')) !!}
</div>
<div class="form-group">
{!! Form::submit('Save',array('class'=>'btn btn-primary')) !!}
</div>
{{ Form::close() }}
When I go to url http://localhost:8000/patient/emergency-contacts/create it gives me error:
"Unsupported operand types"
You need to change 2 things
In your controller:
$surnames = DB::table('salutations')->pluck('name', 'id')->toArray();
So you get an array as [id => 'value'] and not only ['value']. In the View:
{!! Form::select('role', $salutation, null, ['class' => 'form-control']) !!}
{!! Form::select('relationship', ['Father', 'Mother', 'Husband','Wife','Son','Daughter','Uncle','Aunty','Other']) !!}
{!! Form::close() !!}
Always 'escape' the Form tags, if not, the HTML will be printed on screen, not parsed.
please use view('patient.emergencycontacts', ['salutation' => $surnames]);
Am new in php laravel and am getting the following error when displaying a page that should be having a form
ErrorException in FormBuilder.php line 525: Undefined offset: 1 (View: E:\mysite\mysite\resources\views\predictions\create.blade.php)
Here is the form code:
#extends('layouts.master')
#section('content')
<h2>Create Predictions</h2>
{!! Form::open(array('route' => 'predictions.store')) !!}
<div class="form-group">
{!! Form::label('title')!!}
{!! Form::text('title',null, array('class' => 'form-control')) !!}
</div>
<div class="form-group">
{!! Form::label('body')!!}
{!! Form::textarea('body',null, array('class' => 'form-control', 'size' => '50*3')) !!}
</div>
{!! Form::token() !!}
{!! Form::submit(null, array('class' => 'btn btn-default')) !!}
{!! Form::close() !!}
Here is the formbuilder code with the exception:
protected function setQuickTextAreaSize($options)
{
$segments = explode('x', $options['size']);
return array_merge($options, ['cols' => $segments[0], 'rows' =>
$segments[1]]);
}
Thanks in advance
There is no size attribute for textarea input tag. Remove 'size' => '50*3' from below code
{!! Form::textarea('body',null, array('class' => 'form-control', 'size' => '50*3')) !!}
Use rows and cols attribute instead. Since I guess you're trying to set 3 rows and 50 columns as your textarea box size your code may like this:
{!! Form::textarea('body',null, array('class' => 'form-control', 'rows' => '3', 'cols' => '50')) !!}
My form.blade.php is sth like
<div class="form-group">
{!! Form::label('title', 'title :', ['class' => 'awesome']) !!}
{!! Form::text('product[title]', null, ['class' => 'form-control']) !!}
</div>
<div class="form-group">
{!! Form::label('description', 'description : ', ['class' => 'awesome']) !!}
{!! Form::text('product[description]', null, ['class' => 'form-control']) !!}
<div id="phone" class="form-group">
{!! Form::label('reference_id1', 'reference_id1 : ', ['class' => 'awesome']) !!}
{!! Form::text('product[reference_id1]', null, ['class' => 'form- control']) !!}
</div>
<div class="form-group">
{!! Form::label('category_id', 'category_id : ', ['class' => 'awesome']) !!}
{!! Form::select('category[]', $categories,null, ['class' => 'form- control', 'multiple']) !!}
</div>
<div class="form-group">
{!! Form::label('color', 'color : ', ['class' => 'awesome']) !!}
{!! Form::text('feature[0][color]', null, ['class' => 'form-control']) !!}
</div>
<div class="form-group">
{!! Form::label('height', 'height : ', ['class' => 'awesome']) !!}
{!! Form::text('feature[0][height]', null, ['class' => 'form-control']) !!}
</div> `
and my Edit.blade.php is like
{!! Form::model($product,['method' => 'PATCH', 'action' => ['ProductController#update',$product->id]]) !!}
#include('products.form', ['submitBtn' => 'submit'])
{!! Form::close() !!}
And this my ProductController.php#edit
public function edit($id)
{
$product = Product::with('feature')->findOrFail($id);
$categories = Category::pluck('title','id');
return view('products.edit')->withProduct($product)->withCategories($categories);
}
this is while when i wanna edit a product, the input requests are set empty!!
for instance when i go to http://myLarave/Public/product/2/edit the title and other inputs are empty :(
any suggestions?!
In your route.php or web.php depend to the version of your laravel, you can make the arg {id?}, for example:
Route::get('edit/{id?}', 'ProductController#edit');
and in the edit function you can initialize the variable $id=null or empty:
public function edit($id = null)
{
if($id != null){
$product = Product::with('feature')->findOrFail($id);
$categories = Category::pluck('title','id');
return view('products.edit')->withProduct($product)->withCategories($categories);
}
}
all I want is to define the form model on template and then put a yield as the content of form data. But it cannot assign the model data correctly into each field that has been defined.
This is my code:
template.detail.blade.php
#extends('admin.template.lte.layout.basic')
#section('content-page')
{!! Form::model($model, ['url' => $formAction]) !!}
#yield('data-form')
{!! Form::close() !!}
#if ($errors->any())
#stop
partial.edit.blade.php
#extends('template.detail')
#section('data-form')
<div class="form-group">
{!! Form::label('Dal_Name', 'Alternative Name', ['class' => 'required']) !!}
{!! Form::text('Dal_Name', null, ['required', 'class' => 'form-control', 'placeholder' => 'Enter Alternative Name']) !!}
</div>
<div class="form-group">
{!! Form::label('Dal_DssID', 'DSS Period', ['class' => 'required']) !!}
{!! Form::select('Dal_DssID', $dssOptions, null, ['class' => 'form-control']) !!}
</div>
<div class="checkbox">
<label for="Dal_Active">
{!! Form::hidden('Dal_Active', 'N') !!}
{!! Form::checkbox('Dal_Active', 'Y') !!}
Active
</label>
</div>
#stop
My Controller part:
/**
* Show the form for editing the specified resource.
*
* #param int $id
*
* #return \Illuminate\Http\Response
*/
public function edit($id)
{
$this->data['model'] = DssAlternative::find($id);
$this->data['formAction'] = \Request::current();
$this->data['dssOptions'] = Dss::lists('Dss_Name', 'Dss_ID');
return view('partial.edit', $this->data);
}
But the model data does not propagate to form correctly.
Sorry for my bad english.
It won't work since you are passing the $model object to partial/edit.blade.php file, and hoping to use it within template/detail.blade.php
exactly at this line
{!! Form::model($model, ['url' => $formAction]) !!}
Solution:
in template/detail.blade.php Take the form model line inside like this:
#extends('admin.template.lte.layout.basic')
#section('content-page')
#yield('data-form')
#if ($errors->any())
#stop
So partial/edit.blade.php would be like below:
#extends('template.detail')
#section('data-form')
{!! Form::model($model, ['url' => $formAction]) !!}
<div class="form-group">
{!! Form::label('Dal_Name', 'Alternative Name', ['class' => 'required']) !!}
{!! Form::text('Dal_Name', null, ['required', 'class' => 'form-control', 'placeholder' => 'Enter Alternative Name']) !!}
</div>
<div class="form-group">
{!! Form::label('Dal_DssID', 'DSS Period', ['class' => 'required']) !!}
{!! Form::select('Dal_DssID', $dssOptions, null, ['class' => 'form-control']) !!}
</div>
<div class="checkbox">
<label for="Dal_Active">
{!! Form::hidden('Dal_Active', 'N') !!}
{!! Form::checkbox('Dal_Active', 'Y') !!}
Active
</label>
</div>
{!! Form::close() !!}
#stop
I am new to Vue.js and I want to render a form element only if another form select field is selected. I hope you understand what I mean.
Here st my Laravel Form:
<div class="form-group">
{!! Form::label('mailarchive', 'Mailarchive: ', ['class' => 'col-sm-3 control-label']) !!}
<div class="col-sm-6">
{!! Form::select('mailarchive', ['-' => 'No', 'Gold' => 'Gold', 'Silver' => 'Silver', 'Bronze' => 'Bronze'], null, ['class' => 'form-control']) !!}
</div>
</div>
<div class="form-group">
{!! Form::label('instance', 'Instance: ', ['class' => 'col-sm-3 control-label']) !!}
<div class="col-sm-6">
{!! Form::select('mailarchive', ['Select' => 'Select', '1' => 'SV01', '2' => 'SV02'], null, ['class' => 'form-control']) !!}
</div>
</div>
The second form-group (label: instance) should only be visible when 'Gold', 'Silver' or 'Bronze' in the first select field is selected, but not visible if 'No' is selected.
Thanks for your help!
Wipsly
// Update
I edited my code to this
<div class="form-group">
{!! Form::label('mailarchive', 'Mailarchive: ', ['class' => 'col-sm-3 control-label']) !!}
<div class="col-sm-6">
{!! Form::select('mailarchive', ['-' => 'No', 'Gold' => 'Gold', 'Silver' => 'Silver', 'Bronze' => 'Bronze'], null, ['class' => 'form-control v-model="mailarchive"']) !!}
</div>
</div>
<div class="form-group v-show="mailarchive !='-'"">
{!! Form::label('instance', 'Instance: ', ['class' => 'col-sm-3 control-label']) !!}
<div class="col-sm-6">
{!! Form::select('mailarchive', ['Select' => 'Select', '1' => 'SV01', '2' => 'SV02'], null, ['class' => 'form-control']) !!}
</div>
</div>
And here is my javascript
<script type="text/javascript">
new Vue({
el: '#mailarchive'
})
</script>
But nothing happens. What do I wrong?
A lot to tackle here. First, you should set a "parent" Vue instance rather than creating a new Vue instance for individual input fields. For example, lets say you want to make the entire form a Vue instance, then when you open your form, set an id like this:
{!! Form::open(['id' => 'example']) !!}
Then, when you create your Vue instance, reference that id:
<script type="text/javascript">
new Vue({
el: '#example'
})
</script>
Next, this code you have is incorrect:
{!! Form::select('mailarchive', ['-' => 'No', 'Gold' => 'Gold', 'Silver' => 'Silver', 'Bronze' => 'Bronze'], null, ['class' => 'form-control v-model="mailarchive"']) !!}
Specifically, pay attention to this part: ['class' => 'form-control v-model="mailarchive"']
What you are doing here is creating some weird class. When you specify extra HTML attributes, you need to pass an array of those attributes like this:
{!! Form::select('mailarchive', ['-' => 'No', 'Gold' => 'Gold', 'Silver' => 'Silver', 'Bronze' => 'Bronze'], null, ['class' => 'form-control', 'v-model' => 'mailarchive']) !!}
From there, another problem is how you are using v-show.
This is what you have: <div class="form-group v-show="mailarchive !='-'"">
Once again, for some reason, you are putting v-directives inside your class. Instead, use it as its own HTML attribute like this:
<div class="form-group" v-show="mailarchive !== '-'">
All that together, you should see something like this:
{!! Form::open(['id' => 'example']) !!}
<div class="form-group">
{!! Form::label('mailarchive', 'Mailarchive: ', ['class' => 'col-sm-3 control-label']) !!}
<div class="col-sm-6">
{!! Form::select('mailarchive', ['-' => 'No', 'Gold' => 'Gold', 'Silver' => 'Silver', 'Bronze' => 'Bronze'], null, ['class' => 'form-control', 'v-model' => 'mailarchive']) !!}
</div>
</div>
<div class="form-group" v-show="mailarchive !== '-'">
{!! Form::label('instance', 'Instance: ', ['class' => 'col-sm-3 control-label']) !!}
<div class="col-sm-6">
{!! Form::select('mailarchive', ['Select' => 'Select', '1' => 'SV01', '2' => 'SV02'], null, ['class' => 'form-control']) !!}
</div>
</div>
{!! Form::submit() !!}
{!! Form::close() !!}
</div>
<script>
new Vue({
el: '#example'
});
</script>
Here is a working example on jsfiddle: http://jsfiddle.net/zj8hwjc9/1/
You will need to bind the first field to a var with v-model="mailArchive" then on the second form group use v-show="mailArchive !='-'"