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. 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 ?

  4. 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 !

  5. 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
  6. 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 ?

  7. 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

  8. 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 ?

  9. 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

  10. 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?

  11. 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...