Jump to content

How to increment hidden text field?


bluesteel

Recommended Posts

Hi everyone,

 

I'm new here and desperately need some guidance. Bit of a PHP noob too.

 

Basically what I'm doing is making a site where a form is required to send information to an email address.

That part I have working fine but what i need to do is have a reference number included in the email so that

every time someone submits the form, the reference number included in the email goes up by one.

 

What I've done is included a hidden text field in the form and set it to 1, but I'm not sure how to increment this in

the PHP script.

 

Heres my PHP script so far:

 

<?php

//--------------------------Set these paramaters--------------------------

 

// Subject

$subject = 'Quotation Form';

 

// email address for data to be sent to

$emailadd = '[email protected]';

 

// Where to redirect.

$url = 'http://www.derekfordwebdesigns.com/examples/wss/confirm.html';

 

// Make all fields required.

$req = '1';

 

$text = "Form results:\n\n";

$space = ' ';

$line = '

';

foreach ($_POST as $key => $value)

{

if ($req == '1')

{

if ($value == '')

{echo "$key is empty";die;}

}

$j = strlen($key);

if ($j >= 20)

{echo "Name of form element $key cannot be longer than 20 characters";die;}

$j = 20 - $j;

for ($i = 1; $i <= $j; $i++)

{$space .= ' ';}

$value = str_replace('\n', "$line", $value);

$conc = "{$key}:$space{$value}$line";

$text .= $conc;

$space = ' ';

}

mail($emailadd, $subject, $text, 'From: '.$emailadd.'');

echo '<META HTTP-EQUIV=Refresh CONTENT="0; URL='.$url.'">';

?>

 

<?php

 

$ref=$_POST('$ref')+1;

 

?>

 

 

The hidden text field for the reference number in the form looks like this:

 

<input name="ref" type="hidden" id="ref" value="1"/>

 

Please help? Everything works put the increment. When I submit the form, I get the proper result but with the same reference number every time. Sorry for asking what is probably a silly and basic question.

 

Thanks in advance :)

Link to comment
https://forums.phpfreaks.com/topic/167977-how-to-increment-hidden-text-field/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.