Pandolfo Posted September 22, 2007 Share Posted September 22, 2007 Hey everyone, I am working on something that has turned into a monster. I have some html containing a select form which i have assigned to a variable. I understand how to echo the variable..no problem there. The problem is that i need to validate the form, grab the selected value, and assign it to a new variable. The code (in part anyway) is listed below. $timesplitter= "<table align=center width=100% border=1 cellpadding=0 cellspacing=0><tr><td align=left width=100% class=even><font color=red>Percentage of time to spend for work and work related activities : </font> <select name=timesplit size=1><option value=0>Do not change/Keep Last years value<option value=10>10%<option value=20>20%<option value=30>30%<option value=40>40%<option value=50>50%<option value=60>60%<option value=70>70%<option value=80>80%</select></td> </tr> </table></td> </tr> </table>"; echo $timesplitter; There's the form. Normally i would use POST to grab the value and set it equal to a new variable. I don't know how to do that in this case. Any help or insight you might be able to offer would really be appreciated. Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/70245-i-dont-know-if-this-is-even-possible/ Share on other sites More sharing options...
MmmVomit Posted September 22, 2007 Share Posted September 22, 2007 Okay, first LINE BREAKS ARE YOUR FRIEND! $timesplitter= "<table align=center width=100% border=1 cellpadding=0 cellspacing=0> <tr> <td align=left width=100% class=even> <font color=red> Percentage of time to spend for work and work related activities : </font> <select name=timesplit size=1> <option value=0>Do not change/Keep Last years value<option value=10>10% <option value=20>20% <option value=30>30% <option value=40>40% <option value=50>50% <option value=60>60% <option value=70>70% <option value=80>80% </select> </td> </tr> </table> </td> </tr> </table>"; echo $timesplitter; Okay, second. To output all that html, you should simply drop out of PHP. <?php // lots of code here ?> <table> <tr> <td> </td> </tr> </table> <?php // more code here ?> There is no need to assign all that to a variable. Third. A select tag has to be contained within form tags. You also need to close your option tags. Quote Link to comment https://forums.phpfreaks.com/topic/70245-i-dont-know-if-this-is-even-possible/#findComment-352807 Share on other sites More sharing options...
MmmVomit Posted September 22, 2007 Share Posted September 22, 2007 Okay, now that all that's out of the way, I don't quite get what you're asking. How is this any different than the forms you've used before? Quote Link to comment https://forums.phpfreaks.com/topic/70245-i-dont-know-if-this-is-even-possible/#findComment-352810 Share on other sites More sharing options...
Pandolfo Posted September 22, 2007 Author Share Posted September 22, 2007 hmm...okay. You mean something like this? $divorcestatement="Your spouse leaves you a note stating that you've neglected the marriage and children too much and divorce is the only option. Divorce results in a fifty percent (50%) reduction of all assets. When the dust settles your net assests total '$newassets'. This change will be reflected in next year's financial statement. Soon after the divorce is settled you meet someone new. Your are currently married/dating again.<br><br>"; echo $divorcestatement; ?> <table align=center width=100% border=1 cellpadding=0 cellspacing=0> <tr> <td align=left width=100% class=even> <font color=red> Percentage of time to spend for work and work related activities : </font> <form name="timesplitter"> <select name=timesplit size=1> <option value=0>Do not change/Keep Last years value<option value=10>10% <option value=.20>20%</option> <option value=.30>30%</option> <option value=.40>40%</option> <option value=.50>50%</option> <option value=.60>60%</option> <option value=.70>70%</option> <option value=.80>80%</option> </select> </form> </td> </tr> </table> </td> </tr> </table> <? $worktime = $_POST['timesplitter']; Quote Link to comment https://forums.phpfreaks.com/topic/70245-i-dont-know-if-this-is-even-possible/#findComment-352813 Share on other sites More sharing options...
BlueSkyIS Posted September 22, 2007 Share Posted September 22, 2007 Put this part at the top, not the bottom: <? $worktime = $_POST['timesplitter']; Quote Link to comment https://forums.phpfreaks.com/topic/70245-i-dont-know-if-this-is-even-possible/#findComment-352852 Share on other sites More sharing options...
MmmVomit Posted September 22, 2007 Share Posted September 22, 2007 That whole $divorcestatement variable can be done away with as well. Your spouse leaves you a note stating that you've neglected the marriage and children too much and divorce is the only option. Divorce results in a fifty percent (50%) reduction of all assets. When the dust settles your net assests total <?=$newassets?>. This change will be reflected in next year's financial statement. Soon after the divorce is settled you meet someone new. Your are currently married/dating again.<br><br> <table align=center width=100% border=1 cellpadding=0 cellspacing=0> <tr> <td align=left width=100% class=even> <font color=red> Percentage of time to spend for work and work related activities : </font> <form name="timesplitter"> <select name=timesplit size=1> <option value=0>Do not change/Keep Last years value<option value=10>10% <option value=.20>20%</option> <option value=.30>30%</option> <option value=.40>40%</option> <option value=.50>50%</option> <option value=.60>60%</option> <option value=.70>70%</option> <option value=.80>80%</option> </select> </form> </td> </tr> </table> </td> </tr> </table> <? $worktime = $_POST['timesplitter']; Using the POST array at the end of the file isn't going to do what you think it will. If you want to use the data that the user enters into the timesplitter form, you're going to have to do something like this. <form method="post" action="another_page.php"> <select> <!-- lots of options go here --> </select> <input type="submit" name="submit" value="Submit Data"> </form> By clicking the submit button, the data in the form gets sent to "another_page.php" and is processed by that script. There isn't a way to get at the data in the form on the current page using PHP. For something like that you want JavaScript. Remember, all PHP does is spit out a document, in this case an html file. Once it's done generating that document, it won't do anything until you tell it to generate another document (e.g. click on a link that takes you to another PHP script). Quote Link to comment https://forums.phpfreaks.com/topic/70245-i-dont-know-if-this-is-even-possible/#findComment-353016 Share on other sites More sharing options...
Barand Posted September 22, 2007 Share Posted September 22, 2007 There isn't a way to get at the data in the form on the current page using PHP. If you don't specify a form action, the default is to submit to the same page, same as if you specify $_SERVER['PHP_SELF'] as the action. <?php if (isset($_GET['do'])) { echo "<p>{$_GET['selection']}</p><hr />"; } ?> <form> <select name="selection"> <option value="option 1">option 1</option> <option value="option 2">option 2</option> <option value="option 3">option 3</option> </select> <br /> <input type="submit" name="do" value="Submit"> </form> Quote Link to comment https://forums.phpfreaks.com/topic/70245-i-dont-know-if-this-is-even-possible/#findComment-353046 Share on other sites More sharing options...
Pandolfo Posted September 24, 2007 Author Share Posted September 24, 2007 So, if i used Barrand's suggestion, how would i assign the result of the select form to a variable? If that is possible, then i think most of the issues i'm having will be solved. Any ideas? Thanks in advance! Quote Link to comment https://forums.phpfreaks.com/topic/70245-i-dont-know-if-this-is-even-possible/#findComment-354172 Share on other sites More sharing options...
roopurt18 Posted September 24, 2007 Share Posted September 24, 2007 It's already assigned to a variable; when the form is submitted it will be in the variable $_POST["selection"]. What is the next step you're trying to accomplish? Quote Link to comment https://forums.phpfreaks.com/topic/70245-i-dont-know-if-this-is-even-possible/#findComment-354202 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.