Niixie Posted January 8, 2012 Share Posted January 8, 2012 Hey all, i have a little problem. I have a form, and when submitting, i need to use the ID that i put in the $_GET array earlier. When you're entering my site, and clicks a certain link, the $_GET will store show=1, and when you're submitting the form on the page, the value of 'show' is needed on the redirect page.. I thought that it would be smart to transfer it with a hidden textfield, but somehow it fails? <form id="comment-form" action="comment_profile.php" method="POST"> <fieldset> <div class="field"> <textarea name="comment-field" rows="2" cols="66"></textarea> <input type="hidden" name="pofileid-field" value="<?php echo $_GET['show']; ?>" /> // <--- Here is the hidden field. <input type="submit" name="submit-field" class="submit" value=""/><i> (HTML tags kan bruges)</i> </div> </fieldset> </form> Above you can see a piece of my code, and i marked the hidden field aswell. What i do not understand is, why isn't the hidden fields value return the value of show when i check in comment_profile.php, as that is where it returns? Thanks in advance -Niixie Quote Link to comment https://forums.phpfreaks.com/topic/254619-form-and-hidden-textfields/ Share on other sites More sharing options...
litebearer Posted January 8, 2012 Share Posted January 8, 2012 when you view the source in your browser. is the correct value on the hidden field? Quote Link to comment https://forums.phpfreaks.com/topic/254619-form-and-hidden-textfields/#findComment-1305615 Share on other sites More sharing options...
Niixie Posted January 8, 2012 Author Share Posted January 8, 2012 Yes, the value from 'show' is '1', but no value is returned into the hidden field. Quote Link to comment https://forums.phpfreaks.com/topic/254619-form-and-hidden-textfields/#findComment-1305616 Share on other sites More sharing options...
litebearer Posted January 8, 2012 Share Posted January 8, 2012 please show the code where you are retrieving the hidden field Quote Link to comment https://forums.phpfreaks.com/topic/254619-form-and-hidden-textfields/#findComment-1305618 Share on other sites More sharing options...
RobertP Posted January 8, 2012 Share Posted January 8, 2012 Not sure how your code is formatted because i see ""// <--- Here is the hidden field."" and that is a php comment lol but your code looks like it is written in html <?php echo '<form id="comment-form" action="comment_profile.php" method="POST"> <fieldset> <div class="field"> <textarea name="comment-field" rows="2" cols="66"></textarea> <input type="hidden" name="pofileid-field" value="'.((array_key_exists('show',$_GET))?$_GET['show']:null).'" /> <input type="submit" name="submit-field" class="submit" value=""/><i> (HTML tags kan bruges)</i> </div> </fieldset> </form>'; ?> Quote Link to comment https://forums.phpfreaks.com/topic/254619-form-and-hidden-textfields/#findComment-1305619 Share on other sites More sharing options...
Niixie Posted January 8, 2012 Author Share Posted January 8, 2012 I added the "// <--" manually when i copied it to here. Can you explain what you are doing there? EDIT: I found a way myself, thank you very much for helping me anyways! Quote Link to comment https://forums.phpfreaks.com/topic/254619-form-and-hidden-textfields/#findComment-1305622 Share on other sites More sharing options...
RobertP Posted January 8, 2012 Share Posted January 8, 2012 ((array_key_exists('show',$_GET))?$_GET['show']:null) if show is set in $_GET, then it will return the value, it if is not set, then it will return null. will not display a notice error Quote Link to comment https://forums.phpfreaks.com/topic/254619-form-and-hidden-textfields/#findComment-1305623 Share on other sites More sharing options...
litebearer Posted January 8, 2012 Share Posted January 8, 2012 If show=1, when OP views source, the value is being set properly (per his comment that GET was 1); therefore, we NEED to see the code that is attempting to retrieve the hidden field. Quote Link to comment https://forums.phpfreaks.com/topic/254619-form-and-hidden-textfields/#findComment-1305624 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.