www.webdeveloper.com
Results 1 to 5 of 5

Thread: passing parameters to form action field

  1. #1
    Join Date
    Nov 2006
    Posts
    27

    passing parameters to form action field

    Hi I'm struggling with my contact form and php - I'm new to all this and trying to understand the sequence of events. The first time the contact form is loaded is from this link:
    HTML Code:
                 <li class="accordionButton"><a class="rfpMenuBtn" href="contactform.php?id=1">Contact us</a></li>
    Then it's loaded again when I click Submit!
    HTML Code:
    <form style="margin-left: 10em;" id='contactus' action='<?php echo $formproc->GetSelfScript(); ?>' method='post' accept-charset='UTF-8'>
    - I guess it's a case of before and after the form is filled, but it seems strange the page loading itself again!

    My question is how do I pass the parameter that was passed in the original link ( href="contactform.php?id=1") to the contact form when it's loaded the second time after clicking Submit ?

    Here's the full contact form page:
    PHP Code:
    <?PHP
    /*
        Contact Form from HTML Form Guide
        This program is free software published under the
        terms of the GNU Lesser General Public License.
        See this page for more info:
        http://www.html-form-guide.com/contact-form/php-contact-form-tutorial.html
    */
    require_once("./include/fgcontactform.php");

    $formproc = new FGContactForm();

    $var1=$_GET['id'];
    switch(
    $var1)
    {
    case 
    3:
    echo 
    'send to david';
    $formproc->AddRecipient('davidm.me@gmail.com'); //<<--- Web Masters address 
    break;

    default:
    echo 
    'send to rahel';
    $formproc->AddRecipient('reikiforpeace@gmail.com'); //<<--- Rahel 
    break;
    }

    //2. For better security. Get a random tring from this link: http://tinyurl.com/randstr
    // and put it here
    $formproc->SetFormRandomKey('CnRrspl1FyEylUj');


    if(isset(
    $_POST['submitted']))
    {
       if(
    $formproc->ProcessForm())
       {
            
    $formproc->RedirectToURL("thank-you.php");
       }
    }

    ?>
    <?php
     
    include ("include/head-section.php");
    ?> 
    <style type="text/css">
    <!--
    body {
          margin: 0;
                padding: 0;
            }    
    fieldset {      
    float: left;      
    /* clear: both; */      
    width: auto;
    margin: 0 0 1.5em 0;      
    margin-left: 10em;      
    padding: 0;      
    border: 1px solid #BFBAB0;      
    background-color: #F2EFE9;      
    }  
    -->
    </style>

    </head>
    <body>
    <div id="screenWrapper">
    <!-- see http://cooltext.com/ to generate a logo like this
    <img src="images/reikiforpeace.png" alt="reiki for peace logo" style="position: absolute; top: 75px; right: 130px;"></img>
     -->

    <?php include('include/header.php'); ?> 

    <?php include('include/menu.php'); ?> 
    <!-- Form Code Start -->
    <div style="margin-top: 2.3em;">
    <?php
    echo 
    "$formproc->GetSelfScript()'?='$_GET['id']. \n";
    ?>
    <form style="margin-left: 10em;" id='contactus' action='<?php echo $formproc->GetSelfScript(); ?>' method='post' accept-charset='UTF-8'>
    <fieldset id="fset">

    <?php
    //$var1=$_GET['id'];
    //switch($_GET['id'])
    switch($var1)
    {
    case 
    1:
    echo 
    "<legend style='margin-top: 1em; font-size: 1.4em; font-weight: normal; color: #a6a6a6; text-align: left;'>Contact us</legend>";
    break;

    case 
    2:
    echo 
    "<legend style='margin-top: 0.5em; font-size: 1.4em; font-weight: normal; color: #a6a6a6; text-align: left;'>Contact Rahel Warshaw-Dadon </legend>";
    echo 
    "<span style='font-size: 12pt; color: grey; text-align: center;'> &nbsp; &nbsp; Reiki Master and Director of Reiki for Peace</span><br/>";
    break;

    case 
    3:
    echo 
    "<legend style='margin-top: 1em; font-size: 1.4em; font-weight: normal; color: #a6a6a6; text-align: left;'>Contact David Myers - Web Master</legend>";
    break;

    default:
    echo 
    "Try Again, the id was "$var1 "<br />";
    break;
    }
    ?>
    <input type='hidden' name='submitted' id='submitted' value='1'/>
    <input type='hidden' name='<?php echo $formproc->GetFormIDInputName(); ?>' value='<?php echo $formproc->GetFormIDInputValue(); ?>'/>
    <input type='text'  class='spmhidip' name='<?php echo $formproc->GetSpamTrapInputName(); ?>' />

    <div class='short_explanation'>* required fields</div>

    <div><span class='error'><?php echo $formproc->GetErrorMessage(); ?></span></div>
    <div class='container'>
        <label for='name'>* Your Name: </label>
        <label style="float: left; margin-left: 170px; clear: right;"  for='email'>* Your Email Address:</label>
        <span id='contactus_email_errorloc' class='error'></span>
    </div>
    <div class='container'>
        <input type='text' name='name' id='name' value='<?php echo $formproc->SafeDisplay('name'?>' maxlength="50" />
        <input style="margin-left: 20px;" type='text' name='email' id='email' value='<?php echo $formproc->SafeDisplay('email'?>' maxlength="50" /><br>
        <span id='contactus_name_errorloc' class='error'></span>
    </div>

    <div class='container'>
        <label for='message' >Message:</label><br/>
        <span id='contactus_message_errorloc' class='error'></span>
        <textarea rows="10" cols="50" name='message' id='message'><?php echo $formproc->SafeDisplay('message'?></textarea>
          <input style="margin-left: 50px;" type='submit' name='Submit' value='Submit' />
    </div>



    </fieldset>
    </div>
    </form>
    <!-- client-side Form Validations:
    Uses the excellent form validation script from JavaScript-coder.com-->

    <script type='text/javascript'>
    // <![CDATA[

        var frmvalidator  = new Validator("contactus");
        frmvalidator.EnableOnPageErrorDisplay();
        frmvalidator.EnableMsgsTogether();
        frmvalidator.addValidation("name","req","Please provide your name");

        frmvalidator.addValidation("email","req","Please provide your email address");

        frmvalidator.addValidation("email","email","Please provide a valid email address");

        frmvalidator.addValidation("message","maxlen=2048","The message is too long!(more than 2KB!)");

    // ]]>
    </script>
    <div id='fg_crdiv'><p>for customization, <a href='http://www.html-form-guide.com/contact-form/php-contact-form-tutorial.html'
    >see the contact form code page</a>.</p></div>
    <!--
    Form Code End
    Visit html-form-guide.com for more info.
    -->
    </div>
    <?php include('include/footer.php'); ?> 
    </body>
    </html>
    Thanks for any help

    David

  2. #2
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,536
    One way:
    PHP Code:
    <form style="margin-left: 10em;" id='contactus' action='<?php
    echo $formproc->GetSelfScript();
    if(!empty(
    $_GET['id'])) {
       echo 
    "?id=" . (int) $_GET['id']; // use (int) to make sure it's integer
    }
    ?>' method='post' accept-charset='UTF-8'>
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  3. #3
    Join Date
    Nov 2006
    Posts
    27
    Thanks for your reply Nogdog. I tried your suggestion, the problem is after I click Submit $_GET['id'] returns empty.
    I don't know how to pass the parameter ('id') from the first event when I open the contact form to the second event when I click Submit - as I said I don't exactly understand the sequence of events. Can you help?

    Thanks

    David

  4. #4
    Join Date
    Jun 2011
    Posts
    1
    hey david,

    what exactly does this parameter do?

    seems like if you want to pass it again, you would just need to redecalre it within the form. once you hit submit, everything in the form gets submitted, so just add a hidden field named id and pass that variable as it's value.

  5. #5
    Join Date
    Nov 2006
    Posts
    27
    Thanks CVaughan for your reply. The parameter is for the layout of the contact form and also who the contact form gets sent to. I'll give your suggestion a try.
    Hope the hidden field keeps its value when the form is reloaded.
    You'll be hearing from me if it doesn't - lol.

    David

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles