1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Help me create a form with PHP

Discussion in 'PHP' started by Emperor, Sep 12, 2007.

  1. #1
    I'm trying to create a nice little form for my site but am having a few problems getting the job done.

    I've created the html code and now I would like to know how to integrate php with it.

    Can anyone help me with this?

    Thanks
     
    Emperor, Sep 12, 2007 IP
  2. undir

    undir Peon

    Messages:
    696
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Why dont you just download some free snippet to do your work
     
    undir, Sep 12, 2007 IP
  3. undir

    undir Peon

    Messages:
    696
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Actually it is very easy. Just tell me what you want to do with the data. Email it or store it in a database?
     
    undir, Sep 12, 2007 IP
  4. tushardhoot1

    tushardhoot1 Active Member

    Messages:
    3,013
    Likes Received:
    96
    Best Answers:
    0
    Trophy Points:
    90
    #4
    Tell us what you need to do, we'll help.
     
    tushardhoot1, Sep 12, 2007 IP
  5. Emperor

    Emperor Guest

    Messages:
    4,821
    Likes Received:
    180
    Best Answers:
    0
    Trophy Points:
    0
    #5
    The reason is I want to learn how to do it and thought it would be a nice project for me to do today. :D

    So here's the story. I wanted to create a simple form for my site. The idea was to have visitors fill in a form that was coded in html "at the time I thought I could do it all only using HTML".

    Then I used php to have everything printed in a file "example: form.php" that would pop up.

    <form action="action.php" method="post">
     <p>Your name: <input type="text" name="name" /></p>
     <p>Your age: <input type="text" name="age" /></p>
     <p><input type="submit" /></p>
    </form>
    
    Code (markup):
    Hi <?php echo htmlspecialchars($_POST['name']); ?>.
    You are <?php echo (int)$_POST['age']; ?> years old.
    
    A sample output of this script may be:
    
    Hi Joe. You are 22 years old.
    
    
    Code (markup):
    Sample code of what my form does NOT THE ACTUAL CODE I'VE WRITTEN

    Here's the part I haven't done yet. I don't want a html page to pop up. Using a php string I want the code to apear in a code Box bellow the form on my site.
     
    Emperor, Sep 12, 2007 IP
  6. undir

    undir Peon

    Messages:
    696
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Hi <?php echo htmlspecialchars($_POST['name']); ?>.
    You are <?php echo int($_POST['age']); ?> years old.
     
    undir, Sep 12, 2007 IP
  7. undir

    undir Peon

    Messages:
    696
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    0
    #7
    <form action="action.php" method="post">
     <p>Your name: <input type="text" name="name" /></p>
     <p>Your age: <input type="text" name="age" /></p>
     <p><input type="submit" /></p>
    </form>
    
    <?php
    
    if (isset($_POST['name'])) {
    ?>
    Hi <?php echo htmlspecialchars($_POST['name']); ?>.
    You are <?php echo int($_POST['age']); ?> years old.
    <?
    }
    
    ?>
    PHP:
     
    undir, Sep 12, 2007 IP
  8. Emperor

    Emperor Guest

    Messages:
    4,821
    Likes Received:
    180
    Best Answers:
    0
    Trophy Points:
    0
    #8
    This is the link to what I've got done. If you see my site I'm sure you'll understand better what I want to do.

    Fill in the form and you'll see, everything works correctly. I just need that finishing touch.
     
    Emperor, Sep 12, 2007 IP
  9. undir

    undir Peon

    Messages:
    696
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    0
    #9
    What are you trying to achieve?
     
    undir, Sep 12, 2007 IP
  10. Emperor

    Emperor Guest

    Messages:
    4,821
    Likes Received:
    180
    Best Answers:
    0
    Trophy Points:
    0
    #10
    People fill in the details and out comes a subscription link for paypal.... ;)
     
    Emperor, Sep 12, 2007 IP
  11. undir

    undir Peon

    Messages:
    696
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    0
    #11
    why do you want to show it in another page. why cant you show it below the same form?
     
    undir, Sep 12, 2007 IP
  12. tushardhoot1

    tushardhoot1 Active Member

    Messages:
    3,013
    Likes Received:
    96
    Best Answers:
    0
    Trophy Points:
    90
    #12
    Ok.

    So you want to create a form processor that'll take those entries and then make a paypal "suscribe now" button, correct?
     
    tushardhoot1, Sep 12, 2007 IP
  13. Emperor

    Emperor Guest

    Messages:
    4,821
    Likes Received:
    180
    Best Answers:
    0
    Trophy Points:
    0
    #13
    That's exactly what I'm trying to do :rolleyes: but haven't been able to achieve yet.
    I want the link to shown right bellow the form. If you could help me with that I would really appreciate it.



    Edit

    100% correct. All I need to do is have the link displayed bellow the forum and I'll be very happy. :D
     
    Emperor, Sep 12, 2007 IP
  14. undir

    undir Peon

    Messages:
    696
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    0
    #14
    Hi Tushar. Hoping youll help him out I am outta here. 5.15. am. But hey I dont mind working on it if you cant manage it. Emperor please PM me if you need it.
     
    undir, Sep 12, 2007 IP
    Emperor likes this.
  15. tushardhoot1

    tushardhoot1 Active Member

    Messages:
    3,013
    Likes Received:
    96
    Best Answers:
    0
    Trophy Points:
    90
    #15
    Ok.

    Well first you need to create a random subscription and see what the link structure is like.

    Basically you need to learn how paypal makes a new subscription link.


    This could be, for example; www.paypal.com?processpayment_userid_[youruseridhere]_subscriptionemail_[insert email here]
     
    tushardhoot1, Sep 12, 2007 IP
  16. DKameleon

    DKameleon Member

    Messages:
    29
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    38
    #16
    If you want to do it without refreshing page you need to do it with JavaScript (without PHP) or using AJAX (in this case url will be generated with PHP on the server), or even with iframe.

    Here is an AJAX solution:

    form.html:
    <script type="text/javascript" src="prototype.js"></script>
    <script type="text/javascript">
    	function Process(form) {
    		var myAjax = new Ajax.Updater(
    			"container",
    			"form.php",
    			{
    				method: "post",
    				parameters: {
    					name: form.name.value,
    					age: form.age.value,
    				}
    			}
    		);
    		return false;
    	}
    </script>
    <form action="" method="post" onsubmit="Process(this); return false;">
    	<p>Your name: <input type="text" name="name" /></p>
    	<p>Your age: <input type="text" name="age" /></p>
    	<p><input type="submit" /></p>
    </form>
    
    <div id="container"></div>
    
    HTML:
    form.php:
    <a href="<?=@$_POST["name"];?>"><?=@$_POST["age"];?></a>
    PHP:
    Also you need to include prototype.js from _http://www.prototypejs.org/download

    Now you just need to update this solution with your fields. Hope it helps you. :)

    Regards.
     
    DKameleon, Sep 12, 2007 IP
  17. Emperor

    Emperor Guest

    Messages:
    4,821
    Likes Received:
    180
    Best Answers:
    0
    Trophy Points:
    0
    #17
    Wow, I'm having a few problems with that code DKameleon. I added the javascript code and downloaded the prototype.js file. When I fill my form now the only things that happens is the page refreshes...

    Does anyone know what I'm doing wrong? I'll post all my code here.


    This is the form code.

    <script type="text/javascript" src="prototype.js"></script>
    <script type="text/javascript">
        function Process(form) {
            var myAjax = new Ajax.Updater(
                "container",
                "form.php",
                {
                    method: "post",
                    parameters: {
                        name: form.name.value,
                        age: form.age.value,
                    }
                }
            );
            return false;
        }
    </script>
    <table>
    <form action="code.php" method="post" onsubmit="Process(this); return false;">
    <tr><td>Paypal ID:</td><td><input type="text" name="ID"></td></tr>
    <tr><td>Item name:</td><td><input type="text" name="Item"></td></tr>
    <tr><td>Item number:</td><td><input type="text" name="Number"></td></tr>
    <tr><td>Currency: </td><td>
      <select name="Currency">
        <option>USD</option>
        <option>EUR</option>
        <option>CAD</option>
      </select></td></tr>
    <tr><td>Cost: </td><td><input type="text" name="Cost"></td></tr>
    <tr><td>Cicle:</td><td><input type="text" name="Cicle"></td></tr>
    <tr><td>Cicle unit: </td><td>
      <select name="CicleU">
        <option>M</option>
        <option>Y</option>
        <option>D</option>
      </select></td></tr>
    <tr><td> <input type="submit"></td></tr>
     
      </form>
    </table> 
    
    <div id="container"></div>
    Code (markup):

    I downloaded the prototype.js file and put it in the root directory, is that corret?

    Please take a look at the form for a better idea of what I'm talking about.
     
    Emperor, Sep 13, 2007 IP
  18. mikebrad0927

    mikebrad0927 Peon

    Messages:
    266
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #18
    <form action="code.php" method="post" onsubmit="Process(this); return false;">
    Code (markup):
    should be

    <form action="" method="post" onsubmit="Process(this); return false;">
    Code (markup):
     
    mikebrad0927, Sep 13, 2007 IP
  19. mikebrad0927

    mikebrad0927 Peon

    Messages:
    266
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #19
    also, what do you have in form.php?
     
    mikebrad0927, Sep 13, 2007 IP
  20. Emperor

    Emperor Guest

    Messages:
    4,821
    Likes Received:
    180
    Best Answers:
    0
    Trophy Points:
    0
    #20
    I have this

    <html>
    <body>
    https://www.paypal.com/cgi-bin/webscr?cmd=_xclick-subscriptions&business=<?php echo $_POST["ID"]; ?>
    %20&item_name=<?php echo $_POST["Item"]; ?> 
    &item_number=<?php echo $_POST["Number"]; ?>
    &no_shipping=1&no_note=1currency_code=<?php echo $_POST["Currency"]; ?> 
    &bn=PP%2dSubscriptionsBF&charset=UTF%2d8&a3=<?php echo $_POST["Cost"]; ?>
    &p3=<?php echo $_POST["Cicle"]; ?>
    &t3=<?php echo $_POST["CicleU"]; ?>&src=1&sra=1 
    </body>
    </html>
    Code (markup):
     
    Emperor, Sep 13, 2007 IP