Jump to content
xisto Community
Thorned Rose

How Do I Pass Php Variables From A Url To A Form? Im about read to tear my hair out with this one

Recommended Posts

Ok, what I need is for users to be able to select what address they want (e.g. mydomain + .com), click submit that then sends the variables 'domain' and 'ext' through the URL e.g. mywebsite.com/example.php?domain=mydomain&ext=com (the variables being mydomain and com) where they are displayed in a form mail as "Domain Selected: mydomain.com" that can then be submitted and sent to an email.

In my form so far I have

<input name="domainname" type="text" id="domainname" value ="<?php echo "$domain"; ?>">
but it don't do poo and I'm sure that anyone in the know is laughing at my sad attempt at PHP but if you could please tell me how I call both variables from the URL so that they display in the form as one whole address (i.e. mydomain.com not my domain and com) that would be very much appreciated!

Share this post


Link to post
Share on other sites

*edit*
What you have there uses the $domain variable. In order to grab the values from the URL, use the $_GET array.

<input name="domainname" type="text" id="domainname" value ="<?php echo $_GET['domain']; ?>"><input name="extensionname" type="text" id="extensionname" value ="<?php echo $_GET['ext']; ?>">

Withput seeing the entire code you are using, this is my best guess. If this doesn't work for you, please re-post with the entire code. Well, at least the Form in question and the receiving script. Thanks.

Share this post


Link to post
Share on other sites

I can't give you the form for the part that generates the URL as that is a component for Joomla!, just that it outputs the variables in a url that looks like mywebsite.com/example.php?domain=mydomain&ext=com
Here's a simple form (sorry it's messy) with how I want to output the variables domain and ext

<form action="process.php" method="post"><input type=hidden name="subject" value="Domain Request">  <div align="center">Name: 	<input type="text" name="name" size="30" maxlength="30" />	  <br />	  <br />	Email:   <input type="text" name="email" size="30" maxlength="30" />  <br />  <br />	Domain:   <input name="domainname" type="text" id="domainname" value ="<?php echo "$domain" "$ext"; ?>">  <br />  <br />  <input type="submit" name="submit" value="Send" />  </div></form>
This form should display the variables in a text box as "mydomain.com". People can then finish putting in their name and email and hit send which should then send all the form info to an email address.

My process.php so far looks like this:

<?php@extract($_POST);$name = stripslashes($name);$email = stripslashes($email);$subject = stripslashes($subject);$domainname = stripslashes($domainname);mail('email@address.com',$subject,$domainname,"From: $name <$email>");header("location:form.php");?>

It's displaying the variables from the url within the form that have me stumped so far.

Share this post


Link to post
Share on other sites

This is going to get a bit confusing because Joomla is using the $_GET Superarray and you are using the $_POST Superarray, so adjust the $_GET's and $_POST's accordingly. Your form shows the method=POST, so you will need to use the $_POST array to display your data, but Joomla is using the $_GET array(method) and that will require using the $_GET values for where you receive their data.

When the variables are physically included in the URL, use the $_GET array.

*edit*

<?php echo $domain . '.' . $ext; ?>
to add the 'dot' in the output.

Share this post


Link to post
Share on other sites

Wohoo! I got it. I combined the two things you said jlhaslip to get:

<input name="domainname" type="text" id="domainname" value ="<?php echo $_GET['domain']. '.' . $_GET['ext']; ?>">
And it works perfectly.

Thanks for all your help dude! You are a legend as always! ;)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | 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.