Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Page 1 of 3 1 2 3 LastLast
Results 1 to 10 of 21
  1. #1
    Member Elvedin's Avatar
    Join Date
    Jan 2013
    Location
    Bosnia And Herzegowina
    Posts
    78
    Member #
    35009
    Hello people

    First of all i have to tell you , my english is bad... But i hope you will understand me .

    Well , i have an contact form , and i decided to make some fields required , my php is poor and i dont know how to do that. So if anyone have time to help me around that .

    This is my code :

    PHP Code:
    <?php
    if(isset($_POST['send'])){

    $to "hqwebs.eu@gmail.com";
    $name=$_POST['name'];
    $phone $_POST['phone'];
    $email $_POST ['email'];
    $message $_POST['message']. "\n\n Phone Number is " .$phone;
    $headers "From:" $email  ;
    mail($to,$name,$message,$headers);

    if(
    mail){
    echo 
    "Mail Sent.";
    }else{
        echo 
    "Cannot Send your mail for error";
    }
    }
    ?>
    HTML Code:
    <form id=" action="email" method="post" contact-form">
    <fieldset>
    <label>
    <input type="text" name="name" value="Name" onBlur="if(this.value=='') this.value='Name'" onFocus="if(this.value =='Name' ) this.value=''" />
    </label>
    <label>
    <input type="text" name="email" value="Email" onBlur="if(this.value=='') this.value='Email'" onFocus="if(this.value =='Email' ) this.value=''" />
    </label>
    <label>
    <input type="text" name="phone"  value="Phone" onBlur="if(this.value=='') this.value='Phone'" onFocus="if(this.value =='Phone' ) this.value=''" />
    </label>
    <textarea name="message" onBlur="if(this.value=='') this.value='Message'" onFocus="if(this.value =='Message' ) this.value=''">Message</textarea>
    <div class="buttons-wrapper">
    <a class="button" onClick="document.getElementById('contact-form').reset()">Clear</a>
    <input type="submit" name="send" onClick="document.getElementById('contact-form').submit()" value="Send"></a>
    </div>
    </fieldset>
    </form>
    So if I want to make e mail field required and message field too , which codes should I add , so if you can give me finished codes please , I`ll be thankful.

  2.  

  3. #2
    WDF Staff mlseim's Avatar
    Join Date
    Apr 2004
    Location
    Cottage Grove, Minnesota
    Posts
    7,716
    Member #
    5580
    Liked
    718 times
    You have several choices to make ... each one has its own advantages and disadvantages.

    1) Use javascripting
    2) Use AJAX, a combination of PHP and javascripting
    3) Find a pre-made script using JQuery
    4) Only use PHP

    It looks like you're already doing some javascripting. There must be more to your scripting than you are showing us? Is there javascripting that we are not seeing? So the answer to your problem is very abstract. What kind of experience should the user have when filling out the form?


  4. #3
    Member Elvedin's Avatar
    Join Date
    Jan 2013
    Location
    Bosnia And Herzegowina
    Posts
    78
    Member #
    35009
    Okay , I will explain it better now.

    Well this code is named " MailHandler.php " >
    PHP Code:
    <?php
    if(isset($_POST['send'])){

    $to "hqwebs.eu@gmail.com";
    $name=$_POST['name'];
    $phone $_POST['phone'];
    $email $_POST ['email'];
    $message $_POST['message']. "\n\n Phone Number is : " .$phone;
    $headers "From:" $email  ;
    mail($to,$name,$message,$headers);

    if(
    mail){
    echo 
    "Mail Sent.";
    }else{
        echo 
    "Cannot Send your mail for error";
    }
    }
    ?>
    And this code is inside my html file >
    HTML Code:
    <form id="contact-form" action="bin/MailHandler.php" method="post">
    <fieldset>
    <label>
    <input type="text" name="name" value="Name" onBlur="if(this.value=='') this.value='Name'" onFocus="if(this.value =='Name' ) this.value=''" />
    </label>
    <label>
    <input type="text" name="email" value="Email" onBlur="if(this.value=='') this.value='Email'" onFocus="if(this.value =='Email' ) this.value=''" />
    </label>
    <label>
    <input type="text" name="phone" value="Phone" onBlur="if(this.value=='') this.value='Phone'" onFocus="if(this.value =='Phone' ) this.value=''" />
    </label>
    <label>
    <input type="text" name="code" value="Order Code" onBlur="if(this.value=='') this.value='Order Code'" onFocus="if(this.value =='Order Code' ) this.value=''" /> &nbsp; <a href="images/orderhelp.jpg" rel="lightbox" title="What is Order Code"><img src="images/help.png" alt="" /></a>
    </label>
    <textarea name="message" onBlur="if(this.value=='') this.value='Message'" onFocus="if(this.value =='Message' ) this.value=''">Message</textarea>
    <div class="buttons-wrapper">
    <a class="button" onClick="document.getElementById('contact-form').reset()">Clear</a>
    <a class="button" onClick="document.getElementById('contact-form').submit()">Send</a>
    </div>
    </fieldset>
    </form>
    So this php script is called from folder bin , as you can see here >

    <form id="contact-form" action="bin/MailHandler.php" method="post">
    And everything is working fine.
    Now i want to add only some fields required , so when someone is filling the fields , he should write something in required filds , its not important what he will write , its important only to write anything in this required field. So if user didnt write anything in required field , he should het an error which will tell him something like " Required field not filled in " bla bla ..

    If its possible , one guy gave me this code , but something is wrong , its not working ... >
    PHP Code:
    <?php
    $fields 
    = array('message','email');  // required fields go in here
    $errors=false;
    if(isset(
    $_POST['send']))
        {
            
    array_walk($_POST'cleanMe'); // Clean up the input
            
    $to "hqwebs.eu@gmail.com";
            
    $name=$_POST['name'];
            
    $phone $_POST['phone'];
            
    $email $_POST ['email'];
            
    $message $_POST['message']. "\n\n Phone Number is " .$phone;
            
    $headers "From:" $email  ;

          
    /**
            * Checks fields to see if they are empty
            */
            
    foreach($fields as $field)
            {
                if( 
    strlen($_POST[$field]) == )
                {
                    
    $errors true;
                    break;
                }
            }

            if(!
    $errors// If none of the required fields produced an error then try to email
            
    {
                
    mail($to,$name,$message,$headers);

                if(
    mail)
                {
                    echo 
    "Mail Sent.";
                }
                else
                {
                    echo 
    "Cannot Send your mail for error";
                }
            }
            else 
    // One or more of the required fields wasn't filled in
            
    {
                echo 
    'Fields marked with a * are required';
            }
     
        }
    /**
    *
    * Clean up input from the user
    * @param type $data
    * @return string
    */
    function cleanMe($data)
        {
            
    $data trim($data);
            
    $data stripslashes($data);
            
    $data htmlspecialchars($dataENT_QUOTES);
            return 
    $data;
        }
    ?>
    So it will be good if it can be done with this codes , just to repair this or add something . Its not important to me which type of codes it will be , its important to me just to get it working correctly.

    Thank you very much for spending your time on my problem.

  5. #4
    WDF Staff mlseim's Avatar
    Join Date
    Apr 2004
    Location
    Cottage Grove, Minnesota
    Posts
    7,716
    Member #
    5580
    Liked
    718 times
    What is the page called where your HTML form resides? Is it something.php or something.html?

    Your form processing needs to return back to the form page and redisplay it. That adds a bit of complexity because when the form page refreshes, their data is lost. So the PHP script needs to return back the form variables along with an error message. That makes your entire page with the form refresh, and that may, or may not, be desirable to you.

    Your form also has no type of captcha or scripting to make sure the user is human and not a spamming robot.

    There are many examples for JQuery and AJAX scripts that handle both issues ... validation and captcha.

    Doing a Google search, I found this one (see their demo):
    http://www.99points.info/2010/08/aja...query-and-php/

    Their captcha is easy to read (some are really bad). There are also captchas where it asks a question like: What is 5+3? Anything to determine if the user is human or not.

    Here is a variety of forms, with and without captcha ... look at #14, they have you drag a picture into the box.
    http://www.redfoxmagazine.com/30-awe...-contact-form/

    So my point is ... validating, finding an error, and reporting it back isn't really an easy thing to do if you want the experience to be seamless for the user.


  6. #5
    Member Elvedin's Avatar
    Join Date
    Jan 2013
    Location
    Bosnia And Herzegowina
    Posts
    78
    Member #
    35009
    This code is inside my order.html file

    HTML Code:
    <form id="contact-form" action="bin/MailHandler.php" method="post">
    <fieldset>
    <label>
    <input type="text" name="name" value="Name" onBlur="if(this.value=='') this.value='Name'" onFocus="if(this.value =='Name' ) this.value=''" />
    </label>
    <label>
    <input type="text" name="email" value="Email" onBlur="if(this.value=='') this.value='Email'" onFocus="if(this.value =='Email' ) this.value=''" />
    </label>
    <label>
    <input type="text" name="phone" value="Phone" onBlur="if(this.value=='') this.value='Phone'" onFocus="if(this.value =='Phone' ) this.value=''" />
    </label>
    <label>
    <input type="text" name="code" value="Order Code" onBlur="if(this.value=='') this.value='Order Code'" onFocus="if(this.value =='Order Code' ) this.value=''" /> &nbsp; <a href="images/orderhelp.jpg" rel="lightbox" title="What is Order Code"><img src="images/help.png" alt="" /></a>
    </label>
    <textarea name="message" onBlur="if(this.value=='') this.value='Message'" onFocus="if(this.value =='Message' ) this.value=''">Message>
    <div class="buttons-wrapper">
    <a class="button" onClick="document.getElementById('contact-form').reset()">Clear>
    <a class="button" onClick="document.getElementById('contact-form').submit()">Send>
    </div>
    </fieldset>
    </form>
    __________________________________

    mlseim , i see you are trying to give me an quality contact form , and i saw many finished scripts .
    But if its possible to edit my current contact script.

    I dont need captcha , and i dont need anything else.
    I need only to make some fields required , when some1 dont write anything in this field , after he press send button , he should recieve an message that will tell him that he didnt filled the required fields , The text filled in must not be saved when he get error message , it can be deleted and let the user write everything from start . So if its possible , thank you vm.

  7. #6
    WDF Staff mlseim's Avatar
    Join Date
    Apr 2004
    Location
    Cottage Grove, Minnesota
    Posts
    7,716
    Member #
    5580
    Liked
    718 times
    Can you show me the entire "order.html" file?
    I think if it were "order.php", we could do the form AND the scripting all in the same script.

    But before that, is there a reason that you have a directory called "bin"? Is that a requirement of your webhost, or did you just arbitrarily create that?


  8. #7
    Member Elvedin's Avatar
    Join Date
    Jan 2013
    Location
    Bosnia And Herzegowina
    Posts
    78
    Member #
    35009
    I`ll send you the file "order.html" when i come home, but this file is not order.html anymore , i renamed it and edited a little bit , added some fields ... But its not important , still need the same thing to change " required "

    Well , there is not any reason why the file is inside "bin" folder , ts working in other folders too , and i repleaced it to other folder , everything is still working fine , just need to edit this damn thing " required "

  9. #8
    Member Elvedin's Avatar
    Join Date
    Jan 2013
    Location
    Bosnia And Herzegowina
    Posts
    78
    Member #
    35009
    Okay , its " online-upis.html "
    Download link : http://depositfiles.com/files/l5986ca6o

    I want next fields to be required :

    1) Ime i prezime
    2) Ime jednog roditelja
    3) Datum ro?enja
    4) Jedinstveni mati?ni broj
    5) Adresa stanovanja
    6) Broj li?ne karte
    7) Mjesto izdavanja li?ne karte
    8) Kontakt telefon

    So its everything except " Email adresa " and " Napomena ili poruka " .
    So again thanks for spending your time on my problem.

  10. #9
    WDF Staff mlseim's Avatar
    Join Date
    Apr 2004
    Location
    Cottage Grove, Minnesota
    Posts
    7,716
    Member #
    5580
    Liked
    718 times
    sorry ... my PC won't open RAR files.


  11. #10
    Member Elvedin's Avatar
    Join Date
    Jan 2013
    Location
    Bosnia And Herzegowina
    Posts
    78
    Member #
    35009
    Okay , here is another link , downloads directly as html : http://www.2shared.com/document/IL4X...line-upis.html


Page 1 of 3 1 2 3 LastLast

Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

Search tags for this page

required field php contact

Click on a term to search for related topics.
All times are GMT -6. The time now is 03:04 AM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com