Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Other Can someone recommend a customizable contact form, please?

  • This topic is empty.
Viewing 15 posts - 31 through 45 (of 225 total)
  • Author
    Posts
  • #169200
    __
    Participant

    @TheDoc or @Paulie_D, I have another lost post (in this thread; made this morning). Can anyone rescue it?


    @JamesBurton
    :

    For HTML, use the htmlspecialchars function. This turns <, >, &, ", and ' into their html entity equivalents.

    For SQL, it depends on what SQL engine you’re using, and how you’re using it. The best approach -assuming you’re using a MySQL database- is to use the PDO or MySQLi extensions, which support prepared statements: you write the query first, with placeholders for the data, and then provide the data separately. This way, MySQL cannot possibly confuse the two.

    For a validation()-type function, you should not sanitize anything. Validation and sanitization are separate things. Validation depends on what the data is supposed to be (e.g., a name, email address, amount of money, etc.), while sanitization depends on what you’re doing with it. There is no one-size-fits-all solution.

    #169245
    Anonymous
    Inactive

    Greetings traq,

    I’ve been playing around with this since yesterday and am still trying to figure it out. I’ve copied and paste the class definition into the form page and that’s pretty straightforward. I’m pretty sure I’m getting it in the correct place. I’m not so sure about the other coding. Give me ’til tomorrow to try to figure this out on my own and if I don’t succeed I’ll get back with you then.

    Hopefully I won’t have as many iron in the fire tomorrow and can focus on this more clearly.

    Best Regards,

    Michael

    #169250
    __
    Participant

    I’ve copied and paste the class definition into the form page and that’s pretty straightforward. I’m pretty sure I’m getting it in the correct place.

    If you copy+paste it on the page, the class definition will be parsed by PHP before the script is run, so it doesn’t need to be in any particular spot.

    It might be easier, however, to put it in its own file (e.g., “contactMichael1961.php“), and then include it on the page where you’re using it.

    <?php
    include_once "path/to/contactMichael1961.php";
    
    // set up contact form object
    $contactForm = new contactMichael1961;
    
    // do this:
    //  <?= $contactForm->cssStyle(); ?>
    // in the html <head> where you want the <style> to appear
    
    //  do this:
    //  <?= $contactForm->htmlMarkup(); ?>
    //  in the html <body> where you want the form itself to appear
    

    Give me ’til tomorrow to try to figure this out

    No problem. Remember to Ask if you have questions. : )

    #169252
    James Burton
    Participant

    @traq

    Hello, Could you send me a email (Email Deleted) and I can send you some questions about security programming.

    From
    James Burton

    #169253
    __
    Participant

    Could you send me a email… and I can send you some questions about security programming

    Sure, I’d be happy to. I do charge an hourly rate for consulting (details will be in my email).

    Alternatively, if it’s something that others could benefit from (and doesn’t involve confidential/sensitive information), you could start a new discussion here on css-tricks for free and I’d be glad to participate.

    #169453
    Anonymous
    Inactive

    Greetings traq,

    Well, I’m just not getting this. I even managed to screw up my original contact form and have spent the biggest part of the day fixing it! I’ve really gotten myself confused on this and have reread your posts and googled terms I’m unfamiliar with, but have myself so confused nothing is making any sense at this point.

    Should all of the JS come out of the form as the coding you’ve created doesn’t use JS (if I understand correctly.)

    Please explain again exactly what I need to put in the contact form and what other files need to be created/altered if any.

    Sorry for the delay and mess.

    Best Regards.

    #169456
    __
    Participant

    No problem.

    Should all of the JS come out of the form as the coding you’ve created doesn’t use JS (if I understand correctly.)

    Leave it all out, for now. We can add JS later, but for now, there’s none and we don’t want it to get in the way of testing.

    I even managed to screw up my original contact form and have spent the biggest part of the day fixing it!

    Ah-hah! Don’t work on your original files directly. Make backup copies. When programming, never do anything unless you can get your original script back in just a few clicks.

    Please explain again exactly what I need to put in the contact form and what other files need to be created/altered if any.

    Create a new file that holds the class definition. (Just copy+paste what we have in the gist.) I recommend naming this file after the classname, e.g., “contactMichael1961.php.”

    On your “contact me” page, put whatever HTML+CSS you want for your layout. Then, at the very top, above everything else, include the class definition and create a new object from it:

    <?php
    include_once "path/to/contactMichael1961.php";
    $contactForm = new contactMichael1961;
    ?>
    

    In your page’s HTML <head>, print the form’s CSS <style> element:

    <?= $contactForm->cssStyle(); ?>
    

    In your page’s HTML <body>, print the HTML <form> itself:

    <?= $contactForm->htmlMarkup(); ?>
    

    That should give you the initial contact page. Nothing will happen -yet- when you submit it, but I want to make sure things are working “so far.”

    #169537
    Anonymous
    Inactive

    Greetings traq,

    I backed everything up but I’ve shuffled things around so much, and have so many similarly named files, that I got lost and just decided to do it over a bit.

    Well, still no luck. Here’s a pastebin of what I have. I also moved the stylesheet and the contactMichael1961.php but all I’m getting is a white page. Even on Dreamweaver I’m not getting the style but just a white form spread across the page with no order.

    What am I screwing up?

    Best Regards.

    #169562
    __
    Participant

    include_once "path/to/contactMichael1961.php";

    the path here “path/to/…” was not meant to be literal. I don’t know what the path to your file will be, because I don’t know where you saved it. You need to replace this with the actual file path.

    For example, if you used the class name as the filename and saved it in your /home/users/www/phpclasses directory, then the path would be /home/users/www/phpclasses/contactMichael1961.php.

    <?= $contactForm->contact-form/contact.css(); ?>

    Think you mixed up two lines of code, there. It should just be:

    <?= $contactForm->cssStyle(); ?>
    

    <!-- Form Code Start -->

    Don’t put the form html in manually; we’re making the object take care of that. To create the form, you should have only

    <?= $contactForm->htmlMarkup(); ?>
    

    I made a second page on our gist (scroll down) modeled after your contact page. You will still need to figure the location (filesystem path) of your class file, so you can include it.

    all I’m getting is a white page.

    That’s usually the result of a fatal error, when php is configured not to show any error messages. It’s probably because the include failed, and so there was no class definition when you try to create the contactForm object. Fixing the path to the class definition should solve this.

    #169614
    Anonymous
    Inactive

    Greetings traq,

    the path here “path/to/…” was not meant to be literal.

    Yeah, I realized that mistake after I made the post and corrected it.

    I’m confused on the <?= $contactForm->htmlMarkup(); ?> Do I need to set the html as a separate file and then link to it with the above?

    Sorry for the confusion and long delays in replying.

    Best Regards.

    #169657
    __
    Participant

    I’m confused on the <?= $contactForm->htmlMarkup(); ?> Do I need to set the html as a separate file and then link to it with the above?

    Nope, nope, nope. : )

    The HTML for the <form> is in our class definition (remember, the $_htmlMarkup property). Printing the result from the htmlMarkup() method on our $contactForm object gives us everything we need.

    As long as the path in the include statement is correct, the file I added to the gist should work as-is. Give it a try!

    Sorry for the confusion and long delays in replying.

    No problem at all. Don’t think twice about it.

    #169695
    Anonymous
    Inactive

    Greetings traq,

    I’m still not getting this. I tried again and still a white page.

    I don’t understand where the html code you have after the form code is supposed to go.

    I have the css style sheet in the same folder as the php files, is this correct?

    Best Regards.

    #169736
    __
    Participant

    I’m still not getting this. I tried again and still a white page.

    What version of PHP are you running? I just realized something.

    If you’re running an older version, you might not have the openssl_random_pseudo_bytes function, which would cause a fatal error when it is called. Does your web host give you access to your php error logs?

    I don’t understand where the html code you have after the form code is supposed to go…
    I have the css style sheet in the same folder as the php files, is this correct?

    I know it seems counter-intuitive, but there is no html or stylesheet. The class provides all of it. The two files in our gist are everything you need. Don’t put the raw HTML form on your page; don’t link any stylesheets for the form. PHP is writing it for you.

    #169737
    __
    Participant

    I updated the gist to check if openssl_random_pseudo_bytes is available, and use a (whimpy) alternative if not. Make new copies and try it again.

    #169849
    Anonymous
    Inactive

    Greetings traq,

    Please verify whether or not I have everything in the proper place here.

    It’s quite possible it’s a host issue as I’ve had an ongoing one for about a year now, which was supposed to be semi-fixed and allow newer PHP to run on a woefully outdated server. I had/have every intention of switching my host once the new site is ready to put online.

    I really appreciate your patience with this. This PHP stuff is very new to me and the terminology is foggy to me as well.

    Best Regards.

Viewing 15 posts - 31 through 45 (of 225 total)
  • The forum ‘Other’ is closed to new topics and replies.