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 8 of 8
  1. #1
    New to the CF scene
    Join Date
    Sep 2005
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    PHP arrays question

    I am using submission from a form to populate an online PDF proof:


    if(isset($_POST['Preview'])){

    $name = trim($_POST['name']);
    $title_one = trim($_POST['title_one']);
    $title_two = trim($_POST['title_two']);
    $address_one = (trim($_POST['address_one']));
    $address_two = (trim($_POST['address_two']));
    $address_three = (trim($_POST['address_three']));

    $values=$HTTP_POST_VARS;

    //Uses values from a post ignores fields that dont match the pdf
    $fdfdata = "%FDF-1.2\n%’“&&Mac178;\n";
    $fdfdata .= "1 0 obj \n<< /FDF ";
    $fdfdata .= "<< /Fields [\n";

    //loop that adds the field names and values
    foreach($values as $key=>$val)
    {
    $fdfdata.="<< /V ($val)/T ($key) >> ";
    }
    }



    What I need to know is:

    I need to make some changes to the variables names that are posted before they are processed by the FDF commands.
    I'm presuming that I need to take the post variables and put them in an array? Then I need to make $values = the new details.
    Problem is I'm not sure how to do this.
    Can anyone help?

  • #2
    Regular Coder
    Join Date
    Jun 2002
    Location
    Edinburgh, UK
    Posts
    402
    Thanks
    2
    Thanked 1 Time in 1 Post
    The line:
    $values = $HTTP_POST_VARS;
    gets all the posted values and then assigns it to the array $values, so you don't have to.

    In the loop:
    Code:
    //loop that adds the field names and values
    foreach($values as $key=>$val)
    {
    $fdfdata.="<< /V ($val)/T ($key) >> ";
    }
    }
    is where it takes each posted value and the name of the field it was entered into and then add's it to the $fdfdata string. So if you want to make any changes to the values it'd be best to do it within in this loop.

    You said you want to change the name of the fields, so to do this you'd use something along the lines of:

    $key = $key . "_changed";

    before the $fdfdata .= "<< ... line, making all the changes you want to the key variable, as this is where the name of the field is stored.

    Hope this helps
    Last edited by Badman3k; 09-21-2005 at 11:35 AM.
    Rich

    "An expert is a person who has made all the mistakes that can be made in a very narrow field."

  • #3
    Senior Coder JamieR's Avatar
    Join Date
    Oct 2004
    Location
    United Kingdom
    Posts
    3,161
    Thanks
    0
    Thanked 5 Times in 5 Posts
    Hasn't $HTTP_POST_VARS been deprecated?

  • #4
    Senior Coder NancyJ's Avatar
    Join Date
    Feb 2005
    Location
    Bradford, UK
    Posts
    3,174
    Thanks
    19
    Thanked 66 Times in 65 Posts
    Quote Originally Posted by weazel
    Hasn't $HTTP_POST_VARS been deprecated?
    yes... as of 4.1, it still works though.
    I dont see the need to post it into another array though, $_POST is an array.

    you can use
    PHP Code:
    foreach($_POST as $key =>$val
    rather than putting it into a new array first.

    The easiest way to change the values of $key is to change the fieldnames on the form.

  • #5
    New to the CF scene
    Join Date
    Sep 2005
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts
    The details are for business card proofs.

    The final pdf proof has the field names:

    var1, var2, var3, var4 etc..

    However users will have different details. eg some will have a mobile some will not.

    Before I even go near the fdf I want to be able to sort the submitted details so the form looks neat. eg it understands that nothing has been entered for fax number so moves all the other fields in to a different variable name to cover the missing space that no fax number would leave.
    I want to do this and then pass the details to the $values variable

    Any ideas?

  • #6
    Senior Coder NancyJ's Avatar
    Join Date
    Feb 2005
    Location
    Bradford, UK
    Posts
    3,174
    Thanks
    19
    Thanked 66 Times in 65 Posts
    how about
    PHP Code:
    $i=1;
    foreach(
    $values as $key=>$val)
    {
    //if there is data
    if ($val <> ""){
    //put the data into the next available 'var' placeholder
    $fdfdata.="<< /V ($val)/T (var$i) >> ";
    //increment next available place holder i
    $i++;
    }


  • #7
    New to the CF scene
    Join Date
    Sep 2005
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts
    That would be the best choice but some variables need to remain the same and not move depending upon user input.

    So if you could please tell me how to replace the $values=$HTTP_POST_VARS;
    so i can jig about with some variables and then make
    $values=$whatever I do;
    I would be very grateful.

    I am happy to write a long script of ifelses regarding what to to depending on user input.


    The problem is i am a novice at PHP. Although your suggestions are probably brilliant and less time consuming than the way I want to do it, I dont know how to do it any way but my way.

    Sorry for being a pain.

    Regards,

    Tim

  • #8
    Senior Coder NancyJ's Avatar
    Join Date
    Feb 2005
    Location
    Bradford, UK
    Posts
    3,174
    Thanks
    19
    Thanked 66 Times in 65 Posts
    Quote Originally Posted by McNasty
    That would be the best choice but some variables need to remain the same and not move depending upon user input.
    Then surely you should be validating those fields, to make sure they have values assigned to them before preceeding with the preview...

    But anyway you could create an exclude list and do something like this:

    PHP Code:
    $i=1;
    foreach(
    $values as $key=>$val)
    {
    //if there is data
    $excludepattern '/^excludevar1$|^excludevar2$/';
    if ((
    $val <> "")|| (preg_match($excludepattern$key))){
    //put the data into the next available 'var' placeholder
    $fdfdata.="<< /V ($val)/T (var$i) >> ";
    //increment next available place holder i
    $i++;
    }

    Last edited by NancyJ; 09-21-2005 at 06:14 PM.


  •  

    Posting Permissions

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