Jump to content

Recommended Posts

I have a simple captcha just to lessen the spam made up of three rand() numbers.  num1 and num2 are added together then num3 is subtracted from the add to give the total.  Now this is my question.  If someone gets the sum wrong and the form is re-displayed with the sticky fields, I can remove the contents and change the values of the inputs and re-sumbit with the correct sum captcha submitted, but if someone takes the check out of the checkbox or puts one in then it throws up the error Notice: Undefined index:

 

<input type="checkbox" name="call" value="Yes" <?php if($_POST['call'] == 'Yes') echo "checked" ?> /> Do you wish  to receive a call from us?

 

Chances are 99% of the users wont change any or the inputs.  But I'd like to cover myself for that 1% that may.  Of those they will fall into two categories those that selected the wrong option on first submit and notice it during the catchpa re-display of the form,  and those that have changed their minds on a certain option.  Either way I want to make sure that I don't get the Undefined index error if they try to re-submit the form with the check taken out or one put in.

 

So any help would be brilliant.  I've tried so many things over the last couple of hours and can't find a solution.  I like to try and figure it out myself as it helps me learn, but after a few hours now I'm still no further forward.  So any help would be very gratefully received.  If only two stop me from pulling my hair out, I don't think I'd look good bald lol..

 

Many thanks in advance for any help

Oraya

 

Link to comment
https://forums.phpfreaks.com/topic/265228-how-can-i-re-write-this-checkbox-sticky/
Share on other sites

<input type="checkbox" name="call" value="Yes" <?php echo (isset($_POST['call'])) ? 'checked="checked"' : NULL; ?> /> Do you wish  to receive a call from us? 

 

checkboxes will only be set IF it is checked, so you can use isset.  If it is set, then it should be checked.

Ok ignore that...  lol I've just re-read you comment.  No it wont because it's not set so it wont throw and error.  Forgive me, long hours = tiredness and also new to php.  :)

 

Thank you so much for you help that's brilliant.  One more question if you wouldn't mind what does the question mark do?

 

Oraya

Wonderful, have booked marked the link for later reading.  You have now turned the long day into a happy ending, so thank you for that.  I do like to try and figure things out for myself, as I have found that if it takes me a while to find a solution it tends to stick more in my memory and so aids my learning.  But no amount of googling sticky forms gave me the answer. 

 

You are gent, so thank you kindly.  I can now close my laptop having accomplished my goals for today, create a contact form with several combo's doing different things through if statements etc, write a simple captcha to lessen future spam, (yuck almost as bad as the tinned variety lol) and the last goal was to find a solution to the question asked.

 

I can now get some shut eye now.  :)  Thank you once again!  Have a great Thursday Jc.

Oraya

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.