We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 32337
    • 28 Posts
    If I have a form that submits to a page with a form on it and I want to pass the value of a hidden field from the first to the second, is it possible to store the value in $_SESSION and print it in the chunk that loads?

    How?
    When the user submits the form below they go to a page called sendcard with a form on it. In several places in the HTML I need the value of the hidden input "card." I thought that I could call a snippet with
    <?php
    $_SESSION['card'] = $fields['card'];
    ?>
    when the form submits, then create a variable like $card = $_SESSION[’card’] and return $card then, in the html on the sendcard page have something like <img src="/assets/images/card[+$card+].jpg" /> but that totally doesn’t work.
    I’ve read the multipart form example but don’t know how to apply it to this case. Please help.
    <form id="ecard" action="/sendcard" method="post">
    				<fieldset>
    					<input name="card" type="hidden" value="1" />
    					<input name="subject" type="hidden" value="IF SANTA HAD A THEME PARK, THIS WOULD BE IT!" />
    					<input id="ecard1" type="image" src="/assets/media/images/ecards/card1.jpg" title="Customize and Send This Ecard" />
    					<label for="ecard1">If Santa Had a Theme Park,  This Would Be It!</label>
    				</fieldset>
    			</form>
      • 32337
      • 28 Posts
      OK, I’ve worked out that I can do what I wanted but the action has to be to the current resource, however I can use &gotoid to go to the next form. Now I need to figure out how to make a custom placeholder.
        • 28042 ☆ A M B ☆
        • 24,524 Posts
        Why? The action can be to anywhere you want, and the $_POST array will have the value of all the fields of the original form, including the hidden one. Just have your snippet to process the form on the second page, checking to make sure that the submit is from the original form’s page.
          Studying MODX in the desert - http://sottwell.com
          Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
          Join the Slack Community - http://modx.org
          • 32337
          • 28 Posts
          I think, basically, the problem is I have 0 previous experience with anything server side or with PHP, so I’m struggling to figure things out on a less than complete understanding. For instance, while what you wrote makes some sort of sense, I have no idea how to do any of it. But I found enough examples of things using $_SESSION that I was able to put together something which worked, even if it is odd. Without examples of the correct way to do things, I’m just groping around in the dark.

          My next step, btw, is to figure out how to allow the user to enter the recipient.