Jump to content

[SOLVED] php form template


killsite

Recommended Posts

I work in a callcenter where we're required to log notes in a specific format. I want to have a page that if I fill in a text box labeled "Callers name:" then after I hit submit, shows on the other page "Callers name: Joe Schmo"..

 

Can someone please point me in the right direction on how i would pass the post data to another page using php or where I can find a template that'll accomplish this.. I've searched php.resourceindex.com and hotscripts.com but either I'm not searching right or there are none already pre-developed for me to upload, customize, and use. ???

Link to comment
Share on other sites

first you have to build your form... which is simple html, but for the action you want to put the script that will display the next page...

 

for instance say your first page is form.php, you'll have your form code, and it is submitting to display.php

 

form code

<form action='display.php' method='post'>
<input type='text' name='name'><br>
<input type='submit' value='submit'>
</form>

 

your display.php will get the data submitted and display it...

<?php
$name = $_POST['name'];
echo $name;
?>

Link to comment
Share on other sites

Thanks interpim,

 

yours worked nice.. Before you sent me that, I found another and was testing..  It would redirect to the php script but it was empty/blank.

 

 

 

This is what I used:

<html>
<form method="post" action="verified.php">
Caller Name:<input type="text" name="first_name0"/><br/>
<input type="submit" name="submit"/> </form> 
</html>

 

<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>New Page 1</title>
</head>

<body>
Caller Name:
<?php 
$first_name0 = $_POST['first_name0'];
?> 
</body>
</html>


I got this info from http://mrarrowhead.com/php_tutorials_mah/php_passing_variables.php and I think I'm getting it now. Mines failed because I passed the variable but told it to do nothing, if I added "echo $first_name0;" in the next line it would've worked. Did I get that right?

Link to comment
Share on other sites

Now i have another problem. Same form, same method noted above but when the form spits out the text, all " ' " characters are outputted with " \' " instead.

 

Could somebody help me out with this.. Here's an example:

 


  • Can't , Won't , Don't

.........................


  • Can\'t , Won\'t , Don\'t

 

 

I hope this is allowed but if you want to go to the test script, it's at:

http://4phpfreaks.freehostia.com/caller1.html

 

None of the fields are required so to replicate, just use submit anyone of the boxes. Makes me wonder what other characters would have to be cleaned up. Anyhow, any help would be appreciated.

 

Link to comment
Share on other sites

Changed my code accordingly, but it doesn't work...

 

 

<?php

$name = $_POST['needed'];

$var="Can\'t , Won\'t , Don\'t";

$var=stripslashes($var);

echo $needed;

?>

 

The output I get still shows:

Can\'t , Won\'t , Don\'t

 

 

Furthermore, I want it keep return characters submitted in the form as well.

 

Example:

Typing in the following in the form..

Customer Info line 1

Customer Info line 2

Customer Info line 3

Customer Info line 4

 

Produces:

Customer Info line 1 Customer Info line 2 Customer Info line 3 Customer Info line 4

 

 

As with these, I'm looking for something to work globally in php or some other method where my script takes the output, then formats it exactly as it was inputted. It shouldn't include ' \ ' when apostrophes are being used and return values should stick. If I could tell php to use the html br tag when returns are found that would be awsome, but it's obvious it isn't being passed from the form.

 

I found this somewhere on the net and tried to use it in the head of both of either of the pages but it didn't work. I know it's java but it looks like it's using what would be supported in php "\n". Correct me if I'm wrong, because I thought I seen it posted somewhere else on the net. Here's the code..

 

 
<script type="text/javascript"> // handy proto method String.prototype.trim = function() 
{ return this.replace(/(^\s+)¦\s+$/g,"")} function reply(number) {   number =  
number.trim() // remove lead + trail spaces   if(!number) return   // if empty string,  
stop   var area = document.comment.commenttext   var addition = "[reply" + number + "]
\n";   area.value += addition;   area.focus(); } 
</script> 

 

Does anybody have a solution for this or know of a post I can review where this was discussed. I did try searching this forum but couldn't find the answer. Probably using the wrong search terms so any help or a point in the right direction would be appreciated. Thanks.

Link to comment
Share on other sites

Changed my code accordingly, but it doesn't work...

 

<?php

$name = $_POST['needed'];

$var="Can\'t , Won\'t , Don\'t";

$var=stripslashes($var);

echo $needed;

?>

 

 

The correct code would be

<?php
$name = $_POST['needed'];
$var="Can\'t , Won\'t , Don\'t";
$var=stripslashes($var);
echo $var;
?>

 

In order to auto format, you can just load the variable and strip at the same time. Just do

$name = stripslashes($_POST['needed']);
echo $name;

 

For your display on multiple lines, a quick way to do it(as long as normal formatting isn't that important). You can load it into the same type of field you posted it as. For instance if you are using a textarea, your first page would look like this:

<form action=page2.php method=post>
<textarea cols=30 rows=30 name=tbox></textarea>
<input type="submit" value="Submit">
</form>

 

And in the second page you would put it into another textarea with readonly set, so it can't be changed:

<?php
$text = stripslashes($_POST['tbox']);
echo "<textarea cols=30 rows=30 readonly=yes>" . $text . "</textarea>";
?>

 

Hope that helps, I think everyone else got frustrated ;)

echo "

Link to comment
Share on other sites

  • 1 month later...
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.