Back to Squad Support

tekjava
tekjava

Is their any way to get the contact form to work without the need for any plugin?

EngBadr
EngBadr

the same question , I already created my form , and I believe that I did not need any plugin I hope this right ?! my form tag here

<form class="form-horizontal"
data-request="OnSend()" 
data-request-update="alert(your reqesut will send Now)">

here is my code

function OnSend()
{
// Collect input
$name = post('name');
$email = post('email');
$mobile = post('mobile');
$message = post('message');

// Form Validation
$validator = Validator::make(
    [
        'name' => $name,
        'email' => $email,
        'mobile' => $mobile,
        'message' => $message,
    ],
    [
        'name' => 'required',
        'email' => 'required|email',
        'mobile' => 'required',
        'message' => 'required',
    ]
);

if ($validator->fails())
{
    $messages = $validator->messages();
    throw new ApplicationException($messages->first());
}

// All is well -- Submit form
$to = System\Models\MailSettings::get('sender_email');
$params = compact('name','email','mobile','message');
Mail::sendTo($to, 'pcnsup.com::mail.request', $params);
return true;
}

I'am not sure where is my problem and all data become in clear text in my browser URL !!

any expert to help us.

Last updated

EngBadr
EngBadr

I find the solution for that , the way two solve this issue is the PHP code have to be placed in the layout code not in the partial code. that because when we load the home page and display the form the data-request try to find that function in the partial code which not available.

place your HTML code in your partial or page the retirve user input using the code in layout

the form have to be place in the partial no problem.

<form class="form-horizontal"
data-request="OnSend" 
data-request-update="alert(your reqesut will send Now)">

be carfule use data-request="OnSend"

here we go the following code have to be placed in your layout function onSend() { // Collect input ......add any number of data it depend on your form $name = post('name'); $email = post('email'); $mobile = post('mobile'); $address = post('address'); $servicetype = post('servicetype'); $description = post('description');

// Form Validation .... validate what you need 
$validator = Validator::make(
[
'name' => $name,
'email' => $email,
'mobile' => $mobile,
'address' => $address,
'servicetype' => $servicetype,
'description' => $description

],
// here your conditions for validations what is the required and its format 
[
'name' => 'required',
'email' => 'required|email',
'mobile' => 'required',
'address' => 'required',
'servicetype' => 'required',
'description' => 'required'

]
);
if ($validator->fails())
{
$messages = $validator->messages();
throw new ApplicationException($messages->first());
}
// All is well -- Submit form........ every thing nice then

$to = $email;

$params_request = compact('name','email','mobile','address','servicetype','description');

$params_notification = compact('name','servicetype');
// this will send the email to the site administrator or where you need
Mail::sendTo('admin_mail@example.com', 'example.com::mail.request', $params_request); 

// this will send the email to the customer
Mail::sendTo($to, 'example.com::mail.notification', $params_notification);

return true;
}

then you need to create the mail templates needed in my case I create two template with the following code example.com::mail.request example.com::mail.notification where example.come is your domain

each one have different message and contents each variable will be displayed in our template using its variable name depending on which template used

{{name}}
{{email}}
{{mobile}}
.....etc

Last updated

tekjava
tekjava

I solved this issue by using the code from this post: http://octobercms.com/theme/jtherczeg-multi/contact-form

NOTE: I then started getting the error mentioned here https://octobercms.com/forum/post/content-form-with-textarea in which I change the word "message" to "body" in the php, html, and mail template.

hendrac713191
hendrac713191

so we are not need php to send the message ??

tekjava
tekjava

We do and this requires Flexi Contact which is free. You will need to go into settings>mail>mail configuration and create a mail template. See Flexi Contact documentation and links above.

The code section of home page is like so:

function onSend()
{
    // Collect input
    $name = post('name');
    $email = post('email');
    $subject = post('subject');
    $body = post('body');

    // Form Validation
    $validator = Validator::make(
        [
            'name' => $name,
            'email' => $email,
            'subject' => $subject,
            'body' => $body,
        ],
        [
            'name' => 'required',
            'email' => 'required|email',
            'subject' => 'required',
            'body' => 'required',
        ]
    );

    if ($validator->fails())
    {
        $messages = $validator->messages();
        throw new ApplicationException($messages->first());
    }

    // All is well -- Submit form
    $to = System\Models\MailSettings::get('sender_email');
    $params = compact('name','email','subject','body');
    Mail::sendTo($to, 'contactapp.flexicontact::mail.contactform', $params);
    return true;
}

Last updated

tekjava
tekjava

Text area code in form html: change "name" value and css "id" value from "message" to "body".

html section of email template in settings (change "message" value to "body")

Name: {{name}}

Email: {{email}}

Subject: {{subject}}

Message: {{body}}

source: https://octobercms.com/forum/post/content-form-with-textarea

No need to use the component of Flexi Contact anywhere

links shared above your response should help

Last updated

1-7 of 7