Most of the time, you need to add new form fields in your project. Larafy has again made this task easier. The built in custom field module can be used to create new form fields in minutes. Attached image shows the a field called 'Company Name' is added in 'User Registration Form'. This form field is required & must be entered before submitting this form. 


Larafy has 9 different type of form fields:


Field Type Description
Text Input User can enter alphabets, numbers & speical characters.
URL Input The input must have a URL.
Email Input The input must have a email.
Number Input The input must have a number.
Date Input User can select date from the datepicker.
Radio Button User can choose one option from the list.
Check Box User can choose multiple option from the list.
Multi line Text Input User can input alphabets, numbers & speical characters in multiple line.
Dropdown User can choose one option from the dropdown list.




By default, Larafy provides custom field addition into two types of forms:


  1. User Registration form: Fields will be shown during user registration
  2. User Social Networking Field form: Fields will be shown on user profile

You can add this custom field to any of your form. All you need to add few lines of code into your project. Follow these steps to add custom field into new form.

Open config/custom_field.php file & add new form name with unique key.

 

<?php
return array(
'user-registration-form' => 'User Registration Form',
'user-social-form' => 'User Social Form',
'sample-form' => 'Sample Form',
);

 

Please make sure that your form has the class name same as the key of form. 


<form method="post" action="/your-action" class="sample-form">
	<input type="text" name="name">
	{{ getCustomFields('sample-form') }}
</form>

  

The method 'getCustomFields' along with the name of form, can be used to display all the custom fields of the form. To store the custom fields use below codes:


  

$validation = validateCustomField('sample-form',$request);

if($validation->fails())
    return redirect()->back()->withInput()->withErrors($validation->messages());

$data = $request->all();
storeCustomField('sample-form',$sample->id, $data);

  

The validation method checks for the mandatory field as well as field type & if there is any input error, redirects back to the form. If the input provides is correct, it calls another method named 'storeCustomField' with form name, unique id of the entity & with the input field.