php - Ignoring initial loading of PHP_SELF -


i learning php , have page reloads itself. want know if can ignore function on initial loading of page , call once form submit button has been clicked.

the page passed 'ticketid' , loads information it. want able add note using following form method:

<form method="post" action="<?php echo htmlspecialchars($_server["php_self"]);?>"> <strong>add note:</strong>  <textarea name="note" rows="5" cols="40" value=><?php echo htmlspecialchars($note);?></textarea> <span class="error">*<?php echo $noteerr;?></span><br> 

the user clicks on submit button submit note processing:

<button type='submit' name='ticketid' value= <?php echo $_post['ticketid'];?> >view</button> </form> 

the 'ticketid' passed page reload information.

if submit button pressed , no note has been entered want message box display informing user include note. have tried:

if (!empty($_post["note"]))      {     echo "this has updated...";     } else {     echo "missing!";     } 

however loads error message on initial load of page. have tried setting variable post ticketid value , clearing post value after page has displayed , before testing error message:

$tempticketid = $_post['ticketid']; $_post['ticketid'] = null; 

then testing error message, , setting pos value before page ends allow reload correctly again:

$_post['ticketid'] = $tempticketid;  

however post value doesn't save , page reloads no information.

any great appreciated.

here's full code layout:

##load page info...  #set temp variable , clear post value $tempticketid = $_post['ticketid']; $_post['ticketid'] = null;  #load form <form method="post" action="<?php echo htmlspecialchars($_server["php_self"]);?>">     <strong>add note:</strong>      <textarea name="note" rows="5" cols="40" value=><?php echo htmlspecialchars($note);?></textarea>     <span class="error">*<?php echo $noteerr;?></span><br>      <button type='submit' name='ticketid' value= <?php echo $_post['ticketid'];?> >view</button>     </form>  #test if note empty , form button has been pressed     if (!empty($_post["note"]))          {         echo "this has updated...";         } elseif (empty($_post["ticketid"] {         echo "missing!";         }  #set post value reload page $_post['ticketid'] = $tempticketid;  

we need restructure form bit make happen. can check if form submitted testing button must clicked submit. however, you're using button multiple purposes. simplify, we'll have separate submit button, , pass ticketid value through form hidden input. shouldn't need code unsets $_post values.

<button type='submit' name='submit'> view</button> <input type='hidden' name='ticketid' value= <?php echo $_post['ticketid'];?> /> 

then can test if form has been submitted quick check:

if (isset($_post['submit'])) {     if (!empty($_post["note"]))      {         echo "this has updated...";     } else {         echo "missing!";     } } 

Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -