Route [method] not defined - laravel-5.1

I am creating a form to insert data into database.version laravel5.1 but my code is not working.
resources\views\login.blade.php
<!-- Registration Form -->
<form action="{{ URL::route('postform_registration') }}" role="form" id="login_popup_form" method="post" name="login_popup_form">
<input type="hidden" name="_token" value="{{ csrf_token() }}">
<img id="close" src="{{ URL::asset('tradextek/img/close_irtiza.png') }}" alt="" onclick ="div_hide()">
<h2>Registration</h2>
<hr>
<div class="form-group">
<label for="">Your Email</label>
<input type="text" class="form-control" id="login_popup_email" name="login_popup_email" placeholder="Email" type="text">
</div>
<hr>
<div class="form-group">
<label for="">Your Password</label>
<input type="password" class="form-control"id="login_popup_password" name="login_popup_password" placeholder="Password...">
</div>
<hr>
<button type="submit" onclick="check_empty()" class="btn btn-primary">Submit</button>
</form>
<h3>
<?php
if(Session::has('key')){
echo Session::get('key');
}
?>
</h3>
routes.php
Route::post('/login',array(
'as' => 'postform',
'uses' => 'all_control#postform'
));
Route::post('/login',array(
'url' => 'postform_registration',
'uses' => 'all_control#postform_registration'
));
app/controllers/all_control
public function postform_registration(Request $request)
{
$email = $request->login_popup_email;
$password = $request->login_popup_password;
return redirect('login')->with('key', 'You have inserted successfully');
}
Error message
1)ErrorException in UrlGenerator.php line 296:
Route [postform] not defined. (View: C:\xampp\htdocs\project\resources\views\login.blade.php)
2)InvalidArgumentException in UrlGenerator.php line 296:
Route [postform] not defined.

By seeing this code, i guess that,there are two possibilities for your error.
in routes.php you have defined:
Route::post('/login',array(
'as' => 'postform',
'uses' => 'all_control#postform'
));
Route::post('/login',array(
'url' => 'postform_registration',
'uses' => 'all_control#postform_registration'
));
I can't understand why you have different routes entry for same url and same HTTP method in your case POST.
and you have defined POST method for routes
Route::post('/login',array(
'as' => 'postform',
'uses' => 'all_control#postform'
));
and other side you are passing GET Reqest from controller.
and second points:
Have you defined postform in all_control.php?

Related

Dynamic name for react-final-form Field

I have 2 forms. When I choose an option on 1st form, the 2nd form is added to the page with the parameters retrieved from backend. Now how can I set the parameter names as react-final-form Field names?
I could not find a way to do this. Where to pass the parameter names?
<Form
onSubmit={onSubmit}
validate={validate}
React Final Form calls your onSubmit function with the values from all the fields in your form. It's totally up to you to transmit the values to your server.
If you're asking how to build the second form, you just add the fields you need to add. So, say you got back from the server that you needed three fields: [ 'name', 'startTime', 'endTime' ]. You'd just loop through that array and add the fields.
<Form onSubmit={onSubmit}>({handleSubmit}) => (
<form onSubmit={handleSubmit}>
{fieldsFromServer.map(fieldName => (
<div key={fieldName}>
<label>{fieldName}</label>
<Field name={fieldName} component="input"/>
</div>
))}
</form>
)}<Form>
Does that help? You don't have to "pass parameters to the form", you just add the Field components that you need.
Call the FinalForm like
<FinalFieldArrayForm onSubmit={this.handleSubmitTemplate} fieldsFromServer={parameters} />
and FinalForm is
import React from "react";
import ReactDOM from "react-dom";
import { Form, Field } from 'react-final-form'
import arrayMutators from 'final-form-arrays'
import { FieldArray } from 'react-final-form-arrays'
import "./styles.css";
const FinalForm = ({onSubmit, fieldsFromServer}) => (
<Form
onSubmit={onSubmit}
mutators={{
// potentially other mutators could be merged here
...arrayMutators
}}
render={({
handleSubmit,
form: {
mutators: { push, pop }
},
pristine,
form,
submitting,
values
}) => (
<form onSubmit={handleSubmit}>
<div className="buttons">
<button type="button" onClick={() => push('records', undefined)}>+</button>
<button type="button" onClick={() => pop('records')}>-</button>
<button type="button" onClick={form.reset} disabled={submitting || pristine}>Reset</button>
</div>
<FieldArray name="records">
{ ({fields}) => (
<div>
{fields.map( (name, index) => (
<div key={`${name}.${index}`}>
<label>{index + 1}</label>
{fieldsFromServer.map( param => <Field key={`${name}.${param}`} name={`${name}.${param}`} component="input" placeholder={`${name}.${param}`} /> )}
<button type="button" onClick={() => fields.remove(index)}>-</button>
<button type="button" onClick={() => fields.insert(index+1)}>+</button>
</div>
))}
</div>
)}
</FieldArray>
<div className="buttons">
<button type="submit" disabled={submitting || pristine}>Submit</button>
</div>
<pre>{JSON.stringify(values, 0, 2)}</pre>
</form>
)}
/>
)
const rootElement = document.getElementById("root");
ReactDOM.render(<FinalForm onSubmit={() => (<div/>)} fieldsFromServer={["firstName", "lastName"]} />, rootElement);

Gridmvc filtering without query in url

I'm using GridMvc and I'm filtering data. I'd like to hide filter query in the url like http://www.mypage.com/Overview?Name=yyy
My form is defined as:
<form class="form-inline" method="POST" action="#Url.Action("Filter", Request.QueryString)">
<div class="form-group>
#Html.LabelFor(c => c.Name)
#Html.TextBoxFor(c => c.Name, new { placeholder = "Filter", #class = "form-control" })
<button type="submit" class="btn btn-default"><i class="glyphicon glyphicon-search"></i> Search</button>
</div>
</form>
And the action
[HttpPost]
public ActionResult Filter(FilterModel model)
But I always see the query. It's possible to hide query string?
You cound hide your query if you put all you data in hidden fields instead of Request.QueryString.
I mean if your Request.QueryString looks like param1=test1&param2=test2 you should render you view like this:
<form class="form-inline" method="POST" action="#Url.Action("Filter")">
<input type="hidden" name="param1" value="test1" />
<input type="hidden" name="param2" value="test2" />
<div class="form-group>
#Html.LabelFor(c => c.Name)
#Html.TextBoxFor(c => c.Name, new { placeholder = "Filter", #class = "form-control" })
<button type="submit" class="btn btn-default"><i class="glyphicon glyphicon-search"></i> Search</button>
</div>
</form>
MVC binding will bind all hidden values on POST according to name property of this hidden inputs.
You should just fill inputs value (replace test1 and test2 with your values from Request.QueryString)

isvalid() function in symfony always give false

I have created a form and i am using validation on it but whenever i click on submit it not redirect and shows the same page.Even i have set the default values then also no help.
please help me.
Even i have check on varuious form no help.
registration form class
class registrationform extends sfForm {
//put your code here
protected static $option=array('Lab Technician','Lecturur','Assistant Professor','Professor','H.O.D');
public function configure() {
$this->setWidgets(array(
'first_Name'=>new sfWidgetFormInputText(array('default'=>'hello'),array('class' => 'textView'),array('default'=>'hello')),
'middle_Name'=>new sfWidgetFormInputText(array('default'=>'hello'),array('class' => 'textView')),
'last_Name'=>new sfWidgetFormInputText(array('default'=>'hello'),array('class'=>'textView')),
'age'=>new sfWidgetFormInputText(array('default'=>'hello'),array('class'=>'textView')),
));
$this->setValidators(array(
'first_Name' => new sfValidatorString(array('required' => 'The message field is required.')),
'middle_Name' => new sfValidatorString(array('required' => 'The message field is required.')),
'last_Name' => new sfValidatorString(array('required' => 'The message field is required.')),
'age' => new sfValidatorString(array('required' => 'The message field is required.')),
));
$this->widgetSchema->setNameFormat('contact[%s]');
}
****action.class.php****
this is a class i which i am having my action class code.
public function executeIndex(sfWebRequest $request)
{
// $this->forward('default', 'module');
$this->registration_form = new registrationform();
if ($request->isMethod('POST'))
{
$this->registration_form->disableLocalCSRFProtection();
$this->registration_form->bind($request->getParameter('contact'));
if (!($this->registration_form->isValid()))
{
echo"\hiol";
$this->redirect('registration/thankyou?'.http_build_query($this->registration_form->getValues()));
}
}
indexsuccess
<?php echo stylesheet_tag('form');?>
<div class="page">
<div class="form" >
<form action="<?php echo url_for('registration/index') ?>" method="POST">
<div class="row" id="head">
REGISTRATION FORM
</div>
<div class="row">
<div class="columnLabel"><?php echo $registration_form['first_Name']->renderLabel()?></div>
<div class="columnView"><?php echo $registration_form['first_Name']->render()?></div>
</div>
<div class="row">
<div ><?php echo $registration_form['first_Name']->renderError()?></div>
</div>
<div class="row">
<div class="columnLabel" ><?php echo $registration_form['middle_Name']->renderLabel()?></div>
<div class="columnView" ><?php echo $registration_form['middle_Name']->render()?></div>
</div>
<div class="row">
<div class="columnLabel"><?php echo $registration_form['last_Name']->renderLabel()?></div>
<div class="columnView"><?php echo $registration_form['last_Name']->render()?></div>
</div>
<div class="row">
<div class="columnLabel"><?php echo $registration_form['age']->renderLabel()?></div>
<div class="columnView"><?php echo $registration_form['age']->render()?></div>
</div>
<div class="row">
<div class="columnLabel"><input class="button" type="submit" value="submit" name="submit"></div>
</div>
</form>
</div>
<!-- </div>
</div>
</div>
</div>
</div>-->
Your action class is not saving the form if it's valid. You should save and redirect if the form is valid:
if ($this->registration_form->isValid())
{
$this->registration_form->save();
$this->redirect('registration/thankyou');
}
If you need the form value on the next page, don't pass them in url, but flash instead:
$this->getUser()->setFlash('registration_form', $this->registration_form->getValues());

MVC4 C# multiple Forms one page validations

I've got 3 forms on one view on mvc project like this"
VIEW:
<div>
<fieldset>
<legend>Deposit Money</legend>
<div>#Html.LabelFor(u=>u.AccountNumber1)</div>
<div>#Html.DropDownList("Accounts", "-- Select Account --")
</div>
<div>#Html.LabelFor(u=>u.Amount)</div>
<div>#Html.TextBoxFor(u => u.Amount,new {style = "width:150px"})
#Html.ValidationMessageFor(u => u.Amount)
</div>
<div>#Html.LabelFor(u=>u.Comment)</div>
<div>#Html.TextAreaFor(u => u.Comment,new {style = "width:250px"})
#Html.ValidationMessageFor(u => u.Comment)
</div>
<input type="submit" value ="Submit" />
<input type="reset" value ="Clear" />
</fieldset>
</div>
}
</div>
<div id="middlepanel" style="position:absolute;left:33%;right:33%;">
#using (Html.BeginForm("Withdrawal", "ATM", FormMethod.Post, new { }))
{
#Html.ValidationSummary(true,"Deposit Failed. Check Your Details");
<div>
<fieldset>
<legend>Withdraw Money</legend>
<div>#Html.LabelFor(u=>u.AccountNumber1)</div>
<div>#Html.DropDownList("Accounts", "-- Select Account --")
</div>
<div>#Html.LabelFor(u=>u.Amount)</div>
<div>#Html.TextBoxFor(u => u.Amount,new {style = "width:150px"})
#Html.ValidationMessageFor(u => u.Amount)
</div>
<div>#Html.LabelFor(u=>u.Comment)</div>
<div>#Html.TextAreaFor(u => u.Comment,new {style = "width:250px"})
#Html.ValidationMessageFor(u => u.Comment)
</div>
<input type="submit" value ="Submit" />
<input type="reset" value ="Clear" />
</fieldset>
</div>
}
</div>
<div id="rightpanel" style="position:absolute;right:0;width:33%;">
#using (Html.BeginForm("Transfer", "ATM", FormMethod.Post, new { }))
{
#Html.ValidationSummary(true,"Deposit Failed. Check Your Details");
<div>
<fieldset>
<legend>Transfer Money</legend>
<div>#Html.LabelFor(u=>u.AccountNumber1)</div>
<div>#Html.DropDownList("Accounts", "-- Select Account --")
</div>
<div>#Html.LabelFor(u=>u.AccountNumber2)</div>
<div>#Html.DropDownList("Accounts", "-- Select Account --")
</div>
<div>#Html.LabelFor(u=>u.Amount)</div>
<div>#Html.TextBoxFor(u => u.Amount,new {style = "width:150px"})
#Html.ValidationMessageFor(u => u.Amount)
</div>
<div>#Html.LabelFor(u=>u.Comment)</div>
<div>#Html.TextAreaFor(u => u.Comment,new {style = "width:250px"})
#Html.ValidationMessageFor(u => u.Comment)
</div>
<input type="submit" value ="Submit" />
<input type="reset" value ="Clear" />
</fieldset>
</div>
}
</div>
in my controller, I am processing each of the above functionality.
However when one of the forms have an error (i.e blank field)
error is displayed on all the forms (validationSummary)
how can I build invidual errors per form?
Consider using partial views for each forms and call your partial view in your main view using
#Html.Partial("PartialViewName")

How to put special tags for each form element?

I have form with fields:
$this -> add(
array(
'name' => 'firstfield',
'attributes' => array(
'type' => 'text',
'id' => 'id_firstfield'
),
'options' => array(
'label' => 'firstfield'
),
)
);
$this -> add(
array(
'name' => 'secondfield',
'attributes' => array(
'type' => 'text',
'id' => 'id_secondfield'
),
'options' => array(
'label' => 'secondfield'
),
)
);
when I use:
echo $this->formCollection($form);
in my view, I get:
[...]
<label for="id_firstfield">first field</label>
<input name="firstfield" type="text" id="id_firstfield" value="">
<label for="id_secondfield">second field</label>
<input name="secondfield" type="text" id="id_secondfield" value="">
[...]
but I want to get:
[...]
<div id="divforfirstfield">
<label for="id_firstfield">first field</label>
<input name="firstfield" type="text" id="id_firstfield" value="">
</div>
<div id="divforsecondfield">
<label for="id_secondfield">second field</label>
<input name="secondfield" type="text" id="id_secondfield" value="">
</div>
[...]
How to do this?
Using the formCollection() this is not possible. However you can do it like this:
<div id="firstid">
<?php echo $this->formRow($form->get('firstfield')); ?>
</div>
<div id="secondid">
<?php echo $this->formRow($form->get('secondfield')); ?>
</div>
If you want to have the comfort of just one function call to render the form, you'll have to extend the formCollection() view helper with one of your own who do this.

Resources