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 2 1 2 LastLast
Results 1 to 10 of 17
  1. #1
    Member
    Join Date
    Jan 2004
    Posts
    68
    Member #
    4547
    I'm trying to have a form that user fill out. Once it's submitted I want it to be emailed. However, if they don't fill out all the fields I don't want it sent. In my efforts in achieving this I found that the if else statement wasn't working (or i was using it incorrectly). For now I just want it to say true if the form is filled out, and false if it's not. It's not doing that.

    Here's my PHP code:

    PHP Code:
    <?php

    $company
    =$_REQUEST['company'];
    $name=$_REQUEST['name'];
    $email=$_REQUEST['email'];
    $phone=$_REQUEST['phone'];
    $inquiry=$_REQUEST['inquiry'];
    $message='
                Company: $company
                Name: $name
                Email: $email
                Phone: $phone
                Inquiry:
                        $inquiry'
    ;
    $subject='CASFA Contact';

    if (isset(
    $_REQUEST['company']))
    {
        echo 
    'FALSE';
    }
    else
    {
        echo 
    'TRUE';
    }
    ?>
    Here's my HTML:

    HTML Code:
    <form method="get" type="input" action="test1.php">
    	<table id="join">
    		<tr>
    			<td><label for="company">Company Name: </label></td>
    			<td><input type="text" name="company" /></td>
    		</tr>
    		<tr>
    			<td><label for="name">Name: </label></td>
    			<td><input type="text" name="name" /></td>
    		</tr>
    		<tr>
    			<td><label for="email">E-mail Address: </label></td>
    			<td><input type="text" name="email" /></td>
    		</tr>
    		<tr>
    			<td><label for="phone">Phone: </label></td>
    			<td><input type="text" name="phone" /></td>
    		</tr>
    		<tr>
    			<td><label for="inquiry">Inquiry: </label></td>
    			<td><textarea name="inquiry" cols="40" rows="8" /></textarea></td>
    		</tr>
    		<tr>
    			<td></td>
    			<td><input type="submit" value="Submit" /></td>
    		</tr>
    	</table>
    	</form>
    Any ideas would be greatly appreciated.

    Thanks in advance,

    Jake

  2.  

  3. #2
    Senior Member
    Join Date
    May 2003
    Location
    UK
    Posts
    2,354
    Member #
    1326
    Your logic is wrong, if $_REQUEST['company'] is set, you want your script to echo 'true'.

    This works for me,
    PHP Code:
    <html>

    <head>

        <title>emailer check</title>

    </head>

    <body>

    <?php

    $company
    =$_REQUEST['company'];
    $name=$_REQUEST['name'];
    $email=$_REQUEST['email'];
    $phone=$_REQUEST['phone'];
    $inquiry=$_REQUEST['inquiry'];
    $message='
                Company: $company
                Name: $name
                Email: $email
                Phone: $phone
                Inquiry:
                        $inquiry'
    ;
    $subject='CASFA Contact';

    if (isset(
    $_REQUEST['company']))
    {
        echo 
    "true";
    }
    else
    {
        echo 
    "false";
    }
    ?> 

    <form method="get" type="input" action="<?php echo $_SERVER['PHP_SELF']; ?>">
        <table id="join">
            <tr>
                <td><label for="company">Company Name: </label></td>
                <td><input type="text" name="company" /></td>
            </tr>
            <tr>
                <td><label for="name">Name: </label></td>
                <td><input type="text" name="name" /></td>
            </tr>
            <tr>
                <td><label for="email">E-mail Address: </label></td>
                <td><input type="text" name="email" /></td>
            </tr>
            <tr>
                <td><label for="phone">Phone: </label></td>
                <td><input type="text" name="phone" /></td>
            </tr>
            <tr>
                <td><label for="inquiry">Inquiry: </label></td>
                <td><textarea name="inquiry" cols="40" rows="8" /></textarea></td>
            </tr>
            <tr>
                <td></td>
                <td><input type="submit" value="Submit" /></td>
            </tr>
        </table>
        </form>

    </body>
    </html>
    Though, that does not check that all fields are filled in.

  4. #3
    Member
    Join Date
    Jan 2004
    Posts
    68
    Member #
    4547
    I understand I had the echo of the true or false backward, but it still just always says true whether company is set or not.

  5. #4
    Senior Member
    Join Date
    May 2003
    Location
    UK
    Posts
    2,354
    Member #
    1326
    Is the code amended? As in, the logic sorted out?

    My example: www.bfsog.co.uk/emailercheck.php which is the code in my previous post.

  6. #5
    Member
    Join Date
    Jan 2004
    Posts
    68
    Member #
    4547
    Yes. Whether there is something in the company field or not, it says true.

  7. #6
    Senior Member
    Join Date
    May 2003
    Location
    UK
    Posts
    2,354
    Member #
    1326
    No idea, do not know if this will help, but try saving my code and running that.

  8. #7
    Member
    Join Date
    Jan 2004
    Posts
    68
    Member #
    4547
    I just tried your link, and it worked. Wierd that doesn't work on my local host, could have something to do with my settings in the ini file?

  9. #8
    Senior Member
    Join Date
    May 2003
    Location
    UK
    Posts
    2,354
    Member #
    1326
    It is strange, I dont know why it would do that, but if it works online then you are good to go..

    Maybe it's something to do with the $_REQUEST superglobal.

  10. #9
    Member
    Join Date
    Jan 2004
    Posts
    68
    Member #
    4547
    Does it matter if I have it in a separate file? I would prefer to keep my HTML and PHP separate.

  11. #10
    Senior Member
    Join Date
    May 2003
    Location
    UK
    Posts
    2,354
    Member #
    1326
    No, it does not matter, as long as your form tag points to the php file (in your case test1.php)


Page 1 of 2 1 2 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
  •  
All times are GMT -6. The time now is 05:08 AM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com