passing variables - php to html fom

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
plushgirl
Forum Newbie
Posts: 2
Joined: Wed Apr 09, 2008 9:36 am

passing variables - php to html fom

Post by plushgirl »

~pickle | Please use [ code=html ], [ code=php ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: :arrow: Posting Code in the Forums to learn how to do it too.


I am trying to pass a variable from a php script to an html form so when the user clicks submit, the variable is sent with the form to my email. I can get the variable to display on the page, but I can't put it in the form. What am I doing wrong???
Here's the php script:

Code: Select all

 
<?php
 
$template = "domain_reg.html";           
$registerlink = "signup.php";       
$restrict = 0;                      
$REFERERS = array('plushwebdesign.ca', 'www.plushwebdesign.ca');
                                    
error_reporting(0);
 
if ($_SERVER['REQUEST_METHOD'] == 'GET'){
    $domain = $_GET['domain'];
    $ext = $_GET['ext'];
    $option = $_GET['option'];
}else{
    $domain = $_POST['domain'];
    $ext = $_POST['ext'];
    $option = $_POST['option'];
}
 
print_results();
echo "The following domain will be registered for you:  ";
echo $domain;
 
function print_results()
{
    global $template,$domain,$ext,$server;
    if(!is_file($template)){
        print"The template file into which to print the results either does not exist or is
        not writeable<br>
        please correct this if you are the webmaster of this site<br>
        The script can not continue exiting......";
        exit;
    }
    
    $template = file ($template);
    $numtlines = count ($template);
    $line = 0;
    
    while (! stristr ($template[$line], "<!--DOMAIN RESULTS-->") && $line < $numtlines) {
    echo $template[$line];
    $line++;
    }
}
And here's the html:

Code: Select all

<html>
<body>
    <form id="form" action="form2.php" enctype="multipart/form-data" name="form">
    <input type="hidden" name="mydomain" value="" />
    <a href="domain_reg_done.html" onclick="document.getElementById('form').submit()">
        <img src="images/send.gif" alt="" /></a>
    <!--DOMAIN RESULTS-->
     </form>                                                   
</body>
</html>
I've tried <%php echo $GET_['domain']; %> and it doesn't work.


~pickle | Please use [ code=html ], [ code=php ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: :arrow: Posting Code in the Forums to learn how to do it too.
User avatar
aceconcepts
DevNet Resident
Posts: 1424
Joined: Mon Feb 06, 2006 11:26 am
Location: London

Re: passing variables - php to html fom

Post by aceconcepts »

Try declaring your form's method type i.e. POST or GET

Code: Select all

 
method="POST"
 
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: passing variables - php to html fom

Post by pickle »

So you can get the variable to display on the page with the submit button, but not on the page with the form?

Also, why not just use str_replace() in your print_results() function, rather than your while loop - much simpler (unless I'm not understanding some functionality)
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
plushgirl
Forum Newbie
Posts: 2
Joined: Wed Apr 09, 2008 9:36 am

Re: passing variables - php to html fom

Post by plushgirl »

You guys are awesome. Thanks so much for the help :)
Post Reply