chop Posted July 14, 2011 Share Posted July 14, 2011 I want to add a conditional statement to the form action such that a value will be sent if true and not be sent if not true. It looks like this so far (this doesn't send the value): <?php if (isset($_POST['acct_type']) && $_POST['acct_type']=="business") { echo '<form action=register.php?business=true method="post" id="register">'; }else { echo '<form action=register.php method="post" id="register">'; } ?> I'm not even sure if this is the best way to accomplish this! if the "acct_type" = "business" AND the form doesn't validate, the form will be shown again with the form input elements that need to be filled in. This is the js that will do that: if (isset($_GET['business'])) { // will be false if ?business=true is not sent with the register.php URL ?> <script language="javascript">javascript:document.getElementById('pb').style.display='block'; </script> //will show the form elements <?php HERE ARE THE RADIO BUTTONS THAT SET THE "acct_type": <!-- PERSONAL OR BUSINESS ACCOUNT 'acct_type'personal,business --> <p><b>TYPE OF ACCOUNT:</b> <input type="radio" name="acct_type" checked= "checked" value="personal" onclick="javascript:document.getElementById('pb').style.display='none';" /><b>personal.</b> <input type="radio" name="acct_type" value="business" onclick="javascript:document.getElementById('pb').style.display='block';" /><b>business (enter business address).</b></p> thanks in advance Chop Link to comment Share on other sites More sharing options...
HartleySan Posted July 14, 2011 Share Posted July 14, 2011 I apologize for not reading your post fully (as it's late here), but in general, I think that it might be best to pass any info you want to pass as hidden values. Link to comment Share on other sites More sharing options...
chop Posted July 14, 2011 Author Share Posted July 14, 2011 well, you got me thinking in a different way. this is what I came up with that seems to work and is much simpler. No need even for a hidden field. thanks, Chop -----all other form fields here--- <?php if (isset($_POST['acct_type']) && $_POST['acct_type']=="business") { ?> <script language="javascript">javascript:document.getElementById('pb').style.display='block'; </script>// displays business related form elements <?php }?> </fieldset> </form> Link to comment Share on other sites More sharing options...
HartleySan Posted July 15, 2011 Share Posted July 15, 2011 Yeah, that'll work. Ideally, if you have the time and interest, you should consider a full-on Ajax solution. That basically equates to getting the necessary information from a database via PHP without reloading the page, and then handling all the actual logic on the JS side, so that you don't have to mix JS, PHP, HTML, etc. If your solution works as well though, then there's no need to worry, I suppose. Link to comment Share on other sites More sharing options...
Recommended Posts