Facing problems with $_POST. Data can not be processed by PHP...

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sufian
    New Member
    • Jul 2006
    • 9

    Facing problems with $_POST. Data can not be processed by PHP...

    I am new to the world of PHP. Below is my simple PHP file "invite.php " with a form having an image send button (I have to use the image send button because it is the requirement, may be this is causing problem!):

    [code=html]
    <html>
    <head><title>Fo rm</title>
    </head>
    <body>
    <script language="javas cript" src="validation .js"></script>
    <form action="submit. php" method="POST">
    <table border ="0" align="center" cellpadding="9" cellspacing="1" >
    <tr>
    <td colspan="2">Ent er Your Friends' E-mail Addresses<br/>Separate multiple addresses with a comma<br/>
    <textarea name="emails" id="emails" class="subheadi ng" value="" rows="5" cols="52" onfocus= "javascript :if (document.getEl ementById('emai ls').value=='') { document.getEle mentById('email s').value=''; }" onblur="javascr ipt:if (document.getEl ementById('emai ls').value=='') { document.getEle mentById('email s').value=''; }"></textarea>
    </td>
    </tr>
    <tr>
    <td>Meeting Date<br/>
    <input type="text" name="inputDate " id="inputDate" class="subheadi ng" value="" maxlength="17" size="32" onfocus= "javascript :if (document.getEl ementById('inpu tDate').value== '') { document.getEle mentById('input Date').value='' ; }" onblur="javascr ipt:if (document.getEl ementById('inpu tDate').value== '') { document.getEle mentById('input Date').value='' ; }" />&nbsp;<img src="calendar.g if" alt="Calendar" name="calendar" width="14" height="14" id="calendar" />
    </td>
    <td>Meeting Time<br/>
    <input type="text" name="meettime" id="meettime" class="subheadi ng" value=" Noon to Midnight" maxlength="36" size="36" onfocus= "javascript :if (document.getEl ementById('meet time').value==' Noon to Midnight') { document.getEle mentById('meett ime').value=''; }" onblur="javascr ipt:if (document.getEl ementById('meet time').value==' ') { document.getEle mentById('meett ime').value=' Noon to Midnight'; }" />
    </td>
    </tr>
    <tr>
    <td>Your Name<br/>
    <input type="text" name="vname" id="vname" class="subheadi ng" value=" Your Name" maxlength="36" size="36" onfocus= "javascript :if (document.getEl ementById('vnam e').value==' Your Name') { document.getEle mentById('vname ').value=''; }" onblur="javascr ipt:if (document.getEl ementById('vnam e').value=='') { document.getEle mentById('vname ').value=' Your Name'; }" />
    </td>
    <td>Your E-mail Address<br/>
    <input type="text" name="visitorma il" id="visitormail " class="subheadi ng" value=" Your E-Mail Address" maxlength="36" size="36" onfocus= "javascript :if (document.getEl ementById('visi tormail').value ==' Your E-Mail Address') { document.getEle mentById('visit ormail').value= ''; }" onblur="javascr ipt:if (document.getEl ementById('visi tormail').value =='') { document.getEle mentById('visit ormail').value= ' Your E-Mail Address'; }" />
    </td>
    </tr>
    <tr>
    <td colspan="2">Opt ional Message<br/>
    <textarea name="message" id="message" class="subheadi ng" value="" rows="5" cols="52" onfocus= "javascript :if (document.getEl ementById('mess age').value=='' ) { document.getEle mentById('messa ge').value=''; }" onblur="javascr ipt:if (document.getEl ementById('mess age').value=='' ) { document.getEle mentById('messa ge').value=''; }"></textarea>
    <p align="left"><i nput type="image" src="send.gif" name="send" alt="Send" value="Send" onclick="fValid ateContact(this .form); return false;" /></p>
    </td>
    </tr>
    </table>
    </form>
    </body>
    </html>

    The file mentioned in (action="submit .php") is as under:

    <html>
    <head><title>Su ccess Message</title>
    </head>
    <body>
    <?php
    $inputDate = $HTTP_POST_VARS['inputDate'];
    $meettime = $HTTP_POST_VARS['meettime'];
    $visitormail = $_POST['visitormail'];
    ?>
    <table border ="0" align="center" cellpadding="9" >
    <tr>
    <td align="center"> <p align="center"> Success! Your Data has been processed by PHP. Details are: <br />
    Your Email address was: <?php echo $visitormail; ?><br />
    Meeting Date was : <?php echo $inputDate ?><br />
    Meeting Time was : <?php echo $meettime ?><br /></p>
    </td>
    </tr>
    </table>
    </body>
    </html>

    Finally "validation .js" is as under:

    function fValidateContac t(form)
    {
    if(form.emails. value == '')
    {
    alert("Please enter Your Friend's Email to proceed."); form.emails.foc us();
    }
    else if((form.emails .value.indexOf( ".") == -1) || (form.emails.va lue.indexOf("@" ) == -1))
    {
    alert("Please enter a valid Friend's Email."); form.emails.foc us();
    }
    else if(form.inputDa te.value == '')
    {
    alert("Please choose Meeting Date from the Calendar."); form.inputDate. focus();
    }
    else if(form.meettim e.value == '')
    {
    alert("Please enter Meeting Time to proceed."); form.meettime.f ocus();
    }
    else if(form.vname.v alue == '')
    {
    alert("Please enter Your Name to proceed."); form.vname.focu s();
    }
    else if(form.visitor mail.value == '')
    {
    alert("Please enter Email Address to proceed."); form.visitormai l.focus();
    }
    else if((form.visito rmail.value.ind exOf(".") == -1) || (form.visitorma il.value.indexO f("@") == -1))
    {
    alert("Please enter a valid Email Address."); form.visitormai l.focus();
    }
    else
    form.submit(); //May be this is the mistake? But what should I do then?
    }[/code]

    [Please use CODE tags when posting source code. Thanks! --pbmods]

    I don't understand why PHP is not processing the data provided especially:
    $visitormail = $_POST['visitormail'];
    Please help me out. Thanks.
  • Anthony2oo5
    New Member
    • Jun 2007
    • 26

    #2
    Can you simplify your code for us and also explain what is the problem more.

    Comment

    • epots9
      Recognized Expert Top Contributor
      • May 2007
      • 1352

      #3
      give your form a name/id:
      [HTML]<form action="submit. php" method="POST" name="form1" id="form1"> [/HTML]
      try instead of passing this.form, pass nothing and in the function do:
      [CODE=javascript]var form = document.form1;[/CODE]

      Comment

      • Purple
        Recognized Expert Contributor
        • May 2007
        • 404

        #4
        Hi all,

        I have done a couple of tweeks to the php in this code follows:

        [PHP]
        <?php
        if (isset($_POST['inputDate'])) $inputDate = $_POST['inputDate']; else $inputDate = null;
        if (isset($_POST['meettime'])) $meettime = $_POST['meettime']; else $meettime = null;
        if (isset($_POST['visitormail'])) $visitormail = $_POST['visitormail']; else $visitormail = null;
        ?>
        [/PHP]

        will fix the error messages on the first run, when I tested it the javascript validation worked ok

        try these sugestions and post back if you are still having problems with a bit more of an explanation of your issue..

        Regards Purple
        Last edited by Purple; Jun 13 '07, 03:02 PM. Reason: formatting looked awful :)

        Comment

        • sufian
          New Member
          • Jul 2006
          • 9

          #5
          Hi all,
          Thanks for your kind reply. I am still facing the same problems!
          I have given a name and id to the form in invite.php and moreover follows the second advice regarding Javascript, but the issue is not resolved. Furthermore the code provided by Purple could not resolved the issue. I have also tried the following code in submit.php

          [code=php]
          <?php
          print_r ($_POST);
          ?>[/code]

          But its not working indicating that this file is not receiving POST variables.

          Here is the problem in more detail:
          When I click the Submit button the submit.php file only displays the text but no data which was inserted on the form of the previous php file (invite.php). If data could not be processed by PHP then how come I send an auto mail reply to the visitor of this form (which is yet another requirement to be fulfilled)? Because as far as my limited knowledge the mail function in php takes the recepient email as its first argument.
          Actually this page would be part of a coffee shop website (www.t2f.biz) made on Word Press and someone who wants to meet his/her friends at the coffee shop at a specified time and date will enter the details here and would get an auto mail reply with the following message:
          Sabeen Mahmud has invited you to meet up at The Second Floor on <the date selected from calendar> at <the time inserted in the text field>

          and the stuff like that.

          Comment

          • Purple
            Recognized Expert Contributor
            • May 2007
            • 404

            #6
            Hi,

            Can you post the code as it is now into this - please can you wrap it in php code tags by highlighting the code after it has been inserted and pressing the php button on the right of the menu above.

            Purple

            Comment

            • Purple
              Recognized Expert Contributor
              • May 2007
              • 404

              #7
              Hi,

              I have setup and run your forms based on the changes I suggested and follow is the output, note the array is the output of a print_r($_POST) :

              Code:
              Array ( [emails] => my@email.address [inputDate] => 20/20/20 [meettime] => Noon to Midnight [vname] => adam [visitormail] => me@mine.com [message] => optional message ) 
              
              Success! Your Data has been processed by PHP. 
              Details are: 
              Your Email address was: me@mine.com
              Meeting Date was : 20/20/20
              Meeting Time was : Noon to Midnight
              your code with a couple of changes is as follows:

              invite.php:

              [HTML]<html>
              <head><title>Fo rm</title>
              </head>
              <body>
              <script language="javas cript" src="validation .js"></script>
              <form action="submit. php" method="POST">
              <table border ="0" align="center" cellpadding="9" cellspacing="1" >
              <tr>
              <td colspan="2">Ent er Your Friends' E-mail Addresses<br/>Separate multiple addresses with a comma<br/>
              <textarea name="emails" id="emails" class="subheadi ng" value="" rows="5" cols="52" onfocus= "javascript :if (document.getEl ementById('emai ls').value=='') { document.getEle mentById('email s').value=''; }" onblur="javascr ipt:if (document.getEl ementById('emai ls').value=='') { document.getEle mentById('email s').value=''; }"></textarea>
              </td>
              </tr>
              <tr>
              <td>Meeting Date<br/>
              <input type="text" name="inputDate " id="inputDate" class="subheadi ng" value="" maxlength="17" size="32" onfocus= "javascript :if (document.getEl ementById('inpu tDate').value== '') { document.getEle mentById('input Date').value='' ; }" onblur="javascr ipt:if (document.getEl ementById('inpu tDate').value== '') { document.getEle mentById('input Date').value='' ; }" />&nbsp;<img src="calendar.g if" alt="Calendar" name="calendar" width="14" height="14" id="calendar" />
              </td>
              <td>Meeting Time<br/>
              <input type="text" name="meettime" id="meettime" class="subheadi ng" value=" Noon to Midnight" maxlength="36" size="36" onfocus= "javascript :if (document.getEl ementById('meet time').value==' Noon to Midnight') { document.getEle mentById('meett ime').value=''; }" onblur="javascr ipt:if (document.getEl ementById('meet time').value==' ') { document.getEle mentById('meett ime').value=' Noon to Midnight'; }" />
              </td>
              </tr>
              <tr>
              <td>Your Name<br/>
              <input type="text" name="vname" id="vname" class="subheadi ng" value=" Your Name" maxlength="36" size="36" onfocus= "javascript :if (document.getEl ementById('vnam e').value==' Your Name') { document.getEle mentById('vname ').value=''; }" onblur="javascr ipt:if (document.getEl ementById('vnam e').value=='') { document.getEle mentById('vname ').value=' Your Name'; }" />
              </td>
              <td>Your E-mail Address<br/>
              <input type="text" name="visitorma il" id="visitormail " class="subheadi ng" value=" Your E-Mail Address" maxlength="36" size="36" onfocus= "javascript :if (document.getEl ementById('visi tormail').value ==' Your E-Mail Address') { document.getEle mentById('visit ormail').value= ''; }" onblur="javascr ipt:if (document.getEl ementById('visi tormail').value =='') { document.getEle mentById('visit ormail').value= ' Your E-Mail Address'; }" />
              </td></tr><tr><td colspan="2">Opt ional Message<br/>
              <textarea name="message" id="message" class="subheadi ng" value="" rows="5" cols="52" onfocus= "javascript :if (document.getEl ementById('mess age').value=='' ) { document.getEle mentById('messa ge').value=''; }" onblur="javascr ipt:if (document.getEl ementById('mess age').value=='' ) { document.getEle mentById('messa ge').value=''; }"></textarea>
              <p align="left"><i nput type="image" src="send.gif" name="send" alt="Send" value="Send" onclick="fValid ateContact(this .form); return false;" /></p>
              </td></tr></table></form></body></html>[/HTML]

              submit.php

              [PHP]<html><head><ti tle>Success Message</title></head><body>
              <?php
              print_r($_POST) ;
              if (isset($_POST['inputDate'])) $inputDate = $_POST['inputDate']; else $inputDate = null;
              if (isset($_POST['meettime'])) $meettime = $_POST['meettime']; else $meettime = null;
              if (isset($_POST['visitormail'])) $visitormail = $_POST['visitormail']; else $visitormail = null;
              ?>
              <table border ="0" align="center" cellpadding="9" >
              <tr>
              <td align="center"> <p align="center"> Success! Your Data has been processed by PHP. Details are: <br />
              Your Email address was: <?php echo $visitormail; ?><br />
              Meeting Date was : <?php echo $inputDate ?><br />
              Meeting Time was : <?php echo $meettime ?><br /></p>
              </td></tr></table></body></html> [/PHP]

              and finally validation.js:

              [CODE=javascript]function fValidateContac t(form)
              {
              if(form.emails. value == '')
              {
              alert("Please enter Your Friend's Email to proceed."); form.emails.foc us();
              }
              else if((form.emails .value.indexOf( ".") == -1) || (form.emails.va lue.indexOf("@" ) == -1))
              {
              alert("Please enter a valid Friend's Email."); form.emails.foc us();
              }
              else if(form.inputDa te.value == '')
              {
              alert("Please choose Meeting Date from the Calendar."); form.inputDate. focus();
              }
              else if(form.meettim e.value == '')
              {
              alert("Please enter Meeting Time to proceed."); form.meettime.f ocus();
              }
              else if(form.vname.v alue == '')
              {
              alert("Please enter Your Name to proceed."); form.vname.focu s();
              }
              else if(form.visitor mail.value == '')
              {
              alert("Please enter Email Address to proceed."); form.visitormai l.focus();
              }
              else if((form.visito rmail.value.ind exOf(".") == -1) || (form.visitorma il.value.indexO f("@") == -1))
              {
              alert("Please enter a valid Email Address."); form.visitormai l.focus();
              }
              else
              form.submit(); //May be this is the mistake? But what should I do then?
              }[/CODE]

              I suggest you copy my three code blocks and run them as posted and see it that works for you - you can see from the output of the submit.php and print_r($_POST) that all of the form variables I entered in invite.php have been carried through to submit.php.

              All of that said, I may be completely missing the point here - if that is the case just say so and have another go at telling me the problem

              Regards Purple
              Last edited by Purple; Jun 14 '07, 08:33 AM. Reason: format

              Comment

              • sufian
                New Member
                • Jul 2006
                • 9

                #8
                Hi,
                Thanks for your quick reply.
                Actually I am working in a Network environment (LAN of the company) where PHP is installed only on a server not on my PC. A drive of that server was mapped on my PC when I have given this PC on the first day of my job a few days ago. When given this task I have created a new folder in that mapped drive and start coding PHP. In this mapped drive all of the company's web applications folders are already kept and all applications are working properly from browser on my PC (those application ofcourse contain some PHP code which is functional). Therefore I thought since PHP is working fine at that server, it will also work when I will write code!
                I guess this mapped network drive is causing problem because when I have tested the following simple code at M:\Sufian\Proje cts\Self Testing for PHP
                where M is the network mapped drive of the server.

                [PHP]<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">
                <html xmlns="http://www.w3.org/1999/xhtml">
                <head>
                <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
                <title>Web Forms in PHP</title>
                </head>
                <body>
                <h1>Web Forms in PHP</h1>
                <form action="guest.p hp" method="post">
                <table border="0">
                <tr><td>Your Name:</td>
                <td><input type="text" maxlength="32" size="20" name="user" /></td></tr>
                <tr><td>Your Email Address:</td>
                <td><input type="text" maxlength="32" size="20" name="mail" /></td></tr>
                <tr><td><inpu t type="submit" value="Submit Deatils" /></td>
                <td><input type="reset" value="Reset The Form" /></td></tr>
                </table>
                </form>
                </body>
                </html>
                [/PHP]

                guest.php is as under:

                [PHP]<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">
                <html xmlns="http://www.w3.org/1999/xhtml">
                <head>
                <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
                <title>Your Data</title>
                </head>
                <body>
                <h1>Your Data Processes By PHP</h1>
                <table border="0">
                <tr><th>Your Name:</th><td><?php echo $_POST['user']; ?></td></tr>
                <tr><th>Your Email Address:</th><td><?php echo $_POST['mail']; ?></td></tr></table>
                </body>
                </html>
                [/PHP]

                Then PHP code is not working.
                When I have discussed this problem with a senior colleague, he is saying we have been working for seven years like that and PHP should work like that. Can you please comment on it?
                The solution that I am thinking now is to install PHP latest version on my PC and then try to complete my task.
                Last but not the least I am from the bottom of my heart really grateful for your kind responses.
                May Allah bless you.

                Comment

                • Purple
                  Recognized Expert Contributor
                  • May 2007
                  • 404

                  #9
                  Hi,

                  try this code:

                  [PHP]<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
                  <html>
                  <head>
                  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
                  <title>New document</title>
                  </head>
                  <body>
                  php info follows<br/>
                  <?php phpinfo();?>
                  php info preceeds<br/>
                  </body>
                  </html>[/PHP]

                  and let me know if you get a page full of info on your PHP installation config

                  Regards Purple

                  Comment

                  • sufian
                    New Member
                    • Jul 2006
                    • 9

                    #10
                    PHP was not working from:
                    M:\Sufian\Proje cts\Self Testing for PHP
                    But it is working from:
                    M:\t2fv2\Sufian \Projects\Self Testing for PHP
                    Where t2fv2 is the name of one of the application installed at that mapped drive.
                    I get the page full of info of my PHP installation config from there. Now I have also tried the code provided by you and its working!!!!!!!! !!!!!!!!!!!!!
                    Thanks a lot.

                    Comment

                    • Purple
                      Recognized Expert Contributor
                      • May 2007
                      • 404

                      #11
                      Hi sufian,

                      I am really pleased you got this working.

                      I look forward to hearing more from you on TSDN.

                      Regards Purple.

                      Comment

                      Working...