Jump to content

problem fetching info from form with name + id


tomer_shim

Recommended Posts

Hello,
I am using snoopy php class ([a href=\"http://sourceforge.net/projects/snoopy\" target=\"_blank\"]http://sourceforge.net/projects/snoopy[/a]) to build a 'auto submitter' for an online form. to do so, I used an example code from the README page included in that class docs.
this is the example:

[code]include "Snoopy.class.php";
    $snoopy = new Snoopy;
    
    $submit_url = "http://lnk.ispi.net/texis/scripts/msearch/netsearch.html";
    
    $submit_vars["q"] = "amiga";
    $submit_vars["submit"] = "Search!";
    $submit_vars["searchhost"] = "Altavista";

        
    if($snoopy->submit($submit_url,$submit_vars))
    {
        while(list($key,$val) = each($snoopy->headers))
            echo $key.": ".$val."<br>\n";
        echo "<p>\n";
        
        echo "<PRE>".htmlspecialchars($snoopy->results)."</PRE>\n";
    }
    else
        echo "error fetching document: ".$snoopy->error."\n";[/code]

while im trying to use this code for a regular form which has Text input boxes look like:

[code]<input type="text" name="title" size="50" maxlength="50">[/code]

Then it works, all i need to do is edit the $submit_url and the $submit_vars array to the input 'name's.


The problem starts when i tried to use that class for input boxes which includes array's like:

[code]<input type="text" name="title[]" size="50" maxlength="50" id="dt9" onchange="donh(this.id);">
<input type="text" name="url[]" size="30" id="du9" onchange="donh(this.id);">[/code]

I problem is that i dont know how to write the name of each of these input boxes in the $submit_vars array. i tried stuff like $submit_vars['name[id]'] = "something" (for example $submit_vars['title[dt9]'] = "blabla") but it didnt work. I need to know what is the syntax to do so.

This will really halp my project if someone could please help me.

Thank you in advance!!
Link to comment
Share on other sites

what the name stands for though? the input line contains Name and ID, which one goes under 'name' on the $submit_vars array?
i mean, accoring to:
<input type="text" name="title[]" size="50" maxlength="50" id="dt9" onchange="donh(this.id);">
how the line should look like?
$submit_vars['title'] = 'Whatever';
$submit_vars[dt9'] = 'Whatever';

which one should i use? in one i put the title (name in input) , in the other i put the id (id in input).
if u use title, its actually then name of the hole array cause i have lots of input boxes like that, here only ID changes. and if i put only ID i miss the Title name.
what sould i do?

thanks in advance.
Link to comment
Share on other sites

[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]<input type="text" name="title[]" size="50" maxlength="50" id="dt9" onchange="donh(this.id);">
how the line should look like?
$submit_vars['title'] = 'Whatever';
$submit_vars[dt9'] = 'Whatever';[/quote]
The "id" attribute is irrelevant, since it's not sent.

It depends, whenever you have fields named whatever[], PHP will get an array named whatever. For example:
[code]<input type="text" name="fruit[]"><br /> <<-- If you write 'banana here',
<input type="text" name="fruit[]"><br /> <<-- 'apple' here
<input type="text" name="fruit[]"><br /> <<-- and leave this blank[/code]
You will get an array:
[code]Array
(
    [0] => banana
    [1] => apple
    [2] =>
)[/code]
So, to access it, you must use $_POST['field_name_here']['position_here']. To get "banana", I would use $_POST['fruits'][0].

Link to comment
Share on other sites

thank you, but you have any idea how can i send the info?
with snoopy class im trying to simulate form submit, so i actually need to [i]send[/i] the information with $submit_vars to the php page which include the form, and not [i]get[/i] the data with $_POST.
any idea how can i send it with $submit_vars which used in snoopy class?

Thank you for trying to help, in advance!
Link to comment
Share on other sites

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.