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
Actually it is very easy. Just tell me what you want to do with the data. Email it or store it in a database?
The reason is I want to learn how to do it and thought it would be a nice project for me to do today. 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.
Hi <?php echo htmlspecialchars($_POST['name']); ?>. You are <?php echo int($_POST['age']); ?> years old.
<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:
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.
Ok. So you want to create a form processor that'll take those entries and then make a paypal "suscribe now" button, correct?
That's exactly what I'm trying to do 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.
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.
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]
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.
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.
<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):
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):