Jump to content

Flashmaster82

Members
  • Posts

    166
  • Joined

  • Last visited

Posts posted by Flashmaster82

  1. <?php
    namespace Processwire;
    
    $contact_form = $pages->get("template=contact");
    $company = $pages->get("template=company");
    
    $form = new \FrontendForms\Form('Form');
    $form->setHtml5Validation(true); // Enable HTML5 browser validation
    
    // First Name
    $firstname = new \FrontendForms\InputText('scf_firstname');
    $firstname->setLabel($fields->get('scf_firstname')->$label);
    $firstname->setRule('required');
    $form->add($firstname);
    
    // Last Name
    $lastname = new \FrontendForms\InputText('scf_lastname');
    $lastname->setLabel($fields->get('scf_lastname')->$label);
    $lastname->setRule('required');
    $form->add($lastname);
    
    // Phone
    $phone = new \FrontendForms\InputText('scf_phone');
    $phone->setLabel($fields->get('scf_phone')->$label);
    $phone->setRule('required');
    $form->add($phone);
    
    // Email
    $email = new \FrontendForms\InputText('scf_email');
    $email->setLabel($fields->get('scf_email')->$label);
    $email->setRule('required');
    $form->add($email);
    
    
    // SERVICES
    $service = new \FrontendForms\Select('scf_service');
    $service->setLabel(__($fields->get('scf_service')->$label));
    // Add options dynamically based on existing pages
    $services = wire('pages')->find('template=insurance|telephony|pension, sort=name');
    
    // Add options dynamically based on existing pages
    foreach ($services as $servicePage) {
        $service->addOption($servicePage->title, $servicePage->id);
    } 
    
    $form->add($service);
        
    $message = new \FrontendForms\Textarea('scf_message');
    $message->setLabel($fields->get('scf_message')->$label);
    $message->setRule('required');  
    $form->add($message);
    
    $button = new \FrontendForms\Button('submit');
    $button->setAttribute('value', $fields->get('label_send')->label);
    $button->setAttribute('class', 'btn btn-primary'); // Add the CSS class
    $form->add($button);
    
    if($form->isValid()){
        
        $p = new Page();
        $p->template = 'contact_inquiry';
        $p->parent = wire('pages')->get('template=contact');
        $p->title = $form->getValue('scf_firstname') . ' ' . $form->getValue('scf_lastname');
        $p->scf_firstname = $form->getValue('scf_firstname');
        $p->scf_lastname = $form->getValue('scf_lastname');
        $p->scf_phone = $form->getValue('scf_phone');
        $p->scf_email = $form->getValue('scf_email');
        $p->scf_service = $form->getValue('scf_service');
        $p->scf_message = $form->getValue('scf_message');
        
      
        // Set the scf_date field to the current date and time with the correct timezone
        $dateTime = new \DateTime('now', new \DateTimeZone('Europe/Stockholm'));
        $p->scf_date = $dateTime->format('Y-m-d H:i:s');
        
        $p->save();
        
        
        // Retrieve the title of the selected legal service
        $selectedserviceID = $form->getValue('scf_service');
        $selectedservice = wire('pages')->get($selectedserviceID);
        $selectedserviceTitle = $selectedservice ? $selectedservice->title : 'Not specified';
        
        
        
        // Initialize $messageBody
        $messageBody = '';
        
        $m = wireMail();
        $m->to('test@gmail.com');
        $m->subject("{$contact_form->scf_email_title} {$selectedserviceTitle}, {$form->getValue('scf_firstname')} {$form->getValue('scf_lastname')}");
    
        // Set "Reply-To" address
        $m->header('Reply-To', $form->getValue('scf_email') . ' (' . $form->getValue('scf_firstname') . ' ' . $form->getValue('scf_lastname') . ')');
      
        $messageBody .= "<strong>{$fields->get('scf_firstname')->label}:</strong> " . $form->getValue('scf_firstname') . "<br>";
        $messageBody .= "<strong>{$fields->get('scf_lastname')->label}:</strong> " . $form->getValue('scf_lastname') . "<br>";
        $messageBody .= "<strong>{$fields->get('scf_phone')->label}:</strong> " . $form->getValue('scf_phone') . "<br>";
        $messageBody .= "<strong>{$fields->get('scf_email')->label}:</strong> " . $form->getValue('scf_email') . "<br><br>";
        
        
        
        $messageBody .= "<strong>{$fields->get('scf_service')->label}:</strong> " . $selectedserviceTitle . "<br><br>";
        
        $messageBody .= "<strong>{$fields->get('scf_message')->label}</strong><br>" . $form->getValue('scf_message') . "<br>";
        
        $m->bodyHTML($messageBody);
        $m->send();
        
        
        
        // Set up the email for the form submitter
    $confirmationEmail = wireMail();
    $confirmationEmail->to($form->getValue('scf_email'));
    $confirmationEmail->subject("{$contact_form->scf_email_confirmation_title} {$selectedserviceTitle}");
    
    $confirmationMessage = "{$contact_form->scf_email_confirmation_message}";
    
    $confirmationEmail->bodyHTML($confirmationMessage);
    $confirmationEmail->send();
        
        
        
        
        // Redirect to the success page
        wire('session')->redirect(wire('config')->urls->root . 'arendet-skickades/');
    }
    
    
    echo $form->render();
    ?>

    When i insert like XX into the email field there is an error Error: Exception: Invalid email address (in E:\Wamp\www\website\wire\core\WireMail.php line 162). I dont know how to validate the email adress before sending the form. Any clues?

  2. Can´t install this module: ProcessModule: Module is not installable because not all required dependencies are currently met. What other modules do i need to install to get this to work?

  3. <?php namespace Processwire;
    $form = new \FrontendForms\Form('myForm');
    
    $firstname = new \FrontendForms\InputText('scf_firstname');
    $firstname->setLabel($fields->get('scf_firstname')->$label);
    $firstname->setRule('required');
    $form->add($firstname);
        
    $lastname = new \FrontendForms\InputText('scf_lastname');
    $lastname->setLabel($fields->get('scf_lastname')->$label);
    $lastname->setRule('required');
    $form->add($lastname);
        
    $phone = new \FrontendForms\InputText('scf_phone');
    $phone->setLabel($fields->get('scf_phone')->$label);
    $phone->setRule('required');
    $form->add($phone);      
        
    $email = new \FrontendForms\InputText('scf_email');
    $email->setLabel($fields->get('scf_email')->$label);
    $email->setRule('required');
    $form->add($email); 
        
    $legalservice = new \FrontendForms\Select('scf_legalservice');
    $legalservice->setLabel(__($fields->get('scf_legalservice')->$label));
    // Add options dynamically based on existing pages
    $legalservices = wire('pages')->find('template=legal_service');
    foreach ($legalservices as $service) {
    $legalservice->addOption($service->title, $service->id);
    } 
    $form->add($legalservice);
        
    $message = new \FrontendForms\Textarea('scf_message');
    $message->setLabel($fields->get('scf_message')->$label);
    $message->setRule('required');
    $form->add($message);
    
    $button = new \FrontendForms\Button('submit');
    $button->setAttribute('value', $fields->get('label_send')->label);
    $form->add($button);
    
    if($form->isValid()){
        
        
        $p = new Page();
        $p->template = 'contact_inquiry';
        $p->parent = wire('pages')->get('template=contact');
        $p->title = $form->getValue('scf_firstname') . ' ' . $form->getValue('scf_lastname');
        $p->scf_firstname = $form->getValue('scf_firstname');
        $p->scf_lastname = $form->getValue('scf_lastname');
        $p->scf_phone = $form->getValue('scf_phone');
        $p->scf_email = $form->getValue('scf_email');
        $p->scf_legalservice = $form->getValue('scf_legalservice');
        $p->scf_message = $form->getValue('scf_message');
        
      
        // Set the scf_date field to the current date and time with the correct timezone
        $dateTime = new DateTime('now', new DateTimeZone('Europe/Stockholm'));
        $p->scf_date = $dateTime->format('U'); // 'U' format returns the Unix timestamp
        
        
        $p->save();
        
        
        $m = wireMail();
        $m->to('info@...'); // please change it
        $m->subject('Nytt ärende');
      
        $messageBody .= "<strong>{$fields->get('scf_firstname')->label}:</strong> " . $form->getValue('scf_firstname') . "<br>";
        $messageBody .= "<strong>{$fields->get('scf_lastname')->label}:</strong> " . $form->getValue('scf_lastname') . "<br>";
        $messageBody .= "<strong>{$fields->get('scf_phone')->label}:</strong> " . $form->getValue('scf_phone') . "<br>";
        $messageBody .= "<strong>{$fields->get('scf_email')->label}:</strong> " . $form->getValue('scf_email') . "<br>";
        
        // Retrieve the title of the selected legal service
        $selectedLegalServiceID = $form->getValue('scf_legalservice');
        $selectedLegalService = wire('pages')->get($selectedLegalServiceID);
        $selectedLegalServiceTitle = $selectedLegalService ? $selectedLegalService->title : 'Not specified';
        
        $messageBody .= "<strong>{$fields->get('scf_legalservice')->label}:</strong> " . $selectedLegalServiceTitle . "<br>";
        
        $messageBody .= "<strong>{$fields->get('scf_message')->label}:</strong> " . $form->getValue('scf_message') . "<br>";
        
        $m->bodyHTML($messageBody);
        $m->send();
        
    // Redirect to the success page
        wire('session')->redirect(wire('config')->urls->root . 'forfragan-skickades/');
    }
    
    echo $form->render();
    ?>

     

  4. This is so strange. Now with your code im receiving email. But with this code i will not receive any email?

    <?php namespace Processwire; ?>
    <div class="container col-5 tmar10">
        
    <?php
    $form = new \FrontendForms\Form('myForm');
    
    $firstname = new \FrontendForms\InputText('scf_firstname');
    $firstname->setLabel(__($fields->get('scf_firstname')->label));
    $firstname->setRule('required');
    $firstname->setAttribute('class', 'w3-input w3-border w3-margin-bottom');
    $form->add($firstname);
    
    $lastname = new \FrontendForms\InputText('scf_lastname');
    $lastname->setLabel(__($fields->get('scf_lastname')->label));
    $lastname->setRule('required');
    $lastname->setAttribute('class', 'w3-input w3-border w3-margin-bottom');
    $form->add($lastname);
    
    $phone = new \FrontendForms\InputText('scf_phone');
    $phone->setLabel(__($fields->get('scf_phone')->label));
    $phone->setRule('required');
    $phone->setAttribute('class', 'w3-input w3-border w3-margin-bottom');
    $form->add($phone);
    
    $email = new \FrontendForms\InputText('scf_email');
    $email->setLabel(__($fields->get('scf_email')->label));
    $email->setRule('required');
    $email->setRule('email');
    $email->setAttribute('class', 'w3-input w3-border w3-margin-bottom');
    $form->add($email);
    
    $legalservice = new \FrontendForms\Select('scf_legalservice');
    $legalservice->setLabel(__($fields->get('scf_legalservice')->label));
    // Add options dynamically based on existing pages
    $legalServices = wire('pages')->find('template=legal_service');
    foreach ($legalServices as $service) {
        $legalservice->addOption($service->title, $service->id);
    }
    $legalservice->setAttribute('class', 'w3-select w3-border w3-margin-bottom');
    $form->add($legalservice);
    
    $message = new \FrontendForms\Textarea('scf_message');
    $message->setLabel(__($fields->get('scf_message')->label));
    $message->setRule('required');
    $message->setAttribute('class', 'w3-input w3-border w3-margin-bottom');
    $form->add($message);
    
    $button = new \FrontendForms\Button('submit');
    $button->setAttribute('value', __($fields->get('label_send')->label));
    $button->setAttribute('class', 'w3-btn w3-round w3-blue');
    $button->addWrapper()->setAttribute('class', 'w3-padding-24 w3-center');
    $form->add($button);
        
    if ($form->isValid()) {
        // Form data is valid, save to a new page
        $p = new Page();
        $p->template = 'contact_inquiry';
        $p->parent = wire('pages')->get('template=contact');
        $p->title = $form->getValue('scf_firstname') . ' ' . $form->getValue('scf_lastname');
        $p->scf_firstname = $form->getValue('scf_firstname');
        $p->scf_lastname = $form->getValue('scf_lastname');
        $p->scf_phone = $form->getValue('scf_phone');
        $p->scf_email = $form->getValue('scf_email');
        $p->scf_legalservice = $form->getValue('scf_legalservice');
        $p->scf_message = $form->getValue('scf_message');
        
        // Set the scf_date field to the current date and time
        $p->scf_date = time();
        
        $p->save();
    
        // send an email
        $m = wireMail();
        $m->to('info@....com');
        $m->subject(_('New message from the contact form'));
        $m->fromName($form->getValue('scf_firstname') . ' ' . $form->getValue('scf_lastname'));
        $m->from('noreply@....se');
    
        // Customize the email message body
        $messageBody = "First Name: " . $form->getValue('scf_firstname') . "<br>";
        $messageBody .= "Last Name: " . $form->getValue('scf_lastname') . "<br>";
        $messageBody .= "Phone: " . $form->getValue('scf_phone') . "<br>";
        $messageBody .= "Email: " . $form->getValue('scf_email') . "<br>";
        $messageBody .= "Legal Service: " . $form->getValue('scf_legalservice') . "<br>";
        $messageBody .= "Message: " . $form->getValue('scf_message') . "<br>";
    
        $m->bodyHTML($messageBody);
        if($m->send()){
            print_r('send');
        }
    }
    echo $form->render();
    ?>
    </div>

    Email is changed. I have got some help from ai chat.

  5. Thanks for the reply. I changed to your other module Frontendform and everything works accept im not receiving any email? the email in this code changed btw.

     

    <?php namespace Processwire; ?>
    <div class="container col-5 tmar10">
    <?php
    
    $form = new \FrontendForms\Form('contactform');
    $form->setSuccessMsg(__('Your message was submitted successfully!'));
    $form->setErrorMsg(__('Sorry, but there are errors!'));
    
    $firstname = new \FrontendForms\InputText('scf_firstname');
    $firstname->setLabel(__($fields->get('scf_firstname')->$label));
    $firstname->setRule('required');
    $firstname->setAttribute('class', 'w3-input w3-border w3-margin-bottom');
    $form->add($firstname);
    
    $lastname = new \FrontendForms\InputText('scf_lastname');
    $lastname->setLabel(__($fields->get('scf_lastname')->$label));
    $lastname->setRule('required');
    $lastname->setAttribute('class', 'w3-input w3-border w3-margin-bottom');
    $form->add($lastname);
    
    $phone = new \FrontendForms\InputText('scf_phone');
    $phone->setLabel(__($fields->get('scf_phone')->$label));
    $phone->setRule('required');
    $phone->setAttribute('class', 'w3-input w3-border w3-margin-bottom');
    $form->add($phone);
    
    $email = new \FrontendForms\InputText('scf_email');
    $email->setLabel(__($fields->get('scf_email')->$label));
    $email->setRule('required');
    $email->setRule('email');
    $email->setAttribute('class', 'w3-input w3-border w3-margin-bottom');
    $form->add($email);
    
    $legalservice = new \FrontendForms\Select('scf_legalservice');
    $legalservice->setLabel(__($fields->get('scf_legalservice')->$label));
    // Add options dynamically based on existing pages
    $legalServices = wire('pages')->find('template=legal_service');
    foreach ($legalServices as $service) {
        $legalservice->addOption($service->title, $service->id);
    }
    $legalservice->setAttribute('class', 'w3-select w3-border w3-margin-bottom');
    $form->add($legalservice);
    
    $message = new \FrontendForms\Textarea('scf_message');
    $message->setLabel(__($fields->get('scf_message')->$label));
    $message->setRule('required');
    $message->setAttribute('class', 'w3-input w3-border w3-margin-bottom');
    $form->add($message);
    
    // Note: scf_date is not added as a form field, but it will be set when saving the new page
    
    $button = new \FrontendForms\Button('submit');
    $button->setAttribute('value', __($fields->get('label_send')->$label));
    $button->setAttribute('class', 'w3-btn w3-round w3-blue');
    $button->addWrapper()->setAttribute('class', 'w3-padding-24 w3-center');
    $form->add($button);
    
    if ($form->isValid()) {
        // Form data is valid, save to a new page
        $p = new Page();
        $p->template = 'contact_inquiry';
        $p->parent = wire('pages')->get('template=contact');
        $p->title = $form->getValue('scf_firstname') . ' ' . $form->getValue('scf_lastname');
        $p->scf_firstname = $form->getValue('scf_firstname');
        $p->scf_lastname = $form->getValue('scf_lastname');
        $p->scf_phone = $form->getValue('scf_phone');
        $p->scf_email = $form->getValue('scf_email');
        $p->scf_legalservice = $form->getValue('scf_legalservice');
        $p->scf_message = $form->getValue('scf_message');
        
        // Set the scf_date field to the current date and time
        $p->scf_date = time();
        
        $p->save();
    
        // send an email
        $m = wireMail();
        $m->to('myemail@gmail.com');
        $m->fromName($form->getValue('scf_firstname') . ' ' . $form->getValue('scf_lastname'));
        $m->from($form->getValue('scf_email'));
        $m->subject(_('New message from the contact form'));
        $m->bodyHTML($form->getValue('scf_message') . ' <br><br> ' . $form->getValue('scf_address'));
        $m->send();
        
        // Redirect to the success page
        wire('session')->redirect(wire('config')->urls->root . 'forfragan-skickades/');
    }
    
    echo $form->render();
    
    ?>
    </div>

     

  6. Should you use multiple sitemaps on a multi language website? On my current website (only one sitemap) i have this in the generated sitemap.
     

    https://www.example.se/ 2023-09-24T00:43:23+00:00 hourly 1.0 
    https://www.example.se/en/ 2023-09-24T00:43:23+00:00 hourly 1.0 

     

  7. I have also a dropdown switch

     <?php
    
      $homepage = $pages->get( '/' );
    
      $langswitch = '';
      foreach ( $languages as $language ) {
        if ( !$page->viewable( $language ) ) continue; // is page viewable in this language?
        if ( $language->id == $user->language->id ) { // current user language
          $langswitch .= "<div class='current'>";
        } else {
          $langswitch .= "<div>";
        }
        $url = $page->localUrl( $language );
        $hreflang = $homepage->getLanguageValue( $language, 'name' );
        $langswitch .= "<a hreflang='x-default' href='$url' title='{$language->title}'>{$language->title}<div class='{$language->name}'></div></a></div>";
      }
      echo "<div class='dropdown'> 
             <div class='{$user->language->name}' title='Language'></div>
            <div class='language-switch-ph' style='display:none;'>{$langswitch}</div>
            </div>";
      ?>

     

×
×
  • Create New...