Jump to content

wishbone

Members
  • Posts

    183
  • Joined

  • Last visited

Posts posted by wishbone

  1. problem how to set headers "from" correctly

    Important change due to DMARC-policies:

    If the user's email contains e.g. yahoo or hotmail, it will be rejected.

    -> "From" - never set user's email

    To be able to reply to the user's email nevertheless, set headers.

    $headers = 'From: info@selfdomain.com' . "\r\n" .
    			'Reply-To: $email' . "\r\n" .
    			'X-Mailer: PHP/' . phpversion();

    throws: "Reply-to: $email" (everything else is correct)

    tried:
    'Reply-To: $form[email]' . "\r\n" .

    also only gives the string "$form[email]", doesn't run the code.

    $email is:
    $form = array(
    ย ย ย  ...
    ย ย ย  'email' => $sanitizer->email($input->post->email),
    ย ย ย  ...
    ย ย ย  );

    Where is my syntax error?

    thx again!

  2. thankyou thank you for looking into this!

    18 hours ago, Jan Romero said:

    This doesnโ€™t happen after you set the error, by any chance?

    no, it's the first lines.

    this is Ryan's code (with more fields), error message doesn't show:

    $sent = false;
    $error = '';
    $emailTo = 'abc@gmx.de'; // or pull from PW page field
    
    // sanitize form values or create empty
    $form = array(
        'vorname' => $sanitizer->text($input->post->vorname),
        'name' => $sanitizer->text($input->post->name),
        'orga' => $sanitizer->text($input->post->orga),
        'funktion' => $sanitizer->text($input->post->funktion),
        'gruppe' => $sanitizer->text($input->post->gruppe),
        'anzahl' => $sanitizer->text($input->post->anzahl),
        'termin1' => $sanitizer->date($input->post->termin1, null, ['returnFormat' => 'd.m.Y']),
        'termin2' => $sanitizer->date($input->post->termin2, null, ['returnFormat' => 'd.m.Y']),
        'zeit' => $sanitizer->text($input->post->zeit),
        'telefon' => $sanitizer->text($input->post->telefon),
        'mobil' => $sanitizer->text($input->post->mobil),
        'email' => $sanitizer->email($input->post->email),
        'comments' => $sanitizer->textarea($input->post->comments),
        ); 
    
    // check if the form was submitted
    if($input->post->submit) {
    
        // determine if any fields were ommitted or didn't validate - Ryan, alle Felder mรผssen ausgefรผllt werden
        /*foreach($form as $key => $value) {
            if(empty($value)) $error = "<p class='error'>Please check that you have completed all fields.</p>";
        }*/
    	
    	// nur bestimmte required/ DSGVO
    	if (empty($input->post->email)) $error = "<p class='error'>Bitte eine E-Mail-Adresse angeben</p>";
    
        // if no errors, email the form results
        if(!$error) {
            $msg =
    			"Vorname: $form[vorname]\n" . 
    			"Name: $form[name]\n" . 
    			"Organisation: $form[orga]\n" .  
    			"Funktion: $form[funktion]\n" .
    			"Fรผr wen: $form[gruppe]\n" .
    			"Anzahl Personen: $form[anzahl]\n" .
    			"Wunschtermin: $form[termin1]\n" .
    			"Alternativtermin: $form[termin2]\n" .
    			"Wunschzeit: $form[zeit]\n" .
    			"Telefon: $form[telefon]\n" .
    			"Telefon mobil: $form[mobil]\n" .
                "E-Mail: $form[email]\n" . 
                "Zusรคtzliche Angaben: $form[comments]";
                // "Kontaktart: $form[kontaktart]";  
    
            mail($emailTo, "Neue Anfrage von $form[vorname] $form[name], $form[orga]", $msg, "From: $form[email]");
    
            // populate body with success message, or pull it from another PW field
           echo $page->section_text = "<h2>Vielen Dank, Ihre Anfrage wurde gesendet.</h2>"; 
            $sent = true;	
        }
    }
    
    if(!$sent) {
    
        // sanitize values for placement in markup
        foreach($form as $key => $value) {
            $form[$key] = htmlentities($value, ENT_QUOTES, "UTF-8"); 
        }
    
        // append form
    	if($page->section_title) {
    							echo "<h3>{$page->section_title}</h3>";
    							}
    							 if($page->section_text) {
    							echo "{$page->section_text}";
    							}
        echo <<< _OUT
    
            $error
            <form action="./" method="post">
    	<div>
            <label>
    			<span>Vorname</span>
            	<input type="text" id="vorname" name="vorname" value="$form[vorname]">
    		</label>
    	</div>
    	...
    	...

    ย 

    18 hours ago, Jan Romero said:

    because $input->post->email() is also the name of a sanitizer method

    Ryan also checks with this method for input that doesn't validate. I also need that, don't I ?

  3. this works:

    if (empty($input->post->email)) $error = "<p class='error'>Bitte eine E-Mail-Adresse angeben</p>";

    The form starts with:

    $sent = false;
    $error = '';

    error is called here:

        echo <<< _OUT
    
            $error
            <form action="./" method="post">

    ย 

  4. After thinking about the DSGVO, I need to not make all fields mandatory, only as few as possible, to mark with *required.

    The current code is:

        // sanitize values for placement in markup
        foreach($form as $key => $value) {
            $form[$key] = htmlentities($value, ENT_QUOTES, "UTF-8");
        }

    I rtfm and this is what I came up with:

    $bool = $inputfield->isEmpty();

    but don't know how to use it ๐Ÿ˜ถ

  5. Hi,

    php mailer

    mail($emailTo, "subject", $msg, "From: $form[email]");

    how can I format the date output?

    the input field:

    <input type="date" id="termin1" name="termin1" value="$form[termin1]" placeholder="Wunschtermin">

    the sanitizer:

    'termin1' => $sanitizer->date($input->post->termin1),

    the php mail message call:

    "Wunschtermin: $form[termin1]\n" .

    With no format defined, unix timestamp is being outputted.

    If format defined in the sanitizer, always "20.10.2007" is outputted, no matter which date was picked:

    'termin1' => $sanitizer->date($input->post->termin1, "d.m.Y"),

    if input field is formated, unix timestamps is being outputted

    <input type="date" id="termin1" name="termin1" value="$form[termin1]" placeholder="Wunschtermin" format="d.m.Y.">

    How do I do this?

    Thx !

  6. Hi flydev,

    thank you so much for your very, very kind and elaborated answer! I feel much better now ๐Ÿ˜‰

    On 5/27/2022 at 5:34 PM, flydev ๐Ÿ‘Š๐Ÿป said:

    the solution for the honeypot technique (page #2 I think posted by @kongondo).

    of course, I've read all that, and more about the honeypot technique outside pw. But again, I still have the problem to implement.

    ย 

    On 5/27/2022 at 5:34 PM, flydev ๐Ÿ‘Š๐Ÿป said:
    ย  Reveal hidden contents
    <?php
    
    $sent = false;
    $error = '';
    $emailTo = 'nikola@company.com'; // or pull from PW page field
    
    // sanitize form values or create empty
    $form = array(
        'fullname' => $sanitizer->text($input->post->fullname),
        'email' => $sanitizer->email($input->post->email),
        'comments' => $sanitizer->textarea($input->post->comments),
      
        // ๐Ÿ‘‰ Use $sanitizer for security
        // ๐Ÿ‘‰ Add more fields here, and use the right sanitizer (https://processwire.com/api/ref/sanitizer/)
        
        ); 
    
    // check if the form was submitted
    if($input->post->submit) {
    
        // determine if any fields were ommitted or didn't validate
        // ๐Ÿ‘‰ you can do a small logic here to avoid all field being required.
        foreach($form as $key => $value) {
            if(empty($value)) $error = "<p class='error'>Please check that you have completed all fields.</p>";
        }
    
        // if no errors, email the form results
        // ๐Ÿ‘‰ you can complete the message with your other field value
        if(!$error) {
            $message = "Full name: $form[fullname]\n" . 
                   "Email: $form[email]\n" . 
                   "Comments: $form[comments]"; 
    
            mail($emailTo, "Contact Form", $message, "From: $form[email]");
    
            // populate body with success message, or pull it from another PW field
            $page->body = "<h2>Thank you, your message has been sent.</h2>"; 
            $sent = true;	
        }
    }
    
    if(!$sent) {
    
        // sanitize values for placement in markup
        foreach($form as $key => $value) {
            $form[$key] = htmlentities($value, ENT_QUOTES, "UTF-8"); 
        }
    
        // append form to body copy
        // ๐Ÿ‘‰ add more field/input markup here
        $page->body .= <<< _OUT
    
            $error
            <form action="./" method="post">
            <p>
            <label for="fullname">Your Name</label><br />
            <input type="text" id="fullname" name="fullname" value="$form[fullname]" />
            </p>
    
            <p>
            <label for="email">Your Email</label><br />
            <input type="email" name="email" id="email" value="$form[email]" />
            </p>
    
            <p>
            <label for="comments">Comments</label><br />
            <textarea id="comments" name="comments">$form[comments]</textarea>
            </p>
    
            <p><input type="submit" name="submit" value="Submit" /></p>
            </form>
    
    _OUT;
    
    }
    
    // include site's main template which outputs everything
    include("./main.php"); 

    ย 

    what is this? can't open

    ย 

    On 5/27/2022 at 5:34 PM, flydev ๐Ÿ‘Š๐Ÿป said:

    when you will add more input to the form. I mean here, the $sanitizing technique which give you "control" on the submitted user data.

    Try something with the form, and do not hesitate to ask further help here ๐Ÿ‘

    ย 

    Edit: found your very helpful remarks only recently, in the hidden content which I couldn't open at frist
    Does it mean, I can't just extend the form by duplicating the structure of the input fields, sanitizing them and put them in the mail call?

    Anyway, I will try Ryan's solution and come back to your kind help offer if I have problems.

    ย 

    Thank you again so much for the time you have taken on this! I really really want to learn more processwire, that's why I'm trying to do it myself. Also, I prefer raw code over modules, because they give me the freedom.

    Maybe once I know more about how the code works, modules can make it faster. But for now, I want to learn ๐Ÿ˜‰.

    ย 

    ย 

    • Like 1
  7. 17 hours ago, Juergen said:

    This module creates and validates forms - not less or more.

    If you want to install the module maybe I could help you.

    ย 

    Hi Jรผrgen,

    thank you for your help offer!

    Though I don't know how to send mail via wiremail or other... that's exactly my problem.

  8. 16 hours ago, Klenkes said:

    Don't get me wrong, but these hours would have been better spent on 74โ‚ฌ for a single licence of FormBuilder. No coding required. I own a DEV licence since 2016 and I never think twice about the yearly payment, not even a second! FormBuilder slogan should be: Forms made easy!

    I was thinking of this, of course, but Formbuilder is so overloaded! and for a small project expensive. I'm not doing too many pw-sites.

    Anyway, through doing it myself I try to learn, php, and processwire, and all.

    That's how we non-coders manage to build processwire-sites ๐Ÿ˜‰

  9. Hi Klenkes,

    thx for your idea!

    On 5/24/2022 at 8:24 AM, Klenkes said:

    what about the module SimpleContactForm.

    https://processwire.com/modules/simple-contact-form/

    Wouldnโ€˜t do that what you want?

    I even can't install it. Maybe it is not compliant with php8.

    And not maintained any more.

    And for me very difficult to understand how to modify the thml markup.

    (I wrote that already, but where has the post gone ? ๐Ÿ˜‰ )

  10. Hi Gideon

    9 hours ago, Gideon So said:

    He needs a A 13-field form and a 13-field form is not a simple contact form IMO.

    if the mailer takes more than the given four fields, it should not be complicated to duplicate the structure and insert the custom fields.

    mail($emailTo, "Contact Form", $message, "From: $form[email]");

    Can I just add more custom fields?

    Same with wiremail

  11. 5 hours ago, flydev ๐Ÿ‘Š๐Ÿป said:

    copy paste 13 times

    nobody is talking about copy/paste 13 times. But the structure is the same if 2 or 20 fields.

    5 hours ago, flydev ๐Ÿ‘Š๐Ÿป said:

    just require you to read the documentation

    believe me, I've studied all these modules/ suggestions. Hours and hours and days and days.

    Formbuilder is overloaded for my project.

    Coders just can't understand non-coders, obviously.

    ย 

    5 hours ago, flydev ๐Ÿ‘Š๐Ÿป said:

    About the 12 years old code (which should works without hassle lol thats crazzy every time ๐Ÿ˜‚)

    Now that's what I needed to hear, finally! It's about security concerns also.

    Though, Ryan uses php mail - I don't know if php mail can take more than the given fields?

    mail($emailTo, "Contact Form", $message, "From: $form[email]");

    ย 

    5 hours ago, flydev ๐Ÿ‘Š๐Ÿป said:

    ย  you will find a lot of other working samples code to copy pasta

    besides Ryan's I found just ONE more, which is told to have security issues.

    ย 

    5 hours ago, flydev ๐Ÿ‘Š๐Ÿป said:

    Iย  still suggest you to read and understand what you are doing

    thx again for insinuating that I'm not searching and reading and trying to understand enough.

    Again, coders don't understand non-coders. They think we are just lazy ๐Ÿ˜‰

  12. On 5/24/2022 at 5:15 AM, Gideon So said:

    I fully understand your feeling. I came from a non coder background, too.

    Thank you for your sympathy ๐Ÿ˜‰

    On 5/24/2022 at 5:15 AM, Gideon So said:

    If you are willing to pay for a working contact form. I suggest you to buy Ryan's FormBuilder.

    far too complicated! I just need a simple form full code

  13. as a non-coder designer, this is what frustrates me always with processwire. If I wouldn't like it so much for it's "fluffyness" and flexibility I'd have long given up.

    Navigation is full code in the sample profile. But there is no contact from.

    A simple contact form with custom markup just to insert into a template - I can't find, except the one of Ryan which is 12 years old ๐Ÿ˜‰

    All the modules are either without custom markup, or not maintained any more, or still have issues, or are so complicated, that it's too time consuming to learn.

    Maybe somebody could write the code for me for money?

  14. Was searching and searching for a complete code for a simple form - found this one from 2011 by Ryan, which is exactly what I need:

    So ist that still State of the Art and usable?

    What I need is a simple form with about 13 elements of the form:

    <div>
        <label>
                <span>Name</span>
                <input type="text" placeholder="Name" name="name" size="50" maxlength="20">
        </label>
    </div>

    also a radio button with 3 values.

    The data of the form is to be sent to two email addresses, a confirmation that the mail has been sent - and a honeypot would be great.

    Since I'm a php-dunce, I need the full code...

    thx for advice!

ร—
ร—
  • Create New...