Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 11 of 11
  1. #1
    Regular Coder
    Join Date
    Nov 2011
    Location
    Preston, UK
    Posts
    131
    Thanks
    36
    Thanked 0 Times in 0 Posts

    Having problem with resend form

    I am writing a PHP script to add data to a MySql database.
    There is an input form to add the data and a Captcha before posting.
    If the Captcha is entered correctly, everything works fine and the data is added to the database.


    However, if the Captcha is entered incorrectly, the script re-directs to a resend page which loads up the data that was input on the original input page.
    This is the part that does not work correctly.

    Here is the part of the script that loads the resend page:
    PHP Code:
    // WRONG SECURITY CODE } else {      header("Location: tcc_addrally.php?sdate=$sdate&rallydate=$rallydate&venue=$venue&route=$route&attractions=$attractions&officers=$officers&selection=$type&action=resend");          exit;    } // WRONG SECURITY CODE


    else if($action=="resend"){      $template join('',file('tcc_addrally_resend.tpl'));      $template str_replace("[sdate]",$sdate,$template);     $template str_replace("[rallydate]",$rallydate,$template);     $template str_replace("[venue]",$venue,$template);     $template str_replace("[route]",$route,$template);     $template str_replace("[attractions]",$attractions,$template);     $template str_replace("[officers]",$officers,$template);     $template str_replace("[region]",$region,$template);      print $template;      exit;    } 
    Here is the code for the resend page:
    Code:
    <form action="tcc_addrally.php" method="GET">  <center>    <table align="center" width=600 cellspacing=5 cellpadding=0 border=0>  <tr valign=top><td align= center colspan=2><font size="2" > <b>Start Date of rally:</b>  <input name="sdate"  size="40" value=[sdate]></font><br /> <b><font color="#ff0000">N.B:</font> This MUST be input in format <b><font color="#ff0000">dd-mm-yyyy</font></b> only <br /><br /> </td></tr>  <tr valign=top><td align= center colspan=2><font size="2" > <b>Date of rally:</b>  <input type="text" name="rallydate"  size="40" value=[rallydate]></font><br /><br /> </td></tr>  <tr valign=top><td align= center colspan=2><font size="2" > <b>Venue of rally:</b>  <input type="text" name="venue"  size="40" value=[venue]></font><br /><br /> </td></tr>  <tr valign=top><td align= center colspan=2><font size="2" > <b>Route to rally:</b> <textarea name="route" cols="300" rows="10">[route]</textarea>  </td></tr>  <tr valign=top><td align= center colspan=2><font size="2" > <b>Attractions at rally:</b> <textarea name="attractions" cols="300" rows="10">[attractions]</textarea>  </td></tr>  <tr valign=top><td align= center colspan=2><font size="2" > <b>Officers of rally:</b>  <input type="text" name="officers"  size="40" value=[officers]></font><br /><br /> </td></tr>  <tr> 	<td align="center" valign="TOP"><font size="2">Region:</font><br /> 	<select name="selection">        		<option value="Please select">Please select... 			 			<option value="chil">Chiltern 			<option value="east">Eastern 		</select> 	<p> 	</td> </tr> <!--// CHECK SECURITY CODE-->  <tr><td colspan=2 align=center> 		<img src="../files/CaptchaSecurityImages.php?width=100&height=40&characters=5" /><br /> 		<font size="2" >Security Code: </font><input id="security_code" name="security_code" type="text" /><br /> <font size="4" color="#ff0000" ><b>Please re-enter the security code above the box, in the security code box. Make sure you enter the security code in the correct case as displayed.</b></font><p>		 </td></tr>	  <!--// CHECK SECURITY CODE-->    <tr align=center><td colspan=2> <input type="button" value="Post" onclick="check <input type=reset value="Clear"> <input type="hidden" name="action" value="add"></input> </td></tr> </table>  </center> </form>
    These are the inputs on the forms:


    Start date: (Orig) 12-07-2013---------------(Resend)12-07-2013
    Date of rally: (Orig)12th - 14th July 2013---------------(Resend)12th
    Venue: (Orig)Field Rise Kingsdown Lane---------------(Resend)Field
    Route: Textarea
    Attractions: Textarea
    Officers: (Orig) Robert & Sharon Lane---------------(Resend)Robert


    It appears to me that anything in a 'Textarea' displays in the resend form OK, but in an input box, it will only display up to the first 'space'.
    Also, in a Textbox, the resend form will only display up to '&' and nothing after it.

    Can anybody advise what is wrong with my coding ???

    Thanks,
    The MAN, The MYTH, The LEGEND:
    John C
    ________________________________
    Support your local Country Music Club

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,979
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    Quote Originally Posted by countrydj View Post
    It appears to me that anything in a 'Textarea' displays in the resend form OK, but in an input box, it will only display up to the first 'space'.
    Which is normal. That is an HTML issue, not a PHP one. Check the HTML source generated; so long as data is within the value= section of the input, than PHP has done its job. You need to correct the HTML which requires quotations around attributes with spaces.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • Users who have thanked Fou-Lu for this post:

    countrydj (04-19-2013)

  • #3
    Regular Coder
    Join Date
    Nov 2011
    Location
    Preston, UK
    Posts
    131
    Thanks
    36
    Thanked 0 Times in 0 Posts
    Many thanks, Fou-Lu..

    That worked fine.

    However, when a & is included in the data, the resend stops there.

    e.g.

    Input: Robert & Sharon --- Resend: Robert

    Input: Robert and Sharon --- Resend: Robert and Sharon.

    Have you any idea why this is, or should I repost on the HTML forum ???

    Thank you...
    The MAN, The MYTH, The LEGEND:
    John C
    ________________________________
    Support your local Country Music Club

  • #4
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,979
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    I would presume that still has to do with the spaces. Best I know & is valid within a form value. Otherwise, wrap it in htmlentities to convert it to &amp;.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #5
    Regular Coder
    Join Date
    Nov 2011
    Location
    Preston, UK
    Posts
    131
    Thanks
    36
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Fou-Lu View Post
    I would presume that still has to do with the spaces. Best I know & is valid within a form value. Otherwise, wrap it in htmlentities to convert it to &amp;.
    Thanks for your reply.

    I have done some testing and the problem is to do with '&' not spaces.

    I have googled "wrap it in htmlentities to convert it to &amp;. ", but I cannot see how to solve my problem.
    It would be very easy if I was doing the coding, but the form is for 'Users' to be able to input their own data.

    What I can't understand is that there is no problem with '&' if the Captcha is input correctly. The data, as input, is inserted into the database. But there is when it is input incorrectly.
    The forms are the same, but with the data already displayed for the user.
    If the User just input the Captcha correctly, the data would be wrong.

    Have you any ideas about this ???

    Thanks,
    The MAN, The MYTH, The LEGEND:
    John C
    ________________________________
    Support your local Country Music Club

  • #6
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,979
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    What's the output HTML?
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #7
    Regular Coder
    Join Date
    Nov 2011
    Location
    Preston, UK
    Posts
    131
    Thanks
    36
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Fou-Lu View Post
    What's the output HTML?
    I'm not quite sure what you mean, but maybe it's this:

    Input: Robert & Sharon Lane

    When posted to :
    PHP Code:
    header("Location: tcc_addrally.php?sdate=$sdate&rallydate=$rallydate&venue=$venue&route=$route&attractions=$attractions&officers=$officers&selection=$type&action=resend"); 
    It goes to:
    PHP Code:
    else if($action=="resend"){
    echo 
    "Officers =".$officers; exit; 
    Returns: Officers =Robert

    I need it to return: Robert & Sharon Lane

    I have no idea how to do it.
    The MAN, The MYTH, The LEGEND:
    John C
    ________________________________
    Support your local Country Music Club

  • #8
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,979
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    You're re-requesting the page via header location. & is defined as the querystring separator, so it considers the next half to be that of a new variable. Use urlencode() on the values prior to sending them. Alternatively, use http_build_query and give it an array and it will automatically issue the urlencode.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #9
    Regular Coder
    Join Date
    Nov 2011
    Location
    Preston, UK
    Posts
    131
    Thanks
    36
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Fou-Lu View Post
    You're re-requesting the page via header location. & is defined as the querystring separator, so it considers the next half to be that of a new variable. Use urlencode() on the values prior to sending them. Alternatively, use http_build_query and give it an array and it will automatically issue the urlencode.
    Hi Fou-Lu...
    Thank you very much for your advice.

    However, I have no idea how to do either of your suggestions.

    I have googled both of your suggestions and I can't understand how to do it.

    Can you advise me how it's done ???

    Regards,
    The MAN, The MYTH, The LEGEND:
    John C
    ________________________________
    Support your local Country Music Club

  • #10
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,979
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    You specify each of the variables before the location header wrapped in urlencode:
    PHP Code:
    $officers urlencode($officers); 
    Or, as I'd suggest a better approach, use http_build_query with all of the variables:
    PHP Code:
    $aQs = array(
        
    'sdate' => $sdate,
        
    'rallydate' => $rallydate,
        
    # . . .
        
    'officers' => $officers,
        
    #. . .
    );
    $sQS http_build_query($aQs);
    // That will give you sdate={sdatevalue}&rallydate={rallydatevalue}. . .officers={officersvalue}
    // where every value has been urlencoded 
    Then give $sQS as the querystring for the location script.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #11
    Regular Coder
    Join Date
    Nov 2011
    Location
    Preston, UK
    Posts
    131
    Thanks
    36
    Thanked 0 Times in 0 Posts
    Hi Fou-Lu ...

    Thank you very much for your invaluable HELP...

    I have tried both of the above suggestions, and they both work fine for me.

    The first one is so simple when you know how.

    I felt the the second one was a little more difficult, but that may well have been because I had to think about the final coding.
    However, it is something new to me, so it will be very useful in building an array, in other projects.

    I would be very interested to know WHY you prefer the second suggestion.

    VERY MANY THANKS...
    The MAN, The MYTH, The LEGEND:
    John C
    ________________________________
    Support your local Country Music Club


  •  

    Posting Permissions

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