Laravel 5.2 PHPUnit LogicException: The selected node does not have a form ancestor - laravel

Hi I have this view.
#extends('layouts.app')
#section('title', 'Register')
#section('content')
<!--BEGIN CONTENT-->
<div id="content">
<div class="content">
<div class="breadcrumbs">
Home
<img src="images/marker_2.gif" alt=""/>
<span>Register</span>
</div>
<div class="main_wrapper">
<div class="sell_box sell_box_5">
<h2><strong>Customer</strong> details</h2>
<form name="register" method="post" action="{{ url('/register') }}" enctype="multipart/form-data">
{{ csrf_field() }}
<div class="input_wrapper">
<label><span>* </span><strong>Nama lengkap: </strong></label>
<input type="text" class="txb" value="" name="full_name"/>
</div>
<div class="input_wrapper">
<label><span>* </span><strong>Alamat lengkap: </strong></label>
<input type="text" class="txb" value="" name="address"/>
</div>
<div class="input_wrapper">
<label><span>* </span><strong>Telepon: </strong></label>
<input type="text" class="txb" value="" name="phone"/>
</div>
<div class="input_wrapper">
<label><span>* </span><strong>Upload Identitas (KTP/SIM):</strong></label>
<input type="file" class="txb" name="idcard"/>
</div>
<div class="input_wrapper">
<label><span>* </span><strong>E-mail: </strong></label>
<input type="text" class="txb" value="" name="email"/>
</div>
<div class="input_wrapper">
<label><span>* </span><strong>Password:</strong></label>
<input type="password" class="txb" value="" name="password"/>
</div>
<div class="input_wrapper last">
<label><span>* </span><strong>Password Confirmation:</strong></label>
<input type="password" class="txb" name="password_confirmation"/>
</div>
<div class="input_wrapper">
<label><span>* </span><strong>Nama saudara tidak serumah: </strong></label>
<input type="text" class="txb" value="" name="family_name"/>
</div>
<div class="input_wrapper">
<label><span>* </span><strong>Alamat saudara tidak serumah: </strong></label>
<input type="text" class="txb" value="" name="family_address"/>
</div>
<div class="input_wrapper">
<label><span>* </span><strong>Telepon saudara tidak serumah: </strong></label>
<input type="text" class="txb" value="" name="family_phone"/>
</div>
<div class="clear"></div>
</div>
<div class="sell_submit_wrapper">
<!--
<span class="custom_chb_wrapper fL">
<span class="custom_chb">
<input type="checkbox" name=""/>
</span>
<label>I agree to the Terms and Conditions</label>
</span>
-->
<input type="submit" value="Submit" class="sell_submit"/>
<div class="clear"></div>
</div>
</form>
</div>
</div>
</div>
<!--EOF CONTENT-->
#endsection
This below test method, success pass unit test
public function testNewUserRegistration(){
$this->visit('/register')->see('Submit');
}
But with this below method, I get the following error 1) RegistrationTest::testNewUserRegistration
LogicException: The selected node does not have a form ancestor.
public function testNewUserRegistration(){
$this->visit('/register')->press('Submit');
}
Why this test fail? It can see Submit but can't press Submit.
I read some article it indicate something wrong with the HTML but I don't know which one is wrong because I think nothing wrong with my HTML code.
Any help appreciated.

Related

Selection variable expressions fields are not working in Thymeleaf

I properly define everything in my back end file. When I try to use
the back end variables in Thymeleaf by using selection variable
expression it is not working. It show errors in every field:
cannot resolve field name
register.html
<!doctype html "http://www.thymeleaf.org/dtd/xhtml1-strict-thymeleaf-4.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:th="http://www.thymeleaf.org">
<head th:replace="/fragments/head"></head>
<body>
<nav th:replace="/fragments/nav :: nav-front"></nav>
<div class="container-fluid mt-5">
<div class="row">
<div th:replace="/fragments/categories"></div>
<div class="col"></div>
<div class="col-6">
<h3 class="display-4">Register</h3>
<form method="post" th:object="${user}" th:action="#{/register}" >
<div th:if="${#fields.hasErrors('*')}" class="alert alert-danger">
There are errors
</div>
<div class="form-group">
<label for>Username:</label>
<input type="text" class="form-control" th:field="*{username}" placeholder="Username">
<span class="error" th:if="${#fields.hasErrors('username')}" th:errors="*{username}"></span>
</div>
<div class="form-group">
<label for>Password:</label>
<input type="password" class="form-control" th:field="*{password}">
<span class="error" th:if="${#fields.hasErrors('password')}" th:errors="*{password}"></span>
</div>
<div class="form-group">
<label for>Confirm Password:</label>
<input type="password" class="form-control" th:field="*{confirmPassword}">
<span class="error" th:if="${passwordMatchProblem}">Passwords do not match</span>
</div>
<div class="form-group">
<label for>E-mail:</label>
<input type="email" class="form-control" th:field="*{email}" placeholder="E-mail" required>
<span class="error" th:if="${#fields.hasErrors('email')}" th:errors="*{email}"></span>
</div>
<div class="form-group">
<label for>Phone number:</label>
<input type="text" class="form-control" th:field="*{phoneNumber}" placeholder="Phone number">
<span class="error" th:if="${#fields.hasErrors('phoneNumber')}" th:errors="*{phoneNumber}"></span>
</div>
<button class="btn btn-danger mb-5">Register</button>
</form>
</div>
<div class="col"></div>
</div>
</div>
<div th:replace="/fragments/footer"></div>
</body>
</html>
I get errors everywhere I use the selection expression field.
Are you adding "user" to your model in your controller?
You need to add it to your model so Thymeleaf can access it.
addAttribute method can be used like so: model.addAttribute("user", myUser);

PHP Laravel Post action

I have a form page for users informations update but my post function isn't working.I have defined a post method in the blade page and I show the page as a formaction post.This is my code;
#extends('layouts.admin-master')
#section('content')
<form action="post">
<div class="form-row">
<div class="form-group">
<label for="inputAddress2">Ad Soyad</label>
<input type="text" class="form-control" id="inputAddress2" name="name" value="{{ Auth::user()->name }}">
</div>
<br><br>
<div class="form-group">
<label for="inputAddress2">Şirket</label>
<input type="text" class="form-control" id="inputAddress2" name="company">
</div>
</div>
<div class="form-group">
<label for="inputAddress">Email</label>
<input type="text" class="form-control" id="inputAddress" name="email" value="{{ Auth::user()->email }}">
</div>
<div class="form-group">
<label for="inputAddress2">Telefon</label>
<input type="text" class="form-control" id="inputAddress2" name="phone">
</div>
<div class="form-row">
<div class="form-group col-md-4">
<label for="inputState">Üyelik Tipi</label>
<select id="inputState" class="form-control">
<option selected>Seçenekler</option>
<option>Bronz Üyelik</option>
<option>Silver Üyelik</option>
<option>Gold Üyelik</option>
</select>
</div>
<div class="form-group col-md-2">
<label class="radio-container m-r-55">Tedarikçi
<input type="radio" checked="checked" name="secim" value="tedarikci">
<span class="checkmark"></span>
</label>
`enter code here` <label class="radio-container">Alıcı
<input type="radio" name="secim" value="alici">
<span class="checkmark"></span>
</label>
</div>
</div>
<form action="{{route('form.add')}}" method="post" enctype="multipart/form-data">
<button type="submit" class="btn btn-primary">Kaydet</button>
</form>
</form>
#endsection
try this:
#extends('layouts.admin-master')
#section('content')
<form action="{{route('form.add')}}" method="post" enctype="multipart/form-data">
<div class="form-row">
<div class="form-group">
<label for="inputAddress2">Ad Soyad</label>
<input type="text" class="form-control" id="inputAddress2" name="name" value="{{ Auth::user()->name }}">
</div>
<br><br>
<div class="form-group">
<label for="inputAddress2">Şirket</label>
<input type="text" class="form-control" id="inputAddress2" name="company">
</div>
</div>
<div class="form-group">
<label for="inputAddress">Email</label>
<input type="text" class="form-control" id="inputAddress" name="email" value="{{ Auth::user()->email }}">
</div>
<div class="form-group">
<label for="inputAddress2">Telefon</label>
<input type="text" class="form-control" id="inputAddress2" name="phone">
</div>
<div class="form-row">
<div class="form-group col-md-4">
<label for="inputState">Üyelik Tipi</label>
<select id="inputState" class="form-control">
<option selected>Seçenekler</option>
<option>Bronz Üyelik</option>
<option>Silver Üyelik</option>
<option>Gold Üyelik</option>
</select>
</div>
<div class="form-group col-md-2">
<label class="radio-container m-r-55">Tedarikçi
<input type="radio" checked="checked" name="secim" value="tedarikci">
<span class="checkmark"></span>
</label>
`enter code here` <label class="radio-container">Alıcı
<input type="radio" name="secim" value="alici">
<span class="checkmark"></span>
</label>
</div>
</div>
<button type="submit" class="btn btn-primary">Kaydet</button>
</form>
put this line in your form and it should work :
{{csrf_field()}}
and make sure that your route address is correct too
u can add #csrf above the button

Comment Store in Laravel Redirecting to Home Page

I have a comment form in a page when I submit this form it's redirecting to the home page.
Routes
Route::get('/post/{slug}', 'API\PostController#show')->name('post.show');
Route::post('/post/{slug}', 'API\PostController#addComment')->name('post.comment');
Route::get('{path}',"HomeController#index")->where( 'path', '([A-z\d-\/_.]+)?' );
Blade
<form action="{{route('post.comment',$currentPost->slug)}}" method="POST">
<div class=" row blog-form">
{{csrf_field()}}
<div class="frm_grp col-md-6">
<input type="text" name="name" placeholder="Name"/>
</div>
<div class="frm_grp col-md-6">
<input type="text" name="email" placeholder="Email"/>
</div>
<div class="frm_grp col-md-12">
<input type="text" name="website" placeholder="Website"/>
</div>
<div class="frm_grp col-md-12">
<textarea name="message" placeholder="Message"></textarea>
</div>
<div class="frm_grp col-md-12">
<input type="submit" value="Post Comment"/>
</div>
</div>
</form>

Square Connect Validate Fields

I set up square connect api and my form submits just fine. My problem is I am trying to submit the payment and also email additional information to myself. If everything gets filled out then the code works perfectly but When I call requestCardNonce(event); it only requires the fields to generate the Nonce to be filled in and not the rest of the fields even tho I have them as required. If i remove requestCardNonce(event); all fields are required like they should be. Is there a way i can get validation on all of my fields to work with square connect api?
<form id="nonce-form" action="include/process-card.php" method="post">
<div class="sec1crt-frmlft">
<div class="form-container">
<div class="form-top">
<div class="form-toplft">
<center><img src="images/hdng-icon1.png" class="hdng-icon"></center>
</div>
<div class="form-toprgt">
<p class="txt2-chk">Billing Information</p>
</div>
</div>
<div class="form-content1">
<div class="frmelements">
<label for="FirstName">First Name<span>*</span></label>
<div class="field">
<div class="icon-box">
<center><img src="images/frmicon1.png"></center>
</div>
<input type="text" name="FirstName" class="ft-input" autocomplete="off" id="FirstName" required/>
</div>
</div>
<div class="frmelements">
<label for="LastName">Last Name<span>*</span></label>
<div class="field">
<div class="icon-box">
<center><img src="images/frmicon1.png"></center>
</div>
<input type="text" name="LastName" class="ft-input" autocomplete="off" id="LastName" required/>
</div>
</div>
<div class="frmelements">
<label for="Email">Email <span>*</span> </label>
<div class="field">
<div class="icon-box">
<center><img src="images/frmicon3.png"></center>
</div>
<input type="text" name="Email" class="ft-input" autocomplete="off" id="Email"
pattern="[a-z0-9._%+-]+#[a-z0-9.-]+\.[a-z]{2,3}$" required/>
</div>
</div>
<div class="frmelements">
<label for="Address">Address<span>*</span></label>
<div class="field">
<div class="icon-box">
<center><img src="images/frmicon5.png"></center>
</div>
<input type="text" name="Address" class="ft-input" autocomplete="off" id="Address" required/>
</div>
</div>
<div class="frmelements short1">
<label for="State">State<span>*</span></label>
<div class="field">
<div class="icon-box">
<center><img src="images/frmicon7.png"></center>
</div>
<select name="State" class="ft-input" id="State" class="required" required>
<option value="" onclick="" selected="">Select State</option>
<option value="AL" onclick="">REMOVED TO SHOR</option>
</select>
</div>
</div>
<div class="frmelements short2">
<label for="City">City<span>*</span></label>
<div class="field">
<div class="icon-box">
<center><img src="images/frmicon6.png"></center>
</div>
<input type="text" name="City" class="ft-input" autocomplete="off" id="City" required/>
</div>
</div>
<div class="frmelements short1">
<label for="sq-postal-code">Zip Code <span>*</span></label>
<div class="field">
<div class="icon-box">
<center><img src="images/frmicon8.png"></center>
</div>
<input type="text" name="sq-postal-code" class="ft-input" autocomplete="off" id="sq-postal-code"
pattern="^\d{5}(?:[-\s]\d{4})?$" required/>
</div>
</div>
<div class="frmelements short2">
<label for="Phone">Phone Number <span>*</span></label>
<div class="field">
<div class="icon-box">
<center><img src="images/frmicon4.png"></center>
</div>
<input type="text" name="Phone" class="ft-input" autocomplete="off" id="Phone"
pattern="^(\+\d{1,2}\s)?\(?\d{3}\)?[\s.-]\d{3}[\s.-]\d{4}$" required/>
</div>
</div>
</div>
</div>
</div>
<div class="sec1crt-frmrgt">
<div class="form-container">
<div class="form-top">
<div class="form-toplft">
<center><img src="images/hdng-icon2.png" class="hdng-icon"></center>
</div>
<div class="form-toprgt">
<p class="txt2-chk">Payment Information</p>
</div>
</div>
<div class="form-content2">
<div class="lwrform">
<div style="display:block;" id="cardDiv">
<div class="clearall"></div>
<img src="images/cards.png" class="cards">
<div class="clearall"></div>
<div class="frmelements short1">
<label for="sq-amount">Payment Amount<span>*</span></label>
<div class="field">
<div class="icon-box">
<center><img src="images/frmicon9.png"></center>
</div>
<input data-threeds="pan" type="text" maxlength="16" id="sq-amount" name="sq-amount" class="ft-input"
pattern="^[+-]?[0-9]{1,3}(?:,?[0-9]{3})*(?:\.[0-9]{2})?$" required>
</div>
</div>
<div class="frmelements">
<label for="sq-card-number">Card Number<span>*</span></label>
<div class="field">
<input data-threeds="pan" type="text" maxlength="16" id="sq-card-number" name="sq-card-number" class="ft-input noicon"
pattern="^(?:4[0-9]{12}(?:[0-9]{3})?|[25][1-7][0-9]{14}|6(?:011|5[0-9][0-9])[0-9]{12}|3[47][0-9]{13}|3(?:0[0-5]|[68][0-9])[0-9]{11}|(?:2131|1800|35\d{3})\d{11})$" required>
</div>
</div>
<div class="frmelements short1">
<label for="sq-expiration-date">Expiration Date<span>*</span></label>
<div class="field">
<input data-threeds="pan" type="text" id="sq-expiration-date" name="sq-expiration-date" class="ft-input noicon" required>
</div>
</div>
</div>
<div class="frmelements short2">
<label for="sq-cvv">CVV<span>*</span></label>
<div class="field">
<input type="text" class="ft-input noicon" name="sq-cvv" id="sq-cvv" maxlength="4"
pattern="^[0-9]{3,4}$" required>
</div>
</div>
<div class="frmelements short2">
<p class="txt4-chk">What is this?</p>
</div>
</div>
<!--
After a nonce is generated it will be assigned to this hidden input field.
-->
<input type="hidden" id="card-nonce" name="nonce">
</div>
<div class="clearall"></div>
<div class="frmelements btn-element">
<input type="submit" value="" id="sq-creditcard" onclick="requestCardNonce(event)"
class="button-credit-card">
</div>
<center><img src="images/postal-crt.png" class="postal-crt"></center>
</div>
</div>
</div>
</form>

Laravel Dynamic Form Submit not responding

I have a controller ( Laravel ) which will be dynamic create a form as below
<div class="row" style="margin-bottom:30px;margin-top:20px;">
<div class="col-2">
<form class="addform" id="newcheckform" role="form">
'.csrf_field().'
<label class="" for="cust_code">Cust Code</label>
<input type="text" class="form-control" id="cust_code" value="'.$row->cust_no.'">
</div>
<div class="col-2">
<label class="" for="cust_short">Cust Shortname</label>
<input type="text" class="form-control" id="cust_short">
</div>
<div class="col-4">
<label class="" for="cust_name">Cust Name</label>
<input type="text" class="form-control" id="cust_name" value="'.$row->cust.'">
</div>
<div class="col-2">
<label class="" for="region">Region</label>
<input type="text" class="form-control" id="region">
</div>
<div class="col-2">
<label class="" for="region">Add Cust Data</label>
<button class="btn btn-sm btn-info" id="createnewcust" type="submit">Create</button>
</form>
</div>
</div>
if will be loaded by below script in the blade file
$("#custcheck").load("{{ url('/sales/admin/custcheck') }}");
The form displayed as its should to be.
However I when I submit button. Nothing happened. code as below. Appreciate anyone can help. this script resides in the same blade file.
$(function() {
$(document).on('submit', '#newcheckform', function(e){
alert("Hi");
});
});
You have wrong closing tags for <form> change something like this:
<div class="row" style="margin-bottom:30px;margin-top:20px;">
<form class="addform" id="newcheckform" role="form">
{{csrf_field()}}
<div class="col-2">
<label class="" for="cust_code">Cust Code</label>
<input type="text" class="form-control" id="cust_code" value="{{$row->cust_no}}">
</div>
<div class="col-2">
<label class="" for="cust_short">Cust Shortname</label>
<input type="text" class="form-control" id="cust_short">
</div>
<div class="col-4">
<label class="" for="cust_name">Cust Name</label>
<input type="text" class="form-control" id="cust_name" value="{{$row->cust}}">
</div>
<div class="col-2">
<label class="" for="region">Region</label>
<input type="text" class="form-control" id="region">
</div>
<div class="col-2">
<label class="" for="region">Add Cust Data</label>
<button class="btn btn-sm btn-info" id="createnewcust" type="submit">Create</button>
</div>
</form>
</div>
This will work.

Resources